backend_adaptive_learning/models/usersModels/studentModel.js

59 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-09-13 13:03:35 +00:00
import db from "../../database/db.js";
const StudentModel = (DataTypes) => {
const Students = db.define(
"student",
{
ID_SISWA: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
validate: {
notEmpty: true,
},
},
ID_CLASS: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: "class",
key: "ID_CLASS",
},
},
2024-09-13 13:03:35 +00:00
ID: {
type: DataTypes.UUID,
allowNull: false,
validate: {
notEmpty: true,
},
references: {
model: "users",
key: "ID",
},
},
NISN: {
2024-10-14 01:23:37 +00:00
type: DataTypes.BIGINT(11),
2024-09-13 13:03:35 +00:00
allowNull: false,
unique: true,
validate: {
notEmpty: true,
is10Digits(value) {
const stringValue = value.toString();
if (stringValue.length !== 10) {
throw new Error("NISN must be exactly 10 digits long");
}
},
2024-09-13 13:03:35 +00:00
},
},
},
{
timestamps: false,
tableName: "student",
}
);
return Students;
};
export default StudentModel;