fix: code review fixes
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* termination_config Model
|
||||
* @copyright 2021 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
|
||||
const moment = require("moment");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const { Op } = require("sequelize");
|
||||
const { intersection } = require("lodash");
|
||||
const coreModel = require("./../core/models");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const TerminationConfig = sequelize.define(
|
||||
"termination_config",
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
message: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue:
|
||||
"You have an allergy to one of the main ingredients in our system. Our current system will not suit you.",
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: "Quiz will now be terminated",
|
||||
},
|
||||
counter: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 10,
|
||||
},
|
||||
created_at: DataTypes.DATEONLY,
|
||||
updated_at: DataTypes.DATE,
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
freezeTableName: true,
|
||||
tableName: "termination_config",
|
||||
},
|
||||
{
|
||||
underscoredAll: false,
|
||||
underscored: false,
|
||||
}
|
||||
);
|
||||
|
||||
coreModel.call(this, TerminationConfig);
|
||||
|
||||
TerminationConfig._preCreateProcessing = function (data) {
|
||||
return data;
|
||||
};
|
||||
TerminationConfig._postCreateProcessing = function (data) {
|
||||
return data;
|
||||
};
|
||||
TerminationConfig._customCountingConditions = function (data) {
|
||||
return data;
|
||||
};
|
||||
|
||||
TerminationConfig._filterAllowKeys = function (data) {
|
||||
let cleanData = {};
|
||||
let allowedFields = TerminationConfig.allowFields();
|
||||
allowedFields.push(TerminationConfig._primaryKey());
|
||||
|
||||
for (const key in data) {
|
||||
if (allowedFields.includes(key)) {
|
||||
cleanData[key] = data[key];
|
||||
}
|
||||
}
|
||||
return cleanData;
|
||||
};
|
||||
|
||||
TerminationConfig.associate = function (models) {};
|
||||
|
||||
TerminationConfig.allowFields = function () {
|
||||
return ["id", "message", "title", "counter"];
|
||||
};
|
||||
|
||||
TerminationConfig.labels = function () {
|
||||
return [
|
||||
"ID",
|
||||
"Termination Message",
|
||||
"Termination Title",
|
||||
"Counter (seconds)",
|
||||
];
|
||||
};
|
||||
|
||||
TerminationConfig.validationRules = function () {
|
||||
return [
|
||||
["id", "ID", ""],
|
||||
["message", "Termination Message", "required"],
|
||||
["title", "Termination Title", "required"],
|
||||
["counter", "Counter", "required|integer|min:1|max:60"],
|
||||
];
|
||||
};
|
||||
|
||||
TerminationConfig.validationEditRules = function () {
|
||||
return [
|
||||
["id", "ID", ""],
|
||||
["message", "Termination Message", "required"],
|
||||
["title", "Termination Title", "required"],
|
||||
["counter", "Counter", "required|integer|min:1|max:60"],
|
||||
];
|
||||
};
|
||||
|
||||
// ex
|
||||
TerminationConfig.intersection = function (fields) {
|
||||
if (fields) {
|
||||
return intersection(
|
||||
["id", "message", "title", "counter", "created_at", "updated_at"],
|
||||
Object.keys(fields)
|
||||
);
|
||||
} else return [];
|
||||
};
|
||||
|
||||
return TerminationConfig;
|
||||
};
|
||||
Reference in New Issue
Block a user