204 lines
2.5 KiB
JavaScript
204 lines
2.5 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 ads = sequelize.define(
|
|
'ads',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
ad_title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
ad_format: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"video",
|
|
|
|
|
|
"image",
|
|
|
|
|
|
"interactive",
|
|
|
|
|
|
"offerwall"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
ad_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"pending_review",
|
|
|
|
|
|
"active",
|
|
|
|
|
|
"paused",
|
|
|
|
|
|
"rejected",
|
|
|
|
|
|
"archived"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
destination_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
required_watch_seconds: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
cpm_cost: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
reward_per_view: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
ads.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.ads.hasMany(db.ad_eligibility_rules, {
|
|
as: 'ad_eligibility_rules_ad',
|
|
foreignKey: {
|
|
name: 'adId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.ads.hasMany(db.ad_impressions, {
|
|
as: 'ad_impressions_ad',
|
|
foreignKey: {
|
|
name: 'adId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.ads.belongsTo(db.campaigns, {
|
|
as: 'campaign',
|
|
foreignKey: {
|
|
name: 'campaignId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.ads.hasMany(db.file, {
|
|
as: 'creative_files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.ads.getTableName(),
|
|
belongsToColumn: 'creative_files',
|
|
},
|
|
});
|
|
|
|
db.ads.hasMany(db.file, {
|
|
as: 'creative_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.ads.getTableName(),
|
|
belongsToColumn: 'creative_images',
|
|
},
|
|
});
|
|
|
|
|
|
db.ads.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.ads.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return ads;
|
|
};
|
|
|
|
|