178 lines
2.5 KiB
JavaScript
178 lines
2.5 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const mata_pelajaran = sequelize.define(
|
|
'mata_pelajaran',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
kode_mapel: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
nama_mapel: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
kelompok: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"umum",
|
|
|
|
|
|
"muatan_lokal",
|
|
|
|
|
|
"pilihan"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
urutan: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
mata_pelajaran.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.mata_pelajaran.hasMany(db.kktp, {
|
|
as: 'kktp_mata_pelajaran',
|
|
foreignKey: {
|
|
name: 'mata_pelajaranId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.mata_pelajaran.hasMany(db.nilai, {
|
|
as: 'nilai_mata_pelajaran',
|
|
foreignKey: {
|
|
name: 'mata_pelajaranId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.mata_pelajaran.hasMany(db.materi, {
|
|
as: 'materi_mata_pelajaran',
|
|
foreignKey: {
|
|
name: 'mata_pelajaranId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.mata_pelajaran.hasMany(db.tugas, {
|
|
as: 'tugas_mata_pelajaran',
|
|
foreignKey: {
|
|
name: 'mata_pelajaranId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.mata_pelajaran.hasMany(db.raport_descriptions, {
|
|
as: 'raport_descriptions_mata_pelajaran',
|
|
foreignKey: {
|
|
name: 'mata_pelajaranId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.mata_pelajaran.belongsTo(db.guru, {
|
|
as: 'guru_pengampu',
|
|
foreignKey: {
|
|
name: 'guru_pengampuId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.mata_pelajaran.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.mata_pelajaran.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return mata_pelajaran;
|
|
};
|
|
|
|
|