39981-vm/backend/src/db/models/billing_plans.js
2026-05-13 10:46:44 +00:00

162 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 billing_plans = sequelize.define(
'billing_plans',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
plan_type: {
type: DataTypes.ENUM,
values: [
"free",
"pro",
"studio",
"enterprise"
],
},
monthly_price: {
type: DataTypes.DECIMAL,
},
monthly_job_limit: {
type: DataTypes.INTEGER,
},
monthly_export_limit: {
type: DataTypes.INTEGER,
},
max_projects: {
type: DataTypes.INTEGER,
},
priority_queue: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
commercial_license: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
billing_plans.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.billing_plans.hasMany(db.subscriptions, {
as: 'subscriptions_plan',
foreignKey: {
name: 'planId',
},
constraints: false,
});
//end loop
db.billing_plans.belongsTo(db.users, {
as: 'createdBy',
});
db.billing_plans.belongsTo(db.users, {
as: 'updatedBy',
});
};
return billing_plans;
};