From 48c2634c62a33b1105276222afe7aa8787f83cb8 Mon Sep 17 00:00:00 2001 From: elangptra Date: Mon, 14 Oct 2024 15:35:26 +0700 Subject: [PATCH] feat: table migration to database function --- .../monitoringControllers/monitoring.js | 23 ++-- .../20241014033659-create-teacher.cjs | 44 +++++++ .../20241014063413-create-report.cjs | 43 +++++++ .../20241014063944-create-class.cjs | 31 +++++ .../20241014064557-create-student.cjs | 60 +++++++++ .../20241014065005-create-section.cjs | 40 ++++++ .../20241014065621-create-topic.cjs | 52 ++++++++ .../20241014070248-create-level.cjs | 115 ++++++++++++++++++ .../20241014070802-create-exercise.cjs | 73 +++++++++++ ...20241014071514-create-multiple-choices.cjs | 63 ++++++++++ .../20241014072116-create-matching-pairs.cjs | 47 +++++++ .../20241014072654-create-true-false.cjs | 43 +++++++ ...20241014080340-create-student-learning.cjs | 98 +++++++++++++++ ...20241014082006-create-student-exercise.cjs | 70 +++++++++++ .../20241014082720-create-monitoring.cjs | 75 ++++++++++++ models/contentModels/exerciseModel.js | 4 +- models/contentModels/levelModel.js | 4 +- models/contentModels/sectionModel.js | 2 +- models/contentModels/topicModel.js | 2 +- .../multipleChoicesModel.js | 14 +-- models/exerciseTypesModels/trueFalseModel.js | 2 +- models/learningModels/stdExerciseModel.js | 6 +- models/learningModels/stdLearningModel.js | 4 +- models/usersModels/reportModel.js | 2 +- 24 files changed, 885 insertions(+), 32 deletions(-) create mode 100644 database/migrations/20241014033659-create-teacher.cjs create mode 100644 database/migrations/20241014063413-create-report.cjs create mode 100644 database/migrations/20241014063944-create-class.cjs create mode 100644 database/migrations/20241014064557-create-student.cjs create mode 100644 database/migrations/20241014065005-create-section.cjs create mode 100644 database/migrations/20241014065621-create-topic.cjs create mode 100644 database/migrations/20241014070248-create-level.cjs create mode 100644 database/migrations/20241014070802-create-exercise.cjs create mode 100644 database/migrations/20241014071514-create-multiple-choices.cjs create mode 100644 database/migrations/20241014072116-create-matching-pairs.cjs create mode 100644 database/migrations/20241014072654-create-true-false.cjs create mode 100644 database/migrations/20241014080340-create-student-learning.cjs create mode 100644 database/migrations/20241014082006-create-student-exercise.cjs create mode 100644 database/migrations/20241014082720-create-monitoring.cjs diff --git a/controllers/monitoringControllers/monitoring.js b/controllers/monitoringControllers/monitoring.js index 4dacb7a..6c44dee 100644 --- a/controllers/monitoringControllers/monitoring.js +++ b/controllers/monitoringControllers/monitoring.js @@ -318,7 +318,6 @@ export const monitoringStudentProgressById = async (req, res) => { const topicName = stdLearning.level.levelTopic.NAME_TOPIC; const sectionName = stdLearning.level.levelTopic.topicSection.NAME_SECTION; - // Fetch levels with pagination, search, and sort const levels = await models.StdLearning.findAndCountAll({ where: { ID: userID, @@ -333,16 +332,17 @@ export const monitoringStudentProgressById = async (req, res) => { { FEEDBACK_STUDENT: { [models.Op.like]: `%${search}%` }, }, - // { - // [models.Sequelize.fn('DATE_FORMAT', models.Sequelize.col('STUDENT_START'), '%Y-%m-%d')]: { - // [models.Op.like]: `%${search}%`, - // }, - // }, - // { - // [models.Sequelize.fn('DATE_FORMAT', models.Sequelize.col('STUDENT_FINISH'), '%Y-%m-%d')]: { - // [models.Op.like]: `%${search}%`, - // }, - // }, + // Search student_start dan student_finish belum bisa + { + [models.Sequelize.fn('DATE_FORMAT', models.Sequelize.col('STUDENT_START'), '%Y-%m-%d')]: { + [models.Op.like]: `%${search}%`, + }, + }, + { + [models.Sequelize.fn('DATE_FORMAT', models.Sequelize.col('STUDENT_FINISH'), '%Y-%m-%d')]: { + [models.Op.like]: `%${search}%`, + }, + }, ], }), }, @@ -388,7 +388,6 @@ export const monitoringStudentProgressById = async (req, res) => { return 0; }); - // Pagination logic const paginatedResult = levelArray.slice((page - 1) * limit, page * limit); const totalPages = Math.ceil(levels.count / limit); const currentPage = parseInt(page); diff --git a/database/migrations/20241014033659-create-teacher.cjs b/database/migrations/20241014033659-create-teacher.cjs new file mode 100644 index 0000000..8b5a8ac --- /dev/null +++ b/database/migrations/20241014033659-create-teacher.cjs @@ -0,0 +1,44 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("teacher", { + ID_GURU: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID: { + type: Sequelize.UUID, + allowNull: false, + }, + NIP: { + type: Sequelize.BIGINT(11), + allowNull: false, + }, + }); + + await queryInterface.addConstraint("teacher", { + fields: ["NIP"], + type: "unique", + name: "teacher_unique_nip", + }); + + await queryInterface.addConstraint("teacher", { + fields: ["ID"], + type: "foreign key", + name: "FK_MERANGKAP", + references: { + table: "users", + field: "ID", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("teacher"); + }, +}; diff --git a/database/migrations/20241014063413-create-report.cjs b/database/migrations/20241014063413-create-report.cjs new file mode 100644 index 0000000..5198046 --- /dev/null +++ b/database/migrations/20241014063413-create-report.cjs @@ -0,0 +1,43 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("report", { + ID_REPORT: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID: { + type: Sequelize.UUID, + allowNull: false, + }, + REPORTS: { + type: Sequelize.STRING(256), + allowNull: false, + }, + TIME_REPORT: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("report", { + fields: ["ID"], + type: "foreign key", + name: "FK_MELAPORKAN", + references: { + table: "users", + field: "ID", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("report"); + }, +}; diff --git a/database/migrations/20241014063944-create-class.cjs b/database/migrations/20241014063944-create-class.cjs new file mode 100644 index 0000000..c6b3b75 --- /dev/null +++ b/database/migrations/20241014063944-create-class.cjs @@ -0,0 +1,31 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("class", { + ID_CLASS: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + NAME_CLASS: { + type: Sequelize.STRING(100), + allowNull: false, + }, + TOTAL_STUDENT: { + type: Sequelize.INTEGER(11), + allowNull: true, + }, + TIME_CLASS: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("class"); + }, +}; diff --git a/database/migrations/20241014064557-create-student.cjs b/database/migrations/20241014064557-create-student.cjs new file mode 100644 index 0000000..456a1bc --- /dev/null +++ b/database/migrations/20241014064557-create-student.cjs @@ -0,0 +1,60 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("student", { + ID_SISWA: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_CLASS: { + type: Sequelize.UUID, + allowNull: true, + }, + ID: { + type: Sequelize.UUID, + allowNull: false, + }, + NISN: { + type: Sequelize.BIGINT(11), + allowNull: false, + }, + }); + + await queryInterface.addConstraint("student", { + fields: ["NISN"], + type: "unique", + name: "student_unique_nisn", + }); + + await queryInterface.addConstraint("student", { + fields: ["ID_CLASS"], + type: "foreign key", + name: "FK_MENAMPUNG", + references: { + table: "class", + field: "ID_CLASS", + }, + onUpdate: "CASCADE", + onDelete: "SET NULL", + }); + + await queryInterface.addConstraint("student", { + fields: ["ID"], + type: "foreign key", + name: "FK_MENJADI", + references: { + table: "users", + field: "ID", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("student"); + }, +}; diff --git a/database/migrations/20241014065005-create-section.cjs b/database/migrations/20241014065005-create-section.cjs new file mode 100644 index 0000000..66c1498 --- /dev/null +++ b/database/migrations/20241014065005-create-section.cjs @@ -0,0 +1,40 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("section", { + ID_SECTION: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + NAME_SECTION: { + type: Sequelize.STRING(100), + allowNull: false, + }, + DESCRIPTION_SECTION: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + THUMBNAIL: { + type: Sequelize.STRING(255), + allowNull: true, + }, + IS_DELETED: { + type: Sequelize.TINYINT(1), + allowNull: true, + defaultValue: 0, + }, + TIME_SECTION: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("section"); + }, +}; diff --git a/database/migrations/20241014065621-create-topic.cjs b/database/migrations/20241014065621-create-topic.cjs new file mode 100644 index 0000000..3e83907 --- /dev/null +++ b/database/migrations/20241014065621-create-topic.cjs @@ -0,0 +1,52 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("topic", { + ID_TOPIC: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_SECTION: { + type: Sequelize.UUID, + allowNull: false, + }, + NAME_TOPIC: { + type: Sequelize.STRING(100), + allowNull: false, + }, + DESCRIPTION_TOPIC: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + IS_DELETED: { + type: Sequelize.TINYINT(1), + allowNull: true, + defaultValue: 0, + }, + TIME_TOPIC: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("topic", { + fields: ["ID_SECTION"], + type: "foreign key", + name: "FK_MEMILIKI", + references: { + table: "section", + field: "ID_SECTION", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("topic"); + }, +}; diff --git a/database/migrations/20241014070248-create-level.cjs b/database/migrations/20241014070248-create-level.cjs new file mode 100644 index 0000000..77602f8 --- /dev/null +++ b/database/migrations/20241014070248-create-level.cjs @@ -0,0 +1,115 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("level", { + ID_LEVEL: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_TOPIC: { + type: Sequelize.UUID, + allowNull: false, + }, + ID_SECTION: { + type: Sequelize.UUID, + allowNull: false, + }, + NAME_LEVEL: { + type: Sequelize.STRING(100), + allowNull: false, + }, + CONTENT: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + AUDIO: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + IMAGE: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + VIDEO: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + IS_PRETEST: { + type: Sequelize.TINYINT(1), + allowNull: true, + defaultValue: 0, + }, + ROUTE_1: { + type: Sequelize.UUID, + allowNull: false, + defaultValue: 0, + }, + ROUTE_2: { + type: Sequelize.UUID, + allowNull: false, + defaultValue: 0, + }, + ROUTE_3: { + type: Sequelize.UUID, + allowNull: false, + defaultValue: 0, + }, + ROUTE_4: { + type: Sequelize.UUID, + allowNull: false, + defaultValue: 0, + }, + ROUTE_5: { + type: Sequelize.UUID, + allowNull: false, + defaultValue: 0, + }, + ROUTE_6: { + type: Sequelize.UUID, + allowNull: false, + defaultValue: 0, + }, + IS_DELETED: { + type: Sequelize.TINYINT(1), + allowNull: true, + defaultValue: 0, + }, + TIME_LEVEL: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("level", { + fields: ["ID_TOPIC"], + type: "foreign key", + name: "FK_BERHUBUNGAN", + references: { + table: "topic", + field: "ID_TOPIC", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + + await queryInterface.addConstraint("level", { + fields: ["ID_SECTION"], + type: "foreign key", + name: "FK_MEMPUNYAI", + references: { + table: "section", + field: "ID_SECTION", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("level"); + }, +}; diff --git a/database/migrations/20241014070802-create-exercise.cjs b/database/migrations/20241014070802-create-exercise.cjs new file mode 100644 index 0000000..5ec9bbf --- /dev/null +++ b/database/migrations/20241014070802-create-exercise.cjs @@ -0,0 +1,73 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("admin_exercise", { + ID_ADMIN_EXERCISE: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_LEVEL: { + type: Sequelize.UUID, + allowNull: false, + }, + TITLE: { + type: Sequelize.STRING(100), + allowNull: false, + }, + QUESTION: { + type: Sequelize.TEXT, + allowNull: false, + }, + SCORE_WEIGHT: { + type: Sequelize.INTEGER(11), + allowNull: false, + defaultValue: 1, + }, + QUESTION_TYPE: { + type: Sequelize.STRING(100), + allowNull: false, + }, + AUDIO: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + VIDEO: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + IMAGE: { + type: Sequelize.STRING(1024), + allowNull: true, + }, + IS_DELETED: { + type: Sequelize.TINYINT(1), + allowNull: true, + defaultValue: 0, + }, + TIME_ADMIN_EXC: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("admin_exercise", { + fields: ["ID_LEVEL"], + type: "foreign key", + name: "FK_MEMBUTUHKAN", + references: { + table: "level", + field: "ID_LEVEL", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("admin_exercise"); + }, +}; diff --git a/database/migrations/20241014071514-create-multiple-choices.cjs b/database/migrations/20241014071514-create-multiple-choices.cjs new file mode 100644 index 0000000..a9538af --- /dev/null +++ b/database/migrations/20241014071514-create-multiple-choices.cjs @@ -0,0 +1,63 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("multiple_choices", { + ID_MULTIPLE_CHOICES: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_ADMIN_EXERCISE: { + type: Sequelize.UUID, + allowNull: false, + }, + OPTION_A: { + type: Sequelize.STRING(256), + allowNull: true, + }, + OPTION_B: { + type: Sequelize.STRING(256), + allowNull: true, + }, + OPTION_C: { + type: Sequelize.STRING(256), + allowNull: true, + }, + OPTION_D: { + type: Sequelize.STRING(256), + allowNull: true, + }, + OPTION_E: { + type: Sequelize.STRING(256), + allowNull: true, + }, + ANSWER_KEY: { + type: Sequelize.STRING(100), + allowNull: false, + }, + TIME_MULTIPLE_CHOICES: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("multiple_choices", { + fields: ["ID_ADMIN_EXERCISE"], + type: "foreign key", + name: "FK_MC_TERDAPAT", + references: { + table: "admin_exercise", + field: "ID_ADMIN_EXERCISE", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("multiple_choices"); + }, +}; diff --git a/database/migrations/20241014072116-create-matching-pairs.cjs b/database/migrations/20241014072116-create-matching-pairs.cjs new file mode 100644 index 0000000..365a69e --- /dev/null +++ b/database/migrations/20241014072116-create-matching-pairs.cjs @@ -0,0 +1,47 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("matching_pairs", { + ID_MATCHING_PAIRS: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_ADMIN_EXERCISE: { + type: Sequelize.UUID, + allowNull: false, + }, + LEFT_PAIR: { + type: Sequelize.TEXT, + allowNull: true, + }, + RIGHT_PAIR: { + type: Sequelize.TEXT, + allowNull: true, + }, + TIME_MATCHING_PAIRS: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("matching_pairs", { + fields: ["ID_ADMIN_EXERCISE"], + type: "foreign key", + name: "FK_MP_TERDAPAT", + references: { + table: "admin_exercise", + field: "ID_ADMIN_EXERCISE", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("matching_pairs"); + }, +}; \ No newline at end of file diff --git a/database/migrations/20241014072654-create-true-false.cjs b/database/migrations/20241014072654-create-true-false.cjs new file mode 100644 index 0000000..1e05316 --- /dev/null +++ b/database/migrations/20241014072654-create-true-false.cjs @@ -0,0 +1,43 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("true_false", { + ID_TRUE_FALSE: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_ADMIN_EXERCISE: { + type: Sequelize.UUID, + allowNull: false, + }, + IS_TRUE: { + type: Sequelize.TINYINT(1), + allowNull: false, + }, + TIME_TRUE_FALSE: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("true_false", { + fields: ["ID_ADMIN_EXERCISE"], + type: "foreign key", + name: "FK_TF_TERDAPAT", + references: { + table: "admin_exercise", + field: "ID_ADMIN_EXERCISE", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("true_false"); + }, +}; \ No newline at end of file diff --git a/database/migrations/20241014080340-create-student-learning.cjs b/database/migrations/20241014080340-create-student-learning.cjs new file mode 100644 index 0000000..6ee482e --- /dev/null +++ b/database/migrations/20241014080340-create-student-learning.cjs @@ -0,0 +1,98 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("student_learning", { + ID_STUDENT_LEARNING: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID: { + type: Sequelize.UUID, + allowNull: false, + }, + ID_LEVEL: { + type: Sequelize.UUID, + allowNull: false, + }, + STUDENT_START: { + type: Sequelize.DATE, + allowNull: false, + defaultValue: Sequelize.NOW, + }, + STUDENT_FINISH: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: null, + }, + SCORE: { + type: Sequelize.INTEGER(11), + allowNull: true, + defaultValue: null, + }, + IS_PASS: { + type: Sequelize.TINYINT(1), + allowNull: false, + defaultValue: 0, + }, + NEXT_LEARNING: { + type: Sequelize.UUID, + allowNull: true, + defaultValue: null, + }, + FEEDBACK_STUDENT: { + type: Sequelize.STRING(200), + allowNull: true, + defaultValue: null, + }, + TIME_LEARNING: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + onUpdate: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("student_learning", { + fields: ["ID"], + type: "foreign key", + name: "FK_MENGAKSES", + references: { + table: "users", + field: "ID", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + + await queryInterface.addConstraint("student_learning", { + fields: ["ID_LEVEL"], + type: "foreign key", + name: "FK_DIGUNAKAN", + references: { + table: "level", + field: "ID_LEVEL", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + + await queryInterface.addConstraint("student_learning", { + fields: ["NEXT_LEARNING"], + type: "foreign key", + name: "FK_MELANJUTKAN", + references: { + table: "level", + field: "ID_LEVEL", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("student_learning"); + }, +}; \ No newline at end of file diff --git a/database/migrations/20241014082006-create-student-exercise.cjs b/database/migrations/20241014082006-create-student-exercise.cjs new file mode 100644 index 0000000..ba40871 --- /dev/null +++ b/database/migrations/20241014082006-create-student-exercise.cjs @@ -0,0 +1,70 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("student_exercise", { + ID_STUDENT_EXERCISE: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_ADMIN_EXERCISE: { + type: Sequelize.UUID, + allowNull: false, + }, + ID_STUDENT_LEARNING: { + type: Sequelize.UUID, + allowNull: false, + }, + ANSWER_STUDENT: { + type: Sequelize.STRING(256), + allowNull: false, + }, + IS_CORRECT: { + type: Sequelize.TINYINT(1), + allowNull: false, + defaultValue: 0, + }, + RESULT_SCORE_STUDENT: { + type: Sequelize.FLOAT, + allowNull: true, + defaultValue: null, + }, + TIME_STUDENT_EXC: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + onUpdate: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("student_exercise", { + fields: ["ID_ADMIN_EXERCISE"], + type: "foreign key", + name: "FK_MENGERJAKAN", + references: { + table: "admin_exercise", + field: "ID_ADMIN_EXERCISE", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + + await queryInterface.addConstraint("student_exercise", { + fields: ["ID_STUDENT_LEARNING"], + type: "foreign key", + name: "FK_MELIBATKAN", + references: { + table: "student_learning", + field: "ID_STUDENT_LEARNING", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("student_exercise"); + }, +}; \ No newline at end of file diff --git a/database/migrations/20241014082720-create-monitoring.cjs b/database/migrations/20241014082720-create-monitoring.cjs new file mode 100644 index 0000000..99b4812 --- /dev/null +++ b/database/migrations/20241014082720-create-monitoring.cjs @@ -0,0 +1,75 @@ +const { Sequelize } = require("sequelize"); + +module.exports = { + async up(queryInterface) { + await queryInterface.createTable("monitoring", { + ID_MONITORING: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4, + allowNull: false, + }, + ID_STUDENT_LEARNING: { + type: Sequelize.UUID, + allowNull: false, + }, + ID_CLASS: { + type: Sequelize.UUID, + allowNull: true, + }, + ID_GURU: { + type: Sequelize.UUID, + allowNull: true, + }, + FEEDBACK_GURU: { + type: Sequelize.STRING(200), + allowNull: true, + }, + TIME_MONITORING: { + type: Sequelize.DATE, + allowNull: true, + defaultValue: Sequelize.NOW, + }, + }); + + await queryInterface.addConstraint("monitoring", { + fields: ["ID_STUDENT_LEARNING"], + type: "foreign key", + name: "FK_MENGACU", + references: { + table: "student_learning", + field: "ID_STUDENT_LEARNING", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }); + + await queryInterface.addConstraint("monitoring", { + fields: ["ID_CLASS"], + type: "foreign key", + name: "FK_MENDAPATKAN", + references: { + table: "class", + field: "ID_CLASS", + }, + onUpdate: "CASCADE", + onDelete: "SET NULL", + }); + + await queryInterface.addConstraint("monitoring", { + fields: ["ID_GURU"], + type: "foreign key", + name: "FK_DILAKUKAN", + references: { + table: "teacher", + field: "ID_GURU", + }, + onUpdate: "CASCADE", + onDelete: "SET NULL", + }); + }, + + async down(queryInterface) { + await queryInterface.dropTable("monitoring"); + }, +}; \ No newline at end of file diff --git a/models/contentModels/exerciseModel.js b/models/contentModels/exerciseModel.js index e1d8c9f..9077dff 100644 --- a/models/contentModels/exerciseModel.js +++ b/models/contentModels/exerciseModel.js @@ -39,7 +39,7 @@ const ExerciseModel = (DataTypes) => { }, }, SCORE_WEIGHT: { - type: DataTypes.INTEGER(6), + type: DataTypes.INTEGER(11), allowNull: false, defaultValue: 1, validate: { @@ -66,7 +66,7 @@ const ExerciseModel = (DataTypes) => { allowNull: true, }, IS_DELETED: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: true, defaultValue: 0, validate: { diff --git a/models/contentModels/levelModel.js b/models/contentModels/levelModel.js index 4fec91a..9bea2cf 100644 --- a/models/contentModels/levelModel.js +++ b/models/contentModels/levelModel.js @@ -58,7 +58,7 @@ const LevelModel = (DataTypes) => { allowNull: true, }, IS_PRETEST: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: true, defaultValue: 0, validate: { @@ -91,7 +91,7 @@ const LevelModel = (DataTypes) => { allowNull: false, }, IS_DELETED: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: true, defaultValue: 0, validate: { diff --git a/models/contentModels/sectionModel.js b/models/contentModels/sectionModel.js index e6ecb9e..34c4ec9 100644 --- a/models/contentModels/sectionModel.js +++ b/models/contentModels/sectionModel.js @@ -31,7 +31,7 @@ const SectionModel = (DataTypes) => { allowNull: true, }, IS_DELETED: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: true, defaultValue: 0, validate: { diff --git a/models/contentModels/topicModel.js b/models/contentModels/topicModel.js index 5009110..466162d 100644 --- a/models/contentModels/topicModel.js +++ b/models/contentModels/topicModel.js @@ -38,7 +38,7 @@ const TopicModel = (DataTypes) => { }, }, IS_DELETED: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: true, defaultValue: 0, validate: { diff --git a/models/exerciseTypesModels/multipleChoicesModel.js b/models/exerciseTypesModels/multipleChoicesModel.js index 0f91789..5f059c5 100644 --- a/models/exerciseTypesModels/multipleChoicesModel.js +++ b/models/exerciseTypesModels/multipleChoicesModel.js @@ -25,28 +25,28 @@ const MultipleChoicesModel = (DataTypes) => { }, }, OPTION_A: { - type: DataTypes.STRING(200), + type: DataTypes.STRING(256), allowNull: true, }, OPTION_B: { - type: DataTypes.STRING(200), + type: DataTypes.STRING(256), allowNull: true, }, OPTION_C: { - type: DataTypes.STRING(200), + type: DataTypes.STRING(256), allowNull: true, }, OPTION_D: { - type: DataTypes.STRING(200), + type: DataTypes.STRING(256), allowNull: true, }, OPTION_E: { - type: DataTypes.STRING(200), + type: DataTypes.STRING(256), allowNull: true, }, ANSWER_KEY: { - type: DataTypes.STRING(5), - allowNull: true, + type: DataTypes.STRING(100), + allowNull: false, }, TIME_MULTIPLE_CHOICES: { type: DataTypes.DATE, diff --git a/models/exerciseTypesModels/trueFalseModel.js b/models/exerciseTypesModels/trueFalseModel.js index d960a4e..741cce4 100644 --- a/models/exerciseTypesModels/trueFalseModel.js +++ b/models/exerciseTypesModels/trueFalseModel.js @@ -26,7 +26,7 @@ const TrueFalseModel = (DataTypes) => { }, IS_TRUE: { type: DataTypes.TINYINT(1), - allowNull: true, + allowNull: false, }, TIME_TRUE_FALSE: { type: DataTypes.DATE, diff --git a/models/learningModels/stdExerciseModel.js b/models/learningModels/stdExerciseModel.js index e1cfca7..9c9e4db 100644 --- a/models/learningModels/stdExerciseModel.js +++ b/models/learningModels/stdExerciseModel.js @@ -36,14 +36,14 @@ const StdExerciseModel = (DataTypes) => { }, }, ANSWER_STUDENT: { - type: DataTypes.CHAR(1), + type: DataTypes.STRING(256), allowNull: false, validate: { notEmpty: true, }, }, IS_CORRECT: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: false, defaultValue: 0, validate: { @@ -52,7 +52,7 @@ const StdExerciseModel = (DataTypes) => { }, }, RESULT_SCORE_STUDENT: { - type: DataTypes.INTEGER, + type: DataTypes.FLOAT, allowNull: true, defaultValue: null, }, diff --git a/models/learningModels/stdLearningModel.js b/models/learningModels/stdLearningModel.js index 26d7c67..ae07d4c 100644 --- a/models/learningModels/stdLearningModel.js +++ b/models/learningModels/stdLearningModel.js @@ -46,12 +46,12 @@ const StdLearningModel = (DataTypes) => { defaultValue: null, }, SCORE: { - type: DataTypes.INTEGER, + type: DataTypes.INTEGER(11), allowNull: true, defaultValue: null, }, IS_PASS: { - type: DataTypes.INTEGER(1), + type: DataTypes.TINYINT(1), allowNull: false, defaultValue: 0, validate: { diff --git a/models/usersModels/reportModel.js b/models/usersModels/reportModel.js index c4e4ccc..a0c0024 100644 --- a/models/usersModels/reportModel.js +++ b/models/usersModels/reportModel.js @@ -25,7 +25,7 @@ const ReportModel = (DataTypes) => { }, }, REPORTS: { - type: DataTypes.STRING, + type: DataTypes.STRING(256), allowNull: false, validate: { notEmpty: true,