227 lines
2.9 KiB
JavaScript
227 lines
2.9 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 attendance_logs = sequelize.define(
|
|
'attendance_logs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
work_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
check_in_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
check_out_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
check_in_lat: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
check_in_lng: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
check_out_lat: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
check_out_lng: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"hadir",
|
|
|
|
|
|
"telat",
|
|
|
|
|
|
"tidak_hadir",
|
|
|
|
|
|
"sakit",
|
|
|
|
|
|
"izin",
|
|
|
|
|
|
"dinas"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
late_minutes: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
gps_valid: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
remarks: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
attendance_logs.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.attendance_logs.belongsTo(db.employees, {
|
|
as: 'employee',
|
|
foreignKey: {
|
|
name: 'employeeId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.attendance_logs.belongsTo(db.outlets, {
|
|
as: 'outlet',
|
|
foreignKey: {
|
|
name: 'outletId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.attendance_logs.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.attendance_logs.hasMany(db.file, {
|
|
as: 'check_in_photo',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.attendance_logs.getTableName(),
|
|
belongsToColumn: 'check_in_photo',
|
|
},
|
|
});
|
|
|
|
db.attendance_logs.hasMany(db.file, {
|
|
as: 'check_out_photo',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.attendance_logs.getTableName(),
|
|
belongsToColumn: 'check_out_photo',
|
|
},
|
|
});
|
|
|
|
|
|
db.attendance_logs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.attendance_logs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return attendance_logs;
|
|
};
|
|
|
|
|