151 lines
1.9 KiB
JavaScript
151 lines
1.9 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 usage_records = sequelize.define(
|
|
'usage_records',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
usage_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"voice_minutes",
|
|
|
|
|
|
"sms_messages",
|
|
|
|
|
|
"ai_tokens"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
quantity: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
period_start: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
period_end: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
overage_cost: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
usage_records.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.usage_records.belongsTo(db.businesses, {
|
|
as: 'business',
|
|
foreignKey: {
|
|
name: 'businessId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.usage_records.belongsTo(db.subscriptions, {
|
|
as: 'subscription',
|
|
foreignKey: {
|
|
name: 'subscriptionId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.usage_records.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.usage_records.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.usage_records.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return usage_records;
|
|
};
|
|
|
|
|