163 lines
1.9 KiB
JavaScript
163 lines
1.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 order_actions = sequelize.define(
|
|
'order_actions',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
action_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"Refill",
|
|
|
|
|
|
"Cancel"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"Requested",
|
|
|
|
|
|
"Sent",
|
|
|
|
|
|
"Succeeded",
|
|
|
|
|
|
"Failed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
supplier_action_reference: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
response_payload: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
requested_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
processed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
order_actions.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.order_actions.belongsTo(db.orders, {
|
|
as: 'order',
|
|
foreignKey: {
|
|
name: 'orderId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_actions.belongsTo(db.users, {
|
|
as: 'requested_by_user',
|
|
foreignKey: {
|
|
name: 'requested_by_userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.order_actions.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.order_actions.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return order_actions;
|
|
};
|
|
|
|
|