242 lines
2.8 KiB
JavaScript
242 lines
2.8 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 recoveries = sequelize.define(
|
|
'recoveries',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
recovery_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"initiated",
|
|
|
|
|
|
"in_verification",
|
|
|
|
|
|
"ready_for_pickup",
|
|
|
|
|
|
"completed",
|
|
|
|
|
|
"disputed",
|
|
|
|
|
|
"cancelled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
initiated_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
completed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
verification_method: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"in_app",
|
|
|
|
|
|
"in_person",
|
|
|
|
|
|
"organization",
|
|
|
|
|
|
"government"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
verification_notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
reward_paid_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
reward_paid_currency: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"XOF",
|
|
|
|
|
|
"USD",
|
|
|
|
|
|
"EUR"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
reward_paid: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
rating_for_finder: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
feedback: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
recoveries.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.recoveries.belongsTo(db.reports, {
|
|
as: 'report',
|
|
foreignKey: {
|
|
name: 'reportId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.recoveries.belongsTo(db.users, {
|
|
as: 'owner',
|
|
foreignKey: {
|
|
name: 'ownerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.recoveries.belongsTo(db.users, {
|
|
as: 'finder',
|
|
foreignKey: {
|
|
name: 'finderId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.recoveries.belongsTo(db.recovery_centers, {
|
|
as: 'center',
|
|
foreignKey: {
|
|
name: 'centerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.recoveries.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.recoveries.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.recoveries.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return recoveries;
|
|
};
|
|
|
|
|