54 lines
2.2 KiB
JavaScript
54 lines
2.2 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"), "EV-004", false, "new_job", { id: getId("1"), name: "Jie Yan", avatar: "/assets/avatar-8.png" }, { title: "Remote React / React Native Developer" }, ""],
|
|
[getId("2"), "EV-003", true, "new_job", { id: getId("2"), name: "Fran Perez", avatar: "/assets/avatar-5.png" }, { title: "Senior Golang Backend Engineer" }, ""],
|
|
[getId("3"), "EV-002", true, "new_feature", "", "", "Logistics management is now available"],
|
|
[getId("4"), "EV-001", true, "new_company", { id: getId("3"), name: "Jie Yan", avatar: "/assets/avatar-8.png" }, { name: "Stripe" }, ""],
|
|
];
|
|
|
|
let row_array = SAMPLE_CUSTOMER_ARRAY;
|
|
dirtyTruncateTable("Notifications");
|
|
|
|
let lt_collection = $app.findCollectionByNameOrId("Notifications");
|
|
|
|
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("NOTI_ID", customer[1]);
|
|
record.set("read", customer[2]);
|
|
record.set("type", customer[3]);
|
|
record.set("author", customer[4]);
|
|
record.set("job", customer[5]);
|
|
record.set("description", customer[6]);
|
|
|
|
$app.save(record);
|
|
}
|
|
|
|
console.log(`060_Notifications 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();
|
|
// };
|