31137/backend/src/db/models/bookings.js
2025-05-01 06:01:05 +00:00

74 lines
1.4 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 bookings = sequelize.define(
'bookings',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
date: {
type: DataTypes.DATE,
},
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.customers, {
as: 'customer',
foreignKey: {
name: 'customerId',
},
constraints: false,
});
db.bookings.belongsTo(db.seats, {
as: 'seat',
foreignKey: {
name: 'seatId',
},
constraints: false,
});
db.bookings.belongsTo(db.billboards, {
as: 'billboard',
foreignKey: {
name: 'billboardId',
},
constraints: false,
});
db.bookings.belongsTo(db.users, {
as: 'createdBy',
});
db.bookings.belongsTo(db.users, {
as: 'updatedBy',
});
};
return bookings;
};