Añadir Time Zone a los Venues

This commit is contained in:
David Arranz 2023-06-14 19:34:58 +02:00
parent 3f0b87870c
commit 444d364f1a
2 changed files with 82 additions and 74 deletions

View File

@ -1,68 +1,75 @@
'use strict';
"use strict";
const cdnHelper = require('../../helpers/cdn.helper');
const cdnHelper = require("../../helpers/cdn.helper");
module.exports = function (sequelize, DataTypes) {
const Venue = sequelize.define('Venue', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
const Venue = sequelize.define(
"Venue",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
},
address: {
type: DataTypes.STRING,
allowNull: false,
},
city: {
type: DataTypes.STRING,
allowNull: false,
},
country: {
type: DataTypes.STRING,
},
state: {
type: DataTypes.STRING,
},
postal_code: {
type: DataTypes.STRING,
},
accessibility: {
type: DataTypes.STRING,
},
gmt: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
latitude: {
type: DataTypes.DECIMAL(10, 8),
},
longitude: {
type: DataTypes.DECIMAL(11, 8),
},
image_url: {
type: DataTypes.VIRTUAL,
get: function () {
const city = this.get("city");
return cdnHelper.getCDNCityMediaUrl(city);
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
},
address: {
type: DataTypes.STRING,
allowNull: false,
},
city: {
type: DataTypes.STRING,
allowNull: false,
},
country: {
type: DataTypes.STRING,
},
state: {
type: DataTypes.STRING,
},
postal_code: {
type: DataTypes.STRING,
},
accessibility: {
type: DataTypes.STRING,
},
gmt: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
latitude: {
type: DataTypes.DECIMAL(10, 8),
},
longitude: {
type: DataTypes.DECIMAL(11, 8),
},
image_url: {
type: DataTypes.VIRTUAL,
get: function () {
const city = this.get('city');
return cdnHelper.getCDNCityMediaUrl(city)
}
}
}, {
tableName: 'venues',
freezeTableName: true,
timestamps: true,
});
},
tz: {
type: DataTypes.STRING,
},
},
{
tableName: "venues",
freezeTableName: true,
timestamps: true,
}
);
Venue.associate = function (models) {
Venue.Events = Venue.hasMany(models.Event, { foreignKey: 'venueId', as: 'events' });
};
Venue.associate = function (models) {
Venue.Events = Venue.hasMany(models.Event, { foreignKey: "venueId", as: "events" });
};
return Venue;
};
return Venue;
};

View File

@ -1,15 +1,16 @@
const Joi = require('joi');
const Joi = require("joi");
const VenueInputType = Joi.object().keys({
name: Joi.string().required(),
address: Joi.string().required(),
city: Joi.string().required(),
gmt: Joi.number().min(-12).max(+12),
description: Joi.string().optional(),
country: Joi.string().optional(),
state: Joi.string().optional(),
postal_code: Joi.string().optional(),
accessibility: Joi.string().optional()
name: Joi.string().required(),
address: Joi.string().required(),
city: Joi.string().required(),
gmt: Joi.number().min(-12).max(+12),
description: Joi.string().optional(),
country: Joi.string().optional(),
state: Joi.string().optional(),
postal_code: Joi.string().optional(),
accessibility: Joi.string().optional(),
tz: Joi.string().optional(),
});
/*
const VenueOutputType = Joi.object().keys({
@ -19,6 +20,6 @@ const VenueOutputType = Joi.object().keys({
*/
module.exports = {
VenueInputType,
// VenueOutputType
VenueInputType,
// VenueOutputType
};