191 lines
2.6 KiB
JavaScript
191 lines
2.6 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 declaration_submissions = sequelize.define(
|
|
'declaration_submissions',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
declaration_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"vat",
|
|
|
|
|
|
"tot",
|
|
|
|
|
|
"income_tax"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
submission_reference: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
submitted_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"queued",
|
|
|
|
|
|
"sent",
|
|
|
|
|
|
"received",
|
|
|
|
|
|
"accepted",
|
|
|
|
|
|
"rejected",
|
|
|
|
|
|
"failed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
response_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
declaration_submissions.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.declaration_submissions.belongsTo(db.merchants, {
|
|
as: 'merchant',
|
|
foreignKey: {
|
|
name: 'merchantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.declaration_submissions.belongsTo(db.tax_periods, {
|
|
as: 'tax_period',
|
|
foreignKey: {
|
|
name: 'tax_periodId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.declaration_submissions.belongsTo(db.users, {
|
|
as: 'submitted_by',
|
|
foreignKey: {
|
|
name: 'submitted_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.declaration_submissions.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.declaration_submissions.hasMany(db.file, {
|
|
as: 'submission_payload_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.declaration_submissions.getTableName(),
|
|
belongsToColumn: 'submission_payload_file',
|
|
},
|
|
});
|
|
|
|
|
|
db.declaration_submissions.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.declaration_submissions.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return declaration_submissions;
|
|
};
|
|
|
|
|