219 lines
2.2 KiB
JavaScript
219 lines
2.2 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 vpn_plans = sequelize.define(
|
|
'vpn_plans',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
protocol: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"vless",
|
|
|
|
|
|
"vmess",
|
|
|
|
|
|
"trojan",
|
|
|
|
|
|
"shadowsocks",
|
|
|
|
|
|
"wireguard",
|
|
|
|
|
|
"openvpn",
|
|
|
|
|
|
"mixed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
billing_period: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"day",
|
|
|
|
|
|
"week",
|
|
|
|
|
|
"month",
|
|
|
|
|
|
"quarter",
|
|
|
|
|
|
"year",
|
|
|
|
|
|
"one_time"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
duration_days: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
data_limit_gb: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
device_limit: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
price_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
currency: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"irr",
|
|
|
|
|
|
"usd",
|
|
|
|
|
|
"eur",
|
|
|
|
|
|
"usdt"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
sort_order: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
vpn_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.vpn_plans.hasMany(db.orders, {
|
|
as: 'orders_vpn_plan',
|
|
foreignKey: {
|
|
name: 'vpn_planId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.vpn_plans.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.vpn_plans.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return vpn_plans;
|
|
};
|
|
|
|
|