153 lines
3.7 KiB
JavaScript
153 lines
3.7 KiB
JavaScript
//
|
|
// RULES: this is not a normal nodejs engine, it is a nodejs provided by golang, so fakerjs cannot be used here
|
|
//
|
|
module.exports = ($app) => {
|
|
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 STUDENT_ARRAY = [
|
|
[
|
|
getId("1"),
|
|
"May",
|
|
getAsset("student1.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("student2.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("student3.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("student4.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("student5.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 = STUDENT_ARRAY;
|
|
dirtyTruncateTable("Students");
|
|
|
|
let lt_collection = $app.findCollectionByNameOrId("Students");
|
|
|
|
for (let i = 0; i < row_array.length; i++) {
|
|
let student = row_array[i];
|
|
|
|
let record = new Record(lt_collection);
|
|
record.set("id", student[0]);
|
|
record.set("name", student[1]);
|
|
record.set("avatar_file", student[2]);
|
|
record.set("email", student[3]);
|
|
record.set("phone", student[4]);
|
|
record.set("company", student[5]);
|
|
record.set("billingAddress", student[6]);
|
|
record.set("taxId", student[7]);
|
|
record.set("timezone", student[8]);
|
|
record.set("language", student[9]);
|
|
record.set("currency", student[10]);
|
|
record.set("status", student[11]);
|
|
|
|
$app.save(record);
|
|
}
|
|
|
|
console.log(`052_Students done`);
|
|
};
|
|
|
|
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();
|
|
};
|