"add admin user seed script and refactor common seed utilities"

This commit is contained in:
louiscklaw
2025-05-11 10:34:48 +08:00
parent c29ab4b920
commit 60eed00cb2
26 changed files with 1426 additions and 506 deletions

View File

@@ -1,155 +1,26 @@
const config = require("/pb_hooks/seed/config.js");
const utils = require("/pb_hooks/seed/utils.js");
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
const cat_id_technology = "3".padStart(15, 0);
const getId = (id) => id.padStart(15, 0);
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 cat_id_technology = "3".padStart(15, 0);
// const getId = (id) => id.padStart(15, 0);
let row_array = [
[
getId("1"),
"news (CR)",
getAsset("ci_news.jpg"),
1,
["A", "B", "C"],
"visible",
"news",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_1",
"question_sh_1",
"modal_ans_1",
cat_id_technology,
["A", "B", "C"],
],
[
getId("2"),
"sports (CR)",
getAsset("ci_sports.jpg"),
2,
["A", "B", "C"],
"visible",
"sports",
getAsset("mouse.mp3"),
cat_id_technology,
"question_fh_2",
"question_sh_2",
"modal_ans_2",
cat_id_technology,
["A", "B", "C"],
],
[
getId("3"),
"technology (CR)",
getAsset("ci_technology.jpg"),
3,
["A", "B", "C"],
"visible",
"technology",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_3",
"question_sh_3",
"modal_ans_3",
cat_id_technology,
["A", "B", "C"],
],
[
getId("4"),
"art (CR)",
getAsset("ci_art.jpg"),
4,
["A", "B", "C"],
"visible",
"art",
getAsset("mouse.mp3"),
cat_id_technology,
"question_fh_4",
"question_sh_4",
"modal_ans_4",
cat_id_technology,
["A", "B", "C"],
],
[
getId("5"),
"basic (CR)",
getAsset("ci_basic.jpg"),
5,
["A", "B", "C"],
"visible",
"basic",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_5",
"question_sh_5",
"modal_ans_5",
cat_id_technology,
["A", "B", "C"],
],
[
getId("6"),
"nature (CR)",
getAsset("ci_nature.jpg"),
6,
["A", "B", "C"],
"visible",
"nature",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_6",
"question_sh_6",
"modal_ans_6",
cat_id_technology,
["A", "B", "C"],
],
[
getId("7"),
"workplace (CR)",
getAsset("ci_workplace.jpg"),
7,
["A", "B", "C"],
"visible",
"workplace",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_7",
"question_sh_7",
"modal_ans_7",
cat_id_technology,
["A", "B", "C"],
],
[
getId("8"),
"workplace (CR)",
getAsset("ci_workplace.jpg"),
8,
["A", "B", "C"],
"visible",
"workplace",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_8",
"question_sh_8",
"modal_ans_8",
cat_id_technology,
["A", "B", "C"],
],
[
getId("99"),
"test hidden (CR)",
getAsset("ci_workplace.jpg"),
9,
["A", "B", "C"],
"hidden",
"test",
getAsset("keyboard.mp3"),
cat_id_technology,
"question_fh_9",
"question_sh_9",
"modal_ans_9",
cat_id_technology,
["A", "B", "C"],
],
[getId("1"), "news (CR)", getAsset("ci_news.jpg"), 1, ["A", "B", "C"], "visible", "news", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_1", "question_sh_1", "modal_ans_1", CR_cat_id_news, ["A", "B", "C"]],
[getId("2"), "sports (CR)", getAsset("ci_sports.jpg"), 2, ["A", "B", "C"], "visible", "sports", getAsset("mouse.mp3"), CR_cat_id_technology, "question_fh_2", "question_sh_2", "modal_ans_2", CR_cat_id_news, ["A", "B", "C"]],
[getId("3"), "technology (CR)", getAsset("ci_technology.jpg"), 3, ["A", "B", "C"], "visible", "technology", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_3", "question_sh_3", "modal_ans_3", CR_cat_id_news, ["A", "B", "C"]],
[getId("4"), "art (CR)", getAsset("ci_art.jpg"), 4, ["A", "B", "C"], "visible", "art", getAsset("mouse.mp3"), CR_cat_id_technology, "question_fh_4", "question_sh_4", "modal_ans_4", CR_cat_id_news, ["A", "B", "C"]],
[getId("5"), "basic (CR)", getAsset("ci_basic.jpg"), 5, ["A", "B", "C"], "visible", "basic", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_5", "question_sh_5", "modal_ans_5", CR_cat_id_news, ["A", "B", "C"]],
[getId("6"), "nature (CR)", getAsset("ci_nature.jpg"), 6, ["A", "B", "C"], "visible", "nature", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_6", "question_sh_6", "modal_ans_6", CR_cat_id_technology, ["A", "B", "C"]],
[getId("7"), "workplace (CR)", getAsset("ci_workplace.jpg"), 7, ["A", "B", "C"], "visible", "workplace", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_7", "question_sh_7", "modal_ans_7", CR_cat_id_technology, ["A", "B", "C"]],
[getId("8"), "workplace (CR)", getAsset("ci_workplace.jpg"), 8, ["A", "B", "C"], "visible", "workplace", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_8", "question_sh_8", "modal_ans_8", CR_cat_id_technology, ["A", "B", "C"]],
[getId("99"), "test hidden (CR)", getAsset("ci_workplace.jpg"), 9, ["A", "B", "C"], "hidden", "test", getAsset("keyboard.mp3"), CR_cat_id_technology, "question_fh_9", "question_sh_9", "modal_ans_9", CR_cat_id_technology, ["A", "B", "C"]],
];
dirtyTruncateTable("QuizCRQuestions");
@@ -167,7 +38,7 @@ module.exports = ($app) => {
record.set("visible", lesson_type[5]);
record.set("word", lesson_type[6]);
record.set("sound", lesson_type[7]);
record.set("cat_id", lesson_type[7]);
// record.set("cat_id", lesson_type[7]);
record.set("question_fh", lesson_type[9]);
record.set("question_sh", lesson_type[10]);
record.set("modal_ans", lesson_type[11]);
@@ -180,8 +51,9 @@ module.exports = ($app) => {
console.log(`041_QuizCRQuestions 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();
};
// 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();
// };