backend_adaptive_learning/models/usersModels/teacherModel.js
2024-12-19 10:31:46 +07:00

51 lines
1.0 KiB
JavaScript

import db from "../../database/db.js";
const TeacherModel = (DataTypes) => {
const Teachers = db.define(
"teacher",
{
ID_GURU: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
validate: {
notEmpty: true,
},
},
ID: {
type: DataTypes.UUID,
allowNull: false,
validate: {
notEmpty: true,
},
references: {
model: "users",
key: "ID",
},
},
NIP: {
type: DataTypes.BIGINT(11),
allowNull: false,
unique: true,
validate: {
notEmpty: true,
is16Digits(value) {
const stringValue = value.toString();
if (stringValue.length !== 18) {
throw new Error("NIP must be exactly 18 digits long");
}
},
},
},
},
{
timestamps: false,
tableName: "teacher",
}
);
return Teachers;
};
export default TeacherModel;