38342-vm/backend/src/db/models/paid_actions.js
2026-02-10 20:07:12 +00:00

185 lines
2.1 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 paid_actions = sequelize.define(
'paid_actions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
action_type: {
type: DataTypes.ENUM,
values: [
"post_publish_fee",
"boost_post",
"paid_notification",
"reveal_phone_number",
"external_link_fee",
"report_fee",
"admin_license_fee"
],
},
status: {
type: DataTypes.ENUM,
values: [
"locked_insufficient_balance",
"locked_payment_required",
"paid",
"cancelled"
],
},
base_fee_rwf: {
type: DataTypes.DECIMAL,
},
final_fee_rwf: {
type: DataTypes.DECIMAL,
},
discount_percent: {
type: DataTypes.DECIMAL,
},
requested_time: {
type: DataTypes.DATE,
},
paid_time: {
type: DataTypes.DATE,
},
calculation_details: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
paid_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.paid_actions.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.paid_actions.belongsTo(db.posts, {
as: 'post',
foreignKey: {
name: 'postId',
},
constraints: false,
});
db.paid_actions.belongsTo(db.users, {
as: 'createdBy',
});
db.paid_actions.belongsTo(db.users, {
as: 'updatedBy',
});
};
return paid_actions;
};