iut-hapi/lib/models/movie.js

35 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2021-04-12 03:24:17 +00:00
'use strict';
const Joi = require('joi');
const { Model } = require('@hapipal/schwifty');
module.exports = class Movie extends Model {
static get tableName() {
return 'movie';
}
static get joiSchema() {
return Joi.object({
id: Joi.number().integer().greater(0),
title: Joi.string().min(3).required().example('The Matrix').description('Title of the film'),
description: Joi.string().min(3).required().example('A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against its controllers.').description('Description of the film'),
director: Joi.string().min(3).required().example('Lana Wachowski').description('Director of the film'),
releaseDate: Joi.date().required().example('1999-03-31').description('Release date of the film'),
created_at: Joi.date(),
updated_at: Joi.date()
});
}
$beforeInsert(queryContext) {
this.created_at = new Date();
this.created_at = this.updated_at;
}
$beforeUpdate(queryContext) {
this.updated_at = new Date();
}
}