Files
lettersoup-online/002_source/pocketbase/pb_hooks/seed/006_Users_student.js
2025-04-22 02:53:49 +08:00

59 lines
2.6 KiB
JavaScript

module.exports = ($app) => {
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
let row_array = [
["1".padStart(15, 0), "[email protected]", "[email protected]", "[email protected]", true, true, "test_user_1"],
["2".padStart(15, 0), "[email protected]", "[email protected]", "[email protected]", true, true, "test_user_2"],
["3".padStart(15, 0), "[email protected]", "[email protected]", "[email protected]", true, true, "test_user_3"],
["4".padStart(15, 0), "[email protected]", "[email protected]", "[email protected]", true, true, "test_user_4"],
["5".padStart(15, 0), "[email protected]", "[email protected]", "[email protected]", true, true, "test_user_5"],
];
let um_row_array = [
["1".padStart(15, 0), "[email protected]", "active", "1".padStart(15, 0), JSON.stringify({}), getAsset("people1.png"), "student"],
["2".padStart(15, 0), "[email protected]", "active", "2".padStart(15, 0), JSON.stringify({}), getAsset("people2.png"), "student"],
["3".padStart(15, 0), "[email protected]", "active", "3".padStart(15, 0), JSON.stringify({}), getAsset("people3.png"), "student"],
["4".padStart(15, 0), "[email protected]", "active", "4".padStart(15, 0), JSON.stringify({}), getAsset("people4.png"), "student"],
["5".padStart(15, 0), "[email protected]", "active", "5".padStart(15, 0), JSON.stringify({}), getAsset("people5.png"), "student"],
];
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("state", um[2]);
um_record.set("user_id", um[3]);
um_record.set("meta", um[4]);
um_record.set("avatar", um[5]);
um_record.set("role", um[6]);
$app.save(um_record);
}
console.log("006 add student user done");
};
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();
};