created API For Aplication Absensi
This commit is contained in:
60
models/api_key.model.js
Normal file
60
models/api_key.model.js
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict'
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
class apiKey extends Model {
|
||||
static associate(models) { }
|
||||
}
|
||||
|
||||
apiKey.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
api_key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
is_actived: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 1,
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
deleted_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
created_by: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
},
|
||||
updated_by: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'apiKey',
|
||||
tableName: 'ref_api_keys',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at',
|
||||
deletedAt: 'deleted_at',
|
||||
}
|
||||
)
|
||||
|
||||
return apiKey
|
||||
}
|
||||
|
||||
|
||||
90
models/attendances.model.js
Normal file
90
models/attendances.model.js
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
const { Model, DataTypes } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
class Attedances extends Model {
|
||||
static associate(models) {
|
||||
this.belongsTo(models.User, {
|
||||
foreignKey: 'user_id',
|
||||
as: 'user'
|
||||
})
|
||||
this.belongsTo(models.Branch, {
|
||||
foreignKey: 'branch_id',
|
||||
as: 'branch',
|
||||
onDelete: 'CASCADE'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Attedances.init({
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
},
|
||||
branch_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
},
|
||||
date: {
|
||||
type: DataTypes.DATEONLY,
|
||||
allowNull: false
|
||||
},
|
||||
photo: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
clock_in: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
clock_out: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
lat: {
|
||||
type: DataTypes.DECIMAL(20, 15),
|
||||
allowNull: true,
|
||||
},
|
||||
lng: {
|
||||
type: DataTypes.DECIMAL(20, 15),
|
||||
allowNull: true,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.ENUM('present', 'sick', 'permission'),
|
||||
defaultValue: 'present'
|
||||
},
|
||||
reason:{
|
||||
type: DataTypes.TEXT
|
||||
},
|
||||
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
deleted_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: "Attedances",
|
||||
tableName: "ref_attedances",
|
||||
timestamps: true,
|
||||
createdAt: "created_at",
|
||||
updatedAt: "updated_at",
|
||||
deletedAt: "deleted_at",
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
return Attedances;
|
||||
};
|
||||
57
models/branch.model.js
Normal file
57
models/branch.model.js
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
const { Model, DataTypes } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
class Branch extends Model {
|
||||
static associate(models) {
|
||||
this.hasMany(models.User, {
|
||||
foreignKey: 'branch_id',
|
||||
as: 'user',
|
||||
onDelete: 'CASCADE'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Branch.init({
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
lat: {
|
||||
type: DataTypes.DECIMAL(20, 15),
|
||||
allowNull: false,
|
||||
},
|
||||
lng: {
|
||||
type: DataTypes.DECIMAL(20, 15),
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
deleted_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: "Branch",
|
||||
tableName: "ref_branches",
|
||||
timestamps: true,
|
||||
createdAt: "created_at",
|
||||
updatedAt: "updated_at",
|
||||
deletedAt: "deleted_at",
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
return Branch;
|
||||
};
|
||||
102
models/bug_reporting.model.js
Normal file
102
models/bug_reporting.model.js
Normal file
@@ -0,0 +1,102 @@
|
||||
'use strict'
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
class BugReporting extends Model {
|
||||
static associate(models) {
|
||||
// Define associations, if any
|
||||
}
|
||||
}
|
||||
|
||||
BugReporting.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
class: {
|
||||
type: DataTypes.STRING(191),
|
||||
allowNull: true,
|
||||
},
|
||||
file: {
|
||||
type: DataTypes.STRING(191),
|
||||
allowNull: true,
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
status_code: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
line: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
message: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
trace: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: null,
|
||||
allowNull: true,
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: null,
|
||||
allowNull: true,
|
||||
},
|
||||
url: {
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: null,
|
||||
allowNull: true,
|
||||
},
|
||||
method: {
|
||||
type: DataTypes.STRING(191),
|
||||
defaultValue: null,
|
||||
allowNull: true,
|
||||
},
|
||||
ip: {
|
||||
type: DataTypes.STRING(191),
|
||||
defaultValue: null,
|
||||
allowNull: true,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
deleted_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
created_by: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
},
|
||||
updated_by: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
}
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'BugReporting',
|
||||
tableName: 'core_bug_reportings',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at',
|
||||
deletedAt: 'deleted_at',
|
||||
}
|
||||
)
|
||||
|
||||
return BugReporting
|
||||
}
|
||||
70
models/migration.js
Normal file
70
models/migration.js
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Sequelize = require("sequelize");
|
||||
const process = require("process");
|
||||
const basename = path.basename(__filename);
|
||||
let config;
|
||||
|
||||
try {
|
||||
// Prefer legacy app-specific configuration when available
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
config = require("../app/config/db.config.js");
|
||||
} catch (error) {
|
||||
if (error.code !== "MODULE_NOT_FOUND") {
|
||||
throw error;
|
||||
}
|
||||
// Fallback to the shared config loader
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const appConfig = require("../src/config/config.js");
|
||||
const dbConfig = appConfig.db || {};
|
||||
config = {
|
||||
database: dbConfig.name,
|
||||
username: dbConfig.username,
|
||||
password: dbConfig.password,
|
||||
host: dbConfig.host,
|
||||
port: dbConfig.port,
|
||||
dialect: dbConfig.dialect,
|
||||
logging: false
|
||||
};
|
||||
}
|
||||
require("dotenv").config();
|
||||
|
||||
const db = {};
|
||||
|
||||
const sequelize = new Sequelize(
|
||||
config.database,
|
||||
config.username,
|
||||
config.password,
|
||||
config
|
||||
);
|
||||
|
||||
fs.readdirSync(__dirname)
|
||||
.filter((file) => {
|
||||
return (
|
||||
file.indexOf(".") !== 0 &&
|
||||
file !== basename &&
|
||||
file.slice(-3) === ".js" &&
|
||||
file.indexOf(".test.js") === -1
|
||||
);
|
||||
})
|
||||
.forEach((file) => {
|
||||
const model = require(path.join(__dirname, file))(
|
||||
sequelize,
|
||||
Sequelize.DataTypes
|
||||
);
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach((modelName) => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
// db.Sequelize = Sequelize;
|
||||
db.Op = Sequelize.Op;
|
||||
|
||||
module.exports = db;
|
||||
116
models/user.model.js
Normal file
116
models/user.model.js
Normal file
@@ -0,0 +1,116 @@
|
||||
"use strict";
|
||||
const { Model, DataTypes } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
class User extends Model {
|
||||
static associate(models) {
|
||||
this.belongsTo(models.Branch, {foreignKey: 'branch_id', as: 'branch', onDelete: 'CASCADE'})
|
||||
}
|
||||
}
|
||||
|
||||
User.init({
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
branch_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.ENUM('admin', 'user'),
|
||||
allowNull: true,
|
||||
defaultValue: 'user'
|
||||
},
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isEmail: true,
|
||||
},
|
||||
},
|
||||
|
||||
avatar_url: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
|
||||
phone: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
unique: true,
|
||||
validate: {
|
||||
is: {
|
||||
args: /^\+?[0-9\s\-]{6,20}$/,
|
||||
msg: 'Format nomor telepon tidak valid',
|
||||
},
|
||||
len: {
|
||||
args: [6, 15],
|
||||
msg: "Nomor telepon maksimal 15 karakter"
|
||||
}
|
||||
}
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
|
||||
|
||||
provider_id: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
login_via: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'EMAIL',
|
||||
},
|
||||
google_id: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
is_suspended: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
birth: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true
|
||||
},
|
||||
last_login: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
is_first_login: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
deleted_at: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: "User",
|
||||
tableName: "core_users",
|
||||
timestamps: true,
|
||||
createdAt: "created_at",
|
||||
updatedAt: "updated_at",
|
||||
deletedAt: "deleted_at",
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
return User;
|
||||
};
|
||||
Reference in New Issue
Block a user