37839-vm/backend/src/db/models/fraud_events.js
2026-01-26 16:00:29 +00:00

157 lines
2.0 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 fraud_events = sequelize.define(
'fraud_events',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
summary: {
type: DataTypes.TEXT,
},
event_type: {
type: DataTypes.ENUM,
values: [
"rate_limit",
"fingerprint_mismatch",
"behavioral_score_low",
"manual_flag"
],
},
details: {
type: DataTypes.TEXT,
},
score: {
type: DataTypes.DECIMAL,
},
created_on: {
type: DataTypes.DATE,
},
reviewed: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
fraud_events.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.fraud_events.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.fraud_events.belongsTo(db.task_consumptions, {
as: 'task_consumption',
foreignKey: {
name: 'task_consumptionId',
},
constraints: false,
});
db.fraud_events.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.fraud_events.belongsTo(db.users, {
as: 'createdBy',
});
db.fraud_events.belongsTo(db.users, {
as: 'updatedBy',
});
};
return fraud_events;
};