I removed the relation between schedule
and price
.
models/announce.js
:
const { union } = require('lodash');
const {
CONTRACT_TYPE,
ANNOUNCE_STATUS,
ANNOUNCE_TYPE,
FAMILY_SERVICES,
INSTITUTION_SERVICES,
ADDITIONAL_NEEDS,
} = require('../enums/announce.enum');
const { GENDER, LANGUAGE_CODE } = require('../enums/person.enum');
// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Announce = sequelize.define(
'announce',
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
},
startDate: {
type: DataTypes.DATE,
},
endDate: {
type: DataTypes.DATE,
},
contractType: {
type: DataTypes.ENUM(Object.values(CONTRACT_TYPE)),
},
hourSalary: {
type: DataTypes.INTEGER,
},
status: {
type: DataTypes.ENUM(Object.values(ANNOUNCE_STATUS)),
defaultValue: ANNOUNCE_STATUS.DRAFT,
allowNull: false,
},
announceType: {
type: DataTypes.ENUM(Object.values(ANNOUNCE_TYPE)),
defaultValue: ANNOUNCE_TYPE.FAMILY,
allowNull: false,
},
additionalInformation: {
type: DataTypes.STRING,
},
services: {
type: DataTypes.ARRAY(
DataTypes.ENUM(Object.values(union(FAMILY_SERVICES, INSTITUTION_SERVICES))),
),
},
hasSeniorityBonus: {
type: DataTypes.BOOLEAN,
},
hasBonus: {
type: DataTypes.BOOLEAN,
},
numberOfProfiles: {
type: DataTypes.INTEGER,
defaultValue: 1,
},
additionalNeeds: {
type: DataTypes.ARRAY(DataTypes.ENUM(Object.values(ADDITIONAL_NEEDS))),
defaultValue: Sequelize.literal("'{}'::announce_additional_needs_enum[]"),
},
careGiverGenderWanted: {
type: DataTypes.ARRAY(DataTypes.ENUM(Object.values(GENDER))),
defaultValue: Sequelize.literal(
`'{${GENDER.MAN}, ${GENDER.WOMAN}}'::announce_care_giver_gender_wanted_enum[]`,
),
},
careGiverLanguageWanted: {
type: DataTypes.ENUM(Object.values(GENDER)),
defaultValue: LANGUAGE_CODE.FRENCH,
},
reference: {
type: DataTypes.INTEGER,
defaultValue: Sequelize.literal("nextval('announce_reference_seq'::regclass)"),
allowNull: false,
},
dispute: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false,
},
nextCallDate: {
type: DataTypes.DATEONLY,
},
publishedAt: {
type: DataTypes.DATEONLY,
},
},
{
tableName: 'announce',
underscored: true,
schema: process.env.DATABASE_SCHEMA,
timestamps: true,
},
);
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Announce.associate = (models) => {
Announce.belongsTo(models.beneficiary, {
foreignKey: {
name: 'beneficiaryIdKey',
field: 'beneficiary_id',
},
as: 'beneficiary',
});
Announce.belongsTo(models.backofficeAdmin, {
foreignKey: {
name: 'backofficeAdminKey',
field: 'backoffice_admin',
},
as: 'backofficeAdmin',
});
Announce.belongsTo(models.institution, {
foreignKey: {
name: 'institutionIdKey',
field: 'institution_id',
},
as: 'institution',
});
Announce.belongsTo(models.certificate, {
foreignKey: {
name: 'certificateOfProfilesIdKey',
field: 'certificate_of_profiles_id',
},
targetKey: 'id',
as: 'certificateOfProfiles',
});
Announce.belongsToMany(models['care-giver'], {
through: 'proposedAnnounce',
foreignKey: 'announce_id',
otherKey: 'care_giver_id',
as: 'careGiverThroughProposedAnnounces',
});
Announce.hasMany(models.technicalInfo, {
foreignKey: {
name: 'announceIdKey',
field: 'announce_id',
},
as: 'technicalInfos',
});
Announce.hasMany(models.schedule, {
foreignKey: {
name: 'announceIdKey',
field: 'announce_id',
},
as: 'schedules',
});
Announce.hasMany(models.application, {
foreignKey: {
name: 'announceIdKey',
field: 'announce_id',
},
as: 'applications',
});
Announce.hasMany(models.mission, {
foreignKey: {
name: 'announceIdKey',
field: 'announce_id',
},
as: 'missions',
});
Announce.hasMany(models.price, {
foreignKey: {
name: 'priceIdKey',
field: 'price_id',
},
as: 'prices',
});
Announce.hasOne(models.lead, {
foreignKey: {
name: 'announceIdKey',
field: 'announce_id',
},
as: 'lead',
});
};
return Announce;
};