174 lines
3.6 KiB
JavaScript
174 lines
3.6 KiB
JavaScript
module.exports = function (sequelize, DataTypes) {
|
|
const tour_pages = sequelize.define(
|
|
'tour_pages',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
environment: {
|
|
type: DataTypes.ENUM,
|
|
allowNull: false,
|
|
defaultValue: 'dev',
|
|
|
|
values: ['dev', 'stage', 'production'],
|
|
},
|
|
|
|
source_key: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: false,
|
|
validate: {
|
|
notEmpty: { msg: 'Page name is required' },
|
|
len: {
|
|
args: [1, 255],
|
|
msg: 'Page name must be between 1 and 255 characters',
|
|
},
|
|
},
|
|
},
|
|
|
|
slug: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: false,
|
|
validate: {
|
|
notEmpty: { msg: 'Slug is required' },
|
|
is: {
|
|
args: /^[a-z0-9_-]+$/i,
|
|
msg: 'Slug can only contain letters, numbers, dashes, and underscores',
|
|
},
|
|
len: {
|
|
args: [1, 255],
|
|
msg: 'Slug must be between 1 and 255 characters',
|
|
},
|
|
},
|
|
},
|
|
|
|
sort_order: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
defaultValue: 0,
|
|
},
|
|
|
|
background_image_url: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
background_video_url: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
background_audio_url: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
background_loop: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
background_video_autoplay: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
defaultValue: true,
|
|
},
|
|
|
|
background_video_loop: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
defaultValue: true,
|
|
},
|
|
|
|
background_video_muted: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
defaultValue: true,
|
|
},
|
|
|
|
background_video_start_time: {
|
|
type: DataTypes.DECIMAL(10, 1),
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
|
|
background_video_end_time: {
|
|
type: DataTypes.DECIMAL(10, 1),
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
|
|
design_width: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
|
|
design_height: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
|
|
requires_auth: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
ui_schema_json: {
|
|
type: DataTypes.JSON,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
indexes: [
|
|
{ fields: ['projectId'] },
|
|
{ fields: ['projectId', 'environment', 'slug'], unique: true },
|
|
{ fields: ['projectId', 'environment', 'sort_order'] },
|
|
{ fields: ['deletedAt'] },
|
|
],
|
|
},
|
|
);
|
|
|
|
tour_pages.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.tour_pages.belongsTo(db.projects, {
|
|
as: 'project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: true,
|
|
onDelete: 'CASCADE',
|
|
onUpdate: 'CASCADE',
|
|
});
|
|
|
|
db.tour_pages.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.tour_pages.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return tour_pages;
|
|
};
|