Files
lettersoup-online/002_source/pocketbase/pb_hooks/seed/006_Users_student.js

71 lines
2.8 KiB
JavaScript

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;
let row_array = [
[getId("1"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_student_1"],
[getId("2"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_student_2"],
[getId("3"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_student_3"],
[getId("4"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_student_4"],
[getId("5"), "[email protected]", "[email protected]", "[email protected]", true, true, "test_student_5"],
];
// um = user_meta
let um_row_array = [
[getId("1"), "[email protected]", "active", getId("1"), JSON.stringify({}), getAsset("people1.png"), "student", "student_1"],
[getId("2"), "[email protected]", "pending", getId("2"), JSON.stringify({}), getAsset("people2.png"), "student", "student_2"],
[getId("3"), "[email protected]", "blocked", getId("3"), JSON.stringify({}), getAsset("people3.png"), "student", "student_3"],
[getId("4"), "[email protected]", "active", getId("4"), JSON.stringify({}), getAsset("people4.png"), "student", "student_4"],
[getId("5"), "[email protected]", "pending", getId("5"), JSON.stringify({}), getAsset("people5.png"), "student", "student_5"],
];
let users_collection = $app.findCollectionByNameOrId("users");
let user_metas_collection = $app.findCollectionByNameOrId("UserMetas");
for (let i = 0; i < row_array.length; 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());
$app.save(um_record);
}
console.log("006 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();
// };