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 { ...@@ -45,6 +45,7 @@ export class ApticStructuresService {
private async createApticStructures(structure: ApticStructure): Promise<any> { private async createApticStructures(structure: ApticStructure): Promise<any> {
this.structureAlreadyExist(structure).then((exist) => { this.structureAlreadyExist(structure).then((exist) => {
if (!exist) { if (!exist) {
Logger.log(`Create structure : ${structure.presence_name}`, 'ApticStructuresService - createApticStructures');
const createdStructure = new this.structureModel(); const createdStructure = new this.structureModel();
createdStructure.coord = [structure.gps_lng, structure.gps_lat]; createdStructure.coord = [structure.gps_lng, structure.gps_lat];
createdStructure.structureName = structure.presence_name; createdStructure.structureName = structure.presence_name;
...@@ -61,16 +62,17 @@ export class ApticStructuresService { ...@@ -61,16 +62,17 @@ export class ApticStructuresService {
} }
private async structureAlreadyExist(structure: ApticStructure): Promise<boolean> { private async structureAlreadyExist(structure: ApticStructure): Promise<boolean> {
const existingStructure = await this.structureModel let existingStructure = await this.structureModel
.findOne({ .findOne({
structureName: { $regex: structure.presence_name, $options: 'i' }, structureName: { $regex: structure.presence_name, $options: 'i' },
}) })
.exec(); .exec();
// Check without regex for case like 'TINEBRA*DANIEL/DANIEL/'
if (!existingStructure) {
existingStructure = await this.structureModel.findOne({ structureName: structure.presence_name }).exec();
}
if (existingStructure) { if (existingStructure) {
Logger.log(
`Cannot create structure, it already exist : ${existingStructure.structureName}`,
'ApticStructuresService - structureAlreadyExist'
);
// Add aptic label if it's not the case // Add aptic label if it's not the case
if (!existingStructure.labelsQualifications.includes('passNumerique')) { if (!existingStructure.labelsQualifications.includes('passNumerique')) {
existingStructure.labelsQualifications.push('passNumerique'); existingStructure.labelsQualifications.push('passNumerique');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment