274 lines
3.7 KiB
JavaScript
274 lines
3.7 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 giveaways = sequelize.define(
|
|
'giveaways',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
slug: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
rules: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
terms_conditions: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"scheduled",
|
|
|
|
|
|
"live",
|
|
|
|
|
|
"paused",
|
|
|
|
|
|
"ended",
|
|
|
|
|
|
"archived"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
starts_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
ends_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
winner_count: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
prize_description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
estimated_prize_value: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
eligibility_region: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"worldwide",
|
|
|
|
|
|
"country_only",
|
|
|
|
|
|
"region_only"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
max_entries_per_user: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
giveaways.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.giveaways.hasMany(db.giveaway_faqs, {
|
|
as: 'giveaway_faqs_giveaway',
|
|
foreignKey: {
|
|
name: 'giveawayId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.giveaways.hasMany(db.giveaway_actions, {
|
|
as: 'giveaway_actions_giveaway',
|
|
foreignKey: {
|
|
name: 'giveawayId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.giveaways.hasMany(db.giveaway_entries, {
|
|
as: 'giveaway_entries_giveaway',
|
|
foreignKey: {
|
|
name: 'giveawayId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.giveaways.hasMany(db.comments, {
|
|
as: 'comments_giveaway',
|
|
foreignKey: {
|
|
name: 'giveawayId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.giveaways.hasMany(db.giveaway_ratings, {
|
|
as: 'giveaway_ratings_giveaway',
|
|
foreignKey: {
|
|
name: 'giveawayId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.giveaways.hasMany(db.referrals, {
|
|
as: 'referrals_giveaway',
|
|
foreignKey: {
|
|
name: 'giveawayId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.giveaways.belongsTo(db.organizations, {
|
|
as: 'organization',
|
|
foreignKey: {
|
|
name: 'organizationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.giveaways.hasMany(db.file, {
|
|
as: 'cover_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.giveaways.getTableName(),
|
|
belongsToColumn: 'cover_images',
|
|
},
|
|
});
|
|
|
|
db.giveaways.hasMany(db.file, {
|
|
as: 'attachment_files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.giveaways.getTableName(),
|
|
belongsToColumn: 'attachment_files',
|
|
},
|
|
});
|
|
|
|
|
|
db.giveaways.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.giveaways.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return giveaways;
|
|
};
|
|
|
|
|