add billing address seed data and update user seed scripts with teacher and student roles
```
This commit is contained in:
louiscklaw
2025-05-13 12:35:05 +08:00
parent 9be33f641f
commit 3e1f2e1057
6 changed files with 96 additions and 23 deletions

View File

@@ -16,8 +16,7 @@ $app.rootCmd.addCommand(
require(`${__hooks}/seed/002_LessonsCategories.js`)($app);
require(`${__hooks}/seed/003_Categories.js`)($app);
require(`${__hooks}/seed/004_clean_users.js`)($app);
require(`${__hooks}/seed/005_Users_teacher.js`)($app);
require(`${__hooks}/seed/006_Users_student.js`)($app);
require(`${__hooks}/seed/007_Users_admin.js`)($app);
require(`${__hooks}/seed/010_Vocabularies.js`)($app);
//
@@ -35,6 +34,10 @@ $app.rootCmd.addCommand(
require(`${__hooks}/seed/052_Students.js`)($app);
//
require(`${__hooks}/seed/060_Notifications.js`)($app);
require(`${__hooks}/seed/062_billingAddress.js`)($app);
//
require(`${__hooks}/seed/063_Users_teacher.js`)($app);
require(`${__hooks}/seed/064_Users_student.js`)($app);
$app.reloadCachedCollections();
$app.reloadSettings();

View File

@@ -0,0 +1,54 @@
//
// RULES:
// this is not a normal nodejs engine,
// it is a nodejs provided by golang,
// so fakerjs cannot be used here
// use vscode extensions 'Gruntfuggly.align-mode' to align comma
//
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, user_id_admin, user_id_test_teacher_1 } = config;
const { getId, getAsset, dirtyTruncateTable } = utils;
// generate from `./project/001_documentation/Requirements/REQ0006/gen_customer/gen_customer.mjs`
const SAMPLE_BILLING_ADDRESS_CSV = `
Central African Republic , Arizona , Winfieldburgh , 92017-8004, 1838 Willa Freeway , Suite 307
Iraq , Nevada , Casa Grande , 83831-3843, 6984 Alberto Radial , Suite 154
Grenada , Georgia , New Brodyfort , 18887-7075, 493 Pfannerstill Meadow, Apt. 358
Australia , North Carolina, Fort Jerrell , 14211 , 1763 West Street , Suite 699
Reunion , New York , Kayton , 82048-0645, 636 Angel Junction , Apt. 361
Heard Island and McDonald Islands, Wisconsin , Jalenbury , 75732-7013, 669 Sven Trail , Suite 409
Israel , Maryland , East Allenmouth, 21779 , 6070 W Grand Avenue , Suite 448
Canada , Michigan , Lafayette , 90430-8775, 430 Orland Place , Suite 891
South Georgia , Colorado , Lake Isaias , 26025-5909, 143 Kautzer Unions , Apt. 752
Mali , Illinois , Stammburgh , 92318 , 7669 Jude Drive , Apt. 594
`;
const SAMPLE_BILLING_ADDRESS_AA = SAMPLE_BILLING_ADDRESS_CSV.trim()
.split("\n")
.map((r) => r.split(",").map((c) => c.trim()));
let row_array = SAMPLE_BILLING_ADDRESS_AA;
dirtyTruncateTable("billingAddress");
let ba_collection = $app.findCollectionByNameOrId("billingAddress");
for (let i = 0; i < row_array.length; i++) {
let ba = row_array[i];
let record = new Record(ba_collection);
record.set("id", getId(i.toString()));
record.set("country", ba[0]);
record.set("state", ba[1]);
record.set("city", ba[2]);
record.set("zipCode", ba[3]);
record.set("line1", ba[4]);
record.set("line2", ba[5]);
$app.save(record);
}
console.log(`062_billingAddress done`);
};

View File

@@ -1,9 +1,16 @@
//
// RULES:
// this is not a normal nodejs engine,
// it is a nodejs provided by golang,
// so fakerjs cannot be used here
// use vscode extensions 'Gruntfuggly.align-mode' to align comma
//
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 } = utils;
const { getId, getAsset, randomId } = utils;
let row_array = [
[getId("11"), "teacher1@123.com", "teacher1@123.com", "teacher1@123.com", true, true, "test_teacher_1"],
@@ -21,7 +28,7 @@ module.exports = ($app) => {
let users_collection = $app.findCollectionByNameOrId("users");
let user_metas_collection = $app.findCollectionByNameOrId("UserMetas");
for (let i = 0; i < row_array.length; i++) {
for (let i = 0; i < 1; i++) {
let user = row_array[i];
let um = um_row_array[i];
@@ -52,15 +59,10 @@ module.exports = ($app) => {
um_record.set("email", user[3]);
um_record.set("phone", "9123456" + i.toString());
um_record.set("billingAddress", randomId(10));
$app.save(um_record);
}
console.log("005 add teacher user done");
console.log("063 add teacher user done");
};
// TODO: delete this ?
// 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();
// };

View File

@@ -1,9 +1,16 @@
//
// RULES:
// this is not a normal nodejs engine,
// it is a nodejs provided by golang,
// so fakerjs cannot be used here
// use vscode extensions 'Gruntfuggly.align-mode' to align comma
//
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 } = utils;
const { getId, getAsset, randomId } = utils;
let row_array = [
[getId("1"), "user1@123.com", "user1@123.com", "user1@123.com", true, true, "test_student_1"],
@@ -25,7 +32,7 @@ module.exports = ($app) => {
let users_collection = $app.findCollectionByNameOrId("users");
let user_metas_collection = $app.findCollectionByNameOrId("UserMetas");
for (let i = 0; i < row_array.length; i++) {
for (let i = 0; i < 1; i++) {
let user = row_array[i];
let um = um_row_array[i];
@@ -51,20 +58,20 @@ module.exports = ($app) => {
um_record.set("avatar_file", um[5]);
//
um_record.set("role", um[6]);
um_record.set("name", um[7]);
um_record.set("email", user[3]);
um_record.set("phone", "9123456" + i.toString());
um_record.set("company", "company_" + i.toString());
um_record.set("taxId", "taxId_" + i.toString());
um_record.set("timezone", "America/New_York");
um_record.set("language", "en");
um_record.set("currency", "EUR");
um_record.set("billingAddress", randomId(10));
um_record.set("role", um[6]);
$app.save(um_record);
}
console.log("006 add student user done");
console.log("064 add student user done");
};
// TODO: delete this ?
// 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();
// };

View File

@@ -0,0 +1,3 @@
{
"hello": "json"
}

View File

@@ -10,6 +10,10 @@ module.exports = {
}
},
getId: (id) => id.padStart(15, 0),
randomId: (max) =>
Math.floor(Math.random() * max)
.toString()
.padStart(15, 0),
dirtyTruncateTable: (COLLECTION_NAME) => {
console.log(`perform dirty method to truncate table "${COLLECTION_NAME}"`);