<commit_before>const { DataTypes, Model } = require('sequelize');
const Joi = require('joi');
const { AssociationChangesSchema } = require('./association-changes');
const { ConnectionInformationSchema } = require('./connection-information');

/**
 * This class represents a barman.
 */
class Barman extends Model {

    /**
     * Initialization function.
     *
     * @param sequelize
     * @returns {Model}
     */
    static init(sequelize) {
        return super.init({
            id: {
                type: DataTypes.INTEGER,
                primaryKey: true,
                autoIncrement: true
            },

            firstName: {
                type: DataTypes.STRING,
                allowNull: false
            },

            lastName: {
                type: DataTypes.STRING,
                allowNull: false
            },

            nickname: {
                type: DataTypes.STRING,
                allowNull: false
            },

            facebook: {
                type: DataTypes.STRING
            },

            dateOfBirth: {
                type: DataTypes.DATEONLY,
                allowNull: false
            },

            flow: {
                type: DataTypes.TEXT
            },

            active: {
                type: DataTypes.BOOLEAN,
                allowNull: false,
                defaultValue: true
            }
        }, {
            sequelize,

            // Do not delete row, even when the user delete is account
            paranoid: true
        });
    }


    /**
     * Set associations for the model.
     *
     * @param models
     */
    static associate(models) {
        this.belongsToMany(models.Kommission, { through: models.KommissionWrapper, as: 'kommissions' });
        this.belongsToMany(models.Role, { through: models.RoleWrapper, as: 'roles' });
        this.belongsToMany(models.Service, { through: models.ServiceWrapper, as: 'services' });

        this.hasOne(Barman, { as: 'godFather' });

        this.belongsTo(models.ConnectionInformation, { as: 'connection' });
    }
}

const BarmanSchema = Joi.object().keys({
    firstName: Joi.string(),
    lastName: Joi.string(),
    connection: ConnectionInformationSchema,
    active: Joi.boolean(),
    nickname: Joi.string(),
    facebook: Joi.string().uri(),
    dateOfBirth: Joi.string().isoDate(),
    flow: Joi.string(),

    _embedded: Joi.object({
        godFather: Joi.number().integer(),
        kommissions: AssociationChangesSchema,<commit_msg>Fix #81 God Father issue<commit_after>const { DataTypes, Model } = require('sequelize');
const Joi = require('joi');
const { AssociationChangesSchema } = require('./association-changes');
const { ConnectionInformationSchema } = require('./connection-information');

/**
 * This class represents a barman.
 */
class Barman extends Model {

    /**
     * Initialization function.
     *
     * @param sequelize
     * @returns {Model}
     */
    static init(sequelize) {
        return super.init({
            id: {
                type: DataTypes.INTEGER,
                primaryKey: true,
                autoIncrement: true
            },

            firstName: {
                type: DataTypes.STRING,
                allowNull: false
            },

            lastName: {
                type: DataTypes.STRING,
                allowNull: false
            },

            nickname: {
                type: DataTypes.STRING,
                allowNull: false
            },

            facebook: {
                type: DataTypes.STRING
            },

            dateOfBirth: {
                type: DataTypes.DATEONLY,
                allowNull: false
            },

            flow: {
                type: DataTypes.TEXT
            },

            active: {
                type: DataTypes.BOOLEAN,
                allowNull: false,
                defaultValue: true
            }
        }, {
            sequelize,

            // Do not delete row, even when the user delete is account
            paranoid: true,

            name: {
                plural: 'barmen',
                singular: 'barman'
            }
        });
    }


    /**
     * Set associations for the model.
     *
     * @param models
     */
    static associate(models) {
        this.belongsToMany(models.Kommission, { through: models.KommissionWrapper, as: 'kommissions' });
        this.belongsToMany(models.Role, { through: models.RoleWrapper, as: 'roles' });
        this.belongsToMany(models.Service, { through: models.ServiceWrapper, as: 'services' });

        this.belongsTo(Barman, { as: 'godFather' });

        this.belongsTo(models.ConnectionInformation, { as: 'connection' });
    }
}

const BarmanSchema = Joi.object().keys({
    firstName: Joi.string(),
    lastName: Joi.string(),
    connection: ConnectionInformationSchema,
    active: Joi.boolean(),
    nickname: Joi.string(),
    facebook: Joi.string().uri(),
    dateOfBirth: Joi.string().isoDate(),
    flow: Joi.string(),

    _embedded: Joi.object({
        godFather: Joi.number().integer(),
        kommissions: AssociationChangesSchema,
{'fraction_non_alphanumeric': 0.11378299120234604, 'fraction_numerical': 0.00039100684261974585, 'mean_word_length': 1.624935864545921, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3367519', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1339, 'n_words': 290}