backend_adaptive_learning/models/usersModels/teacherModel.js

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 !== 16) {
throw new Error("NIP must be exactly 16 digits long");
}
},
},
},
},
{
timestamps: false,
tableName: "teacher",
}
);
return Teachers;
};
export default TeacherModel;