Skip to content

Commit

Permalink
fix: route fusion commune
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Apr 9, 2024
1 parent 27ea2ca commit 9551ca5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions apps/api/src/modules/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@ export class AdminService {

for (const voie of voies) {
voie._bal = bal._id;
voie.commune = bal.commune;
const newId = new ObjectId();
idVoies[voie._id.toHexString()] = newId;
voie._id = newId;
}

for (const toponyme of toponymes) {
toponyme._bal = bal._id;
toponyme.commune = bal.commune;
const newId = new ObjectId();
idToponymes[toponyme._id.toHexString()] = newId;
toponyme._id = newId;
}

for (const numero of numeros) {
numero._bal = bal._id;
numero.commune = bal.commune;
numero._id = new ObjectId();
numero.voie = idVoies[numero.voie.toHexString()];
numero.toponyme = numero.toponyme
Expand All @@ -54,6 +51,25 @@ export class AdminService {
}
}

private replaceBalCommune(
bal: BaseLocale,
voies: Voie[],
toponymes: Toponyme[],
numeros: Numero[],
) {
for (const voie of voies) {
voie.commune = bal.commune;
}

for (const toponyme of toponymes) {
toponyme.commune = bal.commune;
}

for (const numero of numeros) {
numero.commune = bal.commune;
}
}

public async fusionCommunes({
codeCommune,
nom,
Expand All @@ -69,6 +85,7 @@ export class AdminService {
const { numeros, voies, toponymes } =
await this.baseLocaleService.findMetas(balId);
this.replaceBalIds(newbaseLocale, voies, toponymes, numeros);
this.replaceBalCommune(newbaseLocale, voies, toponymes, numeros);
await this.baseLocaleService.populate(
newbaseLocale,
{
Expand All @@ -81,6 +98,7 @@ export class AdminService {
} else {
const { numeros, voies, toponymes } =
await this.populateService.extract(codeCommune);
this.replaceBalCommune(newbaseLocale, voies, toponymes, numeros);
await this.baseLocaleService.populate(
newbaseLocale,
{
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/admin/dto/fusion_bases_locales.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class FusionCommunesDTO {

@ApiProperty({ required: true, nullable: false })
@ArrayNotEmpty()
@IsEmail(null, { each: true })
@IsEmail({}, { each: true })
emails: string[];

@ApiProperty({
Expand Down

0 comments on commit 9551ca5

Please sign in to comment.