Files
lettersoup-online/002_source/pocketbase/pb_hooks/seed/051_Teachers_xxx.js

158 lines
3.9 KiB
JavaScript

//
// RULES: this is not a normal nodejs engine, it is a nodejs provided by golang, so fakerjs cannot be used here
//
const config = require("/pb_hooks/seed/config.js");
const utils = require("/pb_hooks/seed/utils.js");
//
module.exports = ($app) => {
const { CR_cat_id_news, CR_cat_id_technology } = config;
const { getId, getAsset, dirtyTruncateTable } = utils;
// const ASSETS_DIR = "/pb_hooks/assets";
// const getAsset = (name) => $filesystem.fileFromPath(ASSETS_DIR + "/" + name);
// const id_v = "1".padStart(15, 0); //id_vocabulary
// const id_c = "2".padStart(15, 0); //id_connectives
// const getId = (id) => id.padStart(15, 0);
// generate from `./project/001_documentation/Requirements/REQ0006/gen_customer/gen_customer.mjs`
const TEACHER_ARRAY = [
[
getId("1"),
"May",
getAsset("teacher1.png"),
"[email protected]",
"281-378-5900 x822",
"Green, Rempel and Hoeger",
{
country: "UK",
state: "Arizona",
city: "Winfieldburgh",
zipCode: "92017-8004",
line1: "1838 Willa Freeway",
line2: "Suite 307",
},
98,
"Asia/Urumqi",
"fr",
"USD",
"active",
],
[
getId("2"),
"Marilyne",
getAsset("teacher2.png"),
"[email protected]",
"(893) 919-2445 x193",
"White - Hessel",
{
country: "US",
state: "Nevada",
city: "Casa Grande",
zipCode: "83831-3843",
line1: "6984 Alberto Radial",
line2: "Suite 154",
},
49,
"Africa/Tunis",
"es",
"EUR",
"pending",
],
[
getId("3"),
"Jacklyn",
getAsset("teacher3.png"),
"[email protected]",
"597-593-0144 x168",
"Rolfson LLC",
{
country: "CA",
state: "Georgia",
city: "New Brodyfort",
zipCode: "18887-7075",
line1: "493 Pfannerstill Meadow",
line2: "Apt. 358",
},
44,
"Asia/Manila",
"en",
"GBP",
"blocked",
],
[
getId("4"),
"Alana",
getAsset("teacher4.png"),
"[email protected]",
"401.212.0386 x31125",
"Friesen, Langworth and Thompson",
{
country: "UK",
state: "North Carolina",
city: "Fort Jerrell",
zipCode: "14211",
line1: "1763 West Street",
line2: "Suite 699",
},
34,
"America/Boa_Vista",
"es",
"USD",
"active",
],
[
getId("5"),
"Rocky",
getAsset("teacher5.png"),
"[email protected]",
"653.964.0412",
"Hayes - Morar",
{
country: "US",
state: "New York",
city: "Kayton",
zipCode: "82048-0645",
line1: "636 Angel Junction",
line2: "Apt. 361",
},
70,
"America/Grand_Turk",
"fr",
"EUR",
"pending",
],
];
let row_array = TEACHER_ARRAY;
dirtyTruncateTable("Teachers");
let lt_collection = $app.findCollectionByNameOrId("Teachers");
for (let i = 0; i < row_array.length; i++) {
let teacher = row_array[i];
let record = new Record(lt_collection);
record.set("id", teacher[0]);
record.set("name", teacher[1]);
record.set("avatar_file", teacher[2]);
record.set("email", teacher[3]);
record.set("phone", teacher[4]);
record.set("company", teacher[5]);
record.set("billingAddress", teacher[6]);
record.set("taxId", teacher[7]);
record.set("timezone", teacher[8]);
record.set("language", teacher[9]);
record.set("currency", teacher[10]);
record.set("status", teacher[11]);
$app.save(record);
}
console.log(`051_Teacher done`);
};
// TODO: remove me
// const dirtyTruncateTable = (COLLECTION_NAME) => {
// console.log(`perform dirty method to truncate table "${COLLECTION_NAME}"`);
// const cmd_to_exec = $os.cmd("sqlite3", "/pb_data/data.db", `DELETE from ${COLLECTION_NAME};`);
// cmd_to_exec.output();
// };