const config = require("/pb_hooks/seed/config.js"); const utils = require("/pb_hooks/seed/utils.js"); module.exports = ($app) => { const { MF_cat_id_news, MF_cat_id_sports, MF_cat_id_technology } = config; const { getId, getAsset, dirtyTruncateTable } = utils; let row_array = [ [getId("1"), "news (MF)", getAsset("ci_news.jpg"), 1, ["A", "B", "C"], "visible", "chinese_1", getAsset("keyboard.mp3"), MF_cat_id_news, "中文1"], [getId("2"), "sports (MF)", getAsset("ci_sports.jpg"), 2, ["A", "B", "C"], "visible", "chinese_2", getAsset("mouse.mp3"), MF_cat_id_news, "中文2"], [getId("3"), "technology (MF)", getAsset("ci_technology.jpg"), 3, ["A", "B", "C"], "visible", "chinese_3", getAsset("keyboard.mp3"), MF_cat_id_news, "中文3"], [getId("4"), "art (MF)", getAsset("ci_art.jpg"), 4, ["A", "B", "C"], "visible", "chinese_1", getAsset("mouse.mp3"), MF_cat_id_sports, "中文1"], [getId("5"), "basic (MF)", getAsset("ci_basic.jpg"), 5, ["A", "B", "C"], "visible", "chinese_2", getAsset("keyboard.mp3"), MF_cat_id_sports, "中文2"], [getId("6"), "nature (MF)", getAsset("ci_nature.jpg"), 6, ["A", "B", "C"], "visible", "chinese_3", getAsset("keyboard.mp3"), MF_cat_id_sports, "中文3"], [getId("7"), "workplace (MF)", getAsset("ci_workplace.jpg"), 7, ["A", "B", "C"], "visible", "chinese_1", getAsset("keyboard.mp3"), MF_cat_id_technology, "中文1"], [getId("8"), "workplace (MF)", getAsset("ci_workplace.jpg"), 8, ["A", "B", "C"], "visible", "chinese_2", getAsset("keyboard.mp3"), MF_cat_id_technology, "中文2"], [getId("99"), "test hidden (MF)", getAsset("ci_workplace.jpg"), 9, ["A", "B", "C"], "hidden", "chinese_3", getAsset("keyboard.mp3"), MF_cat_id_technology, "中文3"], ]; dirtyTruncateTable("QuizMFQuestions"); let lt_collection = $app.findCollectionByNameOrId("QuizMFQuestions"); for (let i = 0; i < row_array.length; i++) { let lesson_type = row_array[i]; let record = new Record(lt_collection); record.set("id", lesson_type[0]); record.set("cat_name", lesson_type[1]); record.set("cat_image", lesson_type[2]); record.set("pos", lesson_type[3]); record.set("init_answer", lesson_type[4]); record.set("visible", lesson_type[5]); record.set("word", lesson_type[6]); record.set("sound", lesson_type[7]); record.set("cat_id", lesson_type[8]); record.set("word_c", lesson_type[9]); $app.save(record); } console.log(`031_QuizMFQuestions done`); }; // 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(); // };