Skip to content

Commit

Permalink
Aftral: [premieroctet#153] No duplicate code on resource TEMPLATE
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaauvray committed Sep 20, 2024
1 parent 67e14b9 commit e9e524d
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const ResourceSchema = new Schema({
}, {...schemaOptions, ...BLOCK_DISCRIMINATOR})

ResourceSchema.pre('validate', async function(next) {
return mongoose.models.resource.exists({_id: {$ne: this._id}, code: this.code})
if (!!this?.origin) {
return next()
}
return mongoose.models.resource.exists({_id: {$ne: this._id}, code: this.code, origin: null})
.then(exists => {
if (exists) {
return next(new BadRequestError(`Une resource de code ${this.code} existe déjà`))
Expand Down

0 comments on commit e9e524d

Please sign in to comment.