2026-02-28 19:55:21 +00:00

212 lines
2.6 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 gigs = sequelize.define(
'gigs',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"active",
"paused",
"under_review"
],
},
impressions: {
type: DataTypes.INTEGER,
},
total_orders: {
type: DataTypes.INTEGER,
},
rating: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
gigs.associate = (db) => {
db.gigs.belongsToMany(db.tags, {
as: 'tags',
foreignKey: {
name: 'gigs_tagsId',
},
constraints: false,
through: 'gigsTagsTags',
});
db.gigs.belongsToMany(db.tags, {
as: 'tags_filter',
foreignKey: {
name: 'gigs_tagsId',
},
constraints: false,
through: 'gigsTagsTags',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.gigs.hasMany(db.gig_levels, {
as: 'gig_levels_gig',
foreignKey: {
name: 'gigId',
},
constraints: false,
});
db.gigs.hasMany(db.bookings, {
as: 'bookings_gig',
foreignKey: {
name: 'gigId',
},
constraints: false,
});
db.gigs.hasMany(db.invites, {
as: 'invites_gig',
foreignKey: {
name: 'gigId',
},
constraints: false,
});
//end loop
db.gigs.belongsTo(db.tutor_profiles, {
as: 'tutor_profile',
foreignKey: {
name: 'tutor_profileId',
},
constraints: false,
});
db.gigs.belongsTo(db.subject_categories, {
as: 'category',
foreignKey: {
name: 'categoryId',
},
constraints: false,
});
db.gigs.belongsTo(db.users, {
as: 'createdBy',
});
db.gigs.belongsTo(db.users, {
as: 'updatedBy',
});
};
return gigs;
};