59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
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",
|
|
},
|
|
},
|
|
ID: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
validate: {
|
|
notEmpty: true,
|
|
},
|
|
references: {
|
|
model: "users",
|
|
key: "ID",
|
|
},
|
|
},
|
|
NISN: {
|
|
type: DataTypes.BIGINT(11),
|
|
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");
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
timestamps: false,
|
|
tableName: "student",
|
|
}
|
|
);
|
|
return Students;
|
|
};
|
|
|
|
export default StudentModel;
|