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 bookings = sequelize.define( 'bookings', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, start_date: { type: DataTypes.DATE, }, end_date: { type: DataTypes.DATE, }, status: { type: DataTypes.ENUM, values: ['pending', 'confirmed', 'completed', 'cancelled'], }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); bookings.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.bookings.belongsTo(db.tourists, { as: 'tourist', foreignKey: { name: 'touristId', }, constraints: false, }); db.bookings.belongsTo(db.guides, { as: 'guide', foreignKey: { name: 'guideId', }, constraints: false, }); db.bookings.belongsTo(db.tour_packages, { as: 'tour_package', foreignKey: { name: 'tour_packageId', }, constraints: false, }); db.bookings.belongsTo(db.users, { as: 'createdBy', }); db.bookings.belongsTo(db.users, { as: 'updatedBy', }); }; return bookings; };