db/models/lineup.jsjavascript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sequelize_1 = require("sequelize");
const db_1 = __importDefault(require("../db"));
const winston_1 = __importDefault(require("../../plugins/winston.js"));
const errors_1 = require("../../utils/errors.js");
/**
* @openapi
* components:
* schemas:
* Lineup:
* type: object
* required:
* - id
* - startCount
* - endCount
* properties:
* id:
* type: string
* format: uuid
* startCount:
* type: integer
* minimum: 0
* endCount:
* type: integer
* minimum: 0
* creatorId:
* type: string
* format: uuid
* updaterId:
* type: string
* format: uuid
*/
/**
* @typedef Lineup
* @property {UUID} id
* @property {number} startCount
* @property {number} endCount
* @property {UUID} UserId
* @property {UUID} creatorId
* @property {UUID} updaterId
* @memberof module:Models
*/
class Lineup extends sequelize_1.Model {
}
Lineup.init({
id: {
type: sequelize_1.DataTypes.UUID,
defaultValue: sequelize_1.DataTypes.UUIDV4,
primaryKey: true,
},
startCount: {
type: sequelize_1.DataTypes.INTEGER,
allowNull: false,
validate: {
min: 0,
},
},
endCount: {
type: sequelize_1.DataTypes.INTEGER,
allowNull: false,
validate: {
min: 0,
},
},
createdAt: sequelize_1.DataTypes.DATE,
updatedAt: sequelize_1.DataTypes.DATE,
deletedAt: sequelize_1.DataTypes.DATE,
}, {
sequelize: db_1.default,
validate: {
endIsAfterStart() {
if (this.startCount > this.endCount) {
winston_1.default.error(`endCount (count: ${this.endCount}) cannot be before startCount (count: ${this.startCount})`);
throw new errors_1.FaultyInputError(`endCount (count: ${this.endCount}) cannot be before startCount (count: ${this.startCount})`);
}
},
},
});
exports.default = Lineup;