Files
lettersoup-online/002_source/pocketbase/pb_hooks/seed/063_Users_teacher.js
louiscklaw 3e1f2e1057 ```
add billing address seed data and update user seed scripts with teacher and student roles
```
2025-05-13 12:35:05 +08:00

69 lines
2.4 KiB
JavaScript

//
// 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, randomId } = utils;
let row_array = [
[getId("11"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_teacher_1"],
[getId("12"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_teacher_2"],
[getId("13"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_teacher_3"],
];
// um = user_meta
let um_row_array = [
[getId("11"), "[email protected]", "active", getId("11"), JSON.stringify({}), getAsset("people1.png"), "teacher", "teacher_1"],
[getId("12"), "[email protected]", "pending", getId("12"), JSON.stringify({}), getAsset("people2.png"), "teacher", "teacher_2"],
[getId("13"), "[email protected]", "blocked", getId("13"), JSON.stringify({}), getAsset("people3.png"), "teacher", "teacher_3"],
];
let users_collection = $app.findCollectionByNameOrId("users");
let user_metas_collection = $app.findCollectionByNameOrId("UserMetas");
for (let i = 0; i < 1; i++) {
let user = row_array[i];
let um = um_row_array[i];
let record = new Record(users_collection);
record.set("id", user[0]);
record.set("password", user[1]);
record.set("passwordConfirm", user[2]);
record.set("email", user[3]);
record.set("emailVisibility", user[4]);
record.set("verified", user[5]);
record.set("name", user[6]);
$app.save(record);
let um_record = new Record(user_metas_collection);
um_record.set("id", um[0]);
um_record.set("helloworld", um[1]);
um_record.set("status", um[2]);
um_record.set("user_id", um[3]);
um_record.set("meta", um[4]);
// NOTE: obslete "avatar" and use "avatar_file"
um_record.set("avatar", um[5]);
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("billingAddress", randomId(10));
$app.save(um_record);
}
console.log("063 add teacher user done");
};