Skip to content
Snippets Groups Projects
Commit 48383420 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix: fix duplication bug from aptic structure

parent 43eb15b7
No related branches found
No related tags found
3 merge requests!27Recette,!26Dev,!22Feat/admin structure delete
......@@ -45,6 +45,7 @@ export class ApticStructuresService {
private async createApticStructures(structure: ApticStructure): Promise<any> {
this.structureAlreadyExist(structure).then((exist) => {
if (!exist) {
Logger.log(`Create structure : ${structure.presence_name}`, 'ApticStructuresService - createApticStructures');
const createdStructure = new this.structureModel();
createdStructure.coord = [structure.gps_lng, structure.gps_lat];
createdStructure.structureName = structure.presence_name;
......@@ -61,16 +62,17 @@ export class ApticStructuresService {
}
private async structureAlreadyExist(structure: ApticStructure): Promise<boolean> {
const existingStructure = await this.structureModel
let existingStructure = await this.structureModel
.findOne({
structureName: { $regex: structure.presence_name, $options: 'i' },
})
.exec();
// Check without regex for case like 'TINEBRA*DANIEL/DANIEL/'
if (!existingStructure) {
existingStructure = await this.structureModel.findOne({ structureName: structure.presence_name }).exec();
}
if (existingStructure) {
Logger.log(
`Cannot create structure, it already exist : ${existingStructure.structureName}`,
'ApticStructuresService - structureAlreadyExist'
);
// Add aptic label if it's not the case
if (!existingStructure.labelsQualifications.includes('passNumerique')) {
existingStructure.labelsQualifications.push('passNumerique');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment