Since this morning, when we want to add some string in text array, the array is always empty.
Feature(s) impacted
Forms with checkboxes
Observed behavior
My entity:
const { v4: uuidv4 } = require('uuid');
const isEmpty = require('lodash/isEmpty');
// This model was generated by Lumber. 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 = (mongoose, Mongoose) => {
// This section contains the properties of your model, mapped to your collection's properties.
const schema = Mongoose.Schema(
{
name: {
type: String,
required: true,
},
logo: {
type: String,
},
type: {
type: String,
required: true,
default: 'corporation',
},
siret: {
type: String,
},
domain: {
type: String,
match: [/\.intent$/, 'Invalid domain'],
required: true,
immutable: true,
unique: true,
},
entityRoles: [
{
_id: false,
name: String,
},
],
stringifiedRoles: {
type: String,
},
activated: {
type: Boolean,
},
settings: {
type: JSON,
},
},
{
timestamps: { createdAt: 'creationDate', updatedAt: 'lastUpdateDate' },
versionKey: false, // You should be aware of the outcome after set to false
},
);
schema.pre('save', async function () {
if (isEmpty(this.logo)) {
this.logo = `${process.env.BASE_LOGO_URL}${uuidv4()}.png`;
}
console.log('this', JSON.stringify(this));
console.log('this.entityRoles', JSON.stringify(this.entityRoles));
if (this.entityRoles) {
_hasAssetOwnerAndServiceProviderRoles(this.entityRoles);
}
});
schema.pre('findOneAndUpdate', function (next) {
const { $set } = this._update;
console.log('this._update', JSON.stringify(this._update));
if ($set.entityRoles) {
_hasAssetOwnerAndServiceProviderRoles($set.entityRoles);
}
next();
});
return mongoose.model('entities', schema, 'entities');
};
/**
* Check if there is assetOwner and serviceProvider in entityRoles
* @param {Object[]} entityRoles - the entityRoles
* @returns {boolean} - true|false
*/
function _hasAssetOwnerAndServiceProviderRoles(entityRoles) {
console.log('entityRoles', JSON.stringify(entityRoles));
if (
entityRoles.some((role) => role.name === 'assetOwner') &&
entityRoles.some((role) => role.name === 'serviceProvider')
) {
throw new Error(
'Vous ne pouvez pas définir un rôle "assetOwner" et un rôle "serviceProvider" pour une entité.',
);
}
if (entityRoles.length === 0) {
throw new Error('Vous devez forçément définir un rôle pour une entité.');
}
return true;
}
Expected behavior
Have an array of string (it worked this morning since multiple weeks ^^)
Failure Logs
Context
- Project name: intent
- Environment name: Production and Sandbox
- Agent (forest package) name & version: “forest-express-mongoose”: “^9.2.4”
- Database type: Mongodb
- Recent changes made on your end if any: Nothing