160 lines
4.0 KiB
JavaScript
160 lines
4.0 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 SAMPLE_CUSTOMER_ARRAY = [
|
|
[
|
|
getId("1"),
|
|
"May",
|
|
getAsset("customer1.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("customer2.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("customer3.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("customer4.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("customer5.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 = SAMPLE_CUSTOMER_ARRAY;
|
|
dirtyTruncateTable("Customers");
|
|
|
|
let lt_collection = $app.findCollectionByNameOrId("Customers");
|
|
|
|
for (let i = 0; i < row_array.length; i++) {
|
|
let customer = row_array[i];
|
|
|
|
let record = new Record(lt_collection);
|
|
record.set("id", customer[0]);
|
|
record.set("name", customer[1]);
|
|
record.set("avatar_file", customer[2]);
|
|
record.set("email", customer[3]);
|
|
record.set("phone", customer[4]);
|
|
record.set("company", customer[5]);
|
|
record.set("billingAddress", customer[6]);
|
|
record.set("taxId", customer[7]);
|
|
record.set("timezone", customer[8]);
|
|
record.set("language", customer[9]);
|
|
record.set("currency", customer[10]);
|
|
record.set("status", customer[11]);
|
|
|
|
$app.save(record);
|
|
}
|
|
|
|
console.log(`050_Customers 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();
|
|
// };
|