Skip to content

Commit

Permalink
Backend - Adapte les fichiers de trajectoires aux nouvelles conventio…
Browse files Browse the repository at this point in the history
…ns de nommage
  • Loading branch information
amandinejacquelin committed Oct 1, 2024
1 parent b24f19e commit e356d7c
Show file tree
Hide file tree
Showing 9 changed files with 1,660 additions and 1,675 deletions.
44 changes: 22 additions & 22 deletions backend/src/indicateurs/controllers/trajectoires.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ApiOkResponse, ApiResponse, ApiTags } from '@nestjs/swagger';
import { NextFunction, Response } from 'express';
import { PublicEndpoint } from '../../auth/decorators/public-endpoint.decorator';
import { TokenInfo } from '../../auth/decorators/token-info.decorators';
import type { SupabaseJwtPayload } from '../../auth/models/auth.models';
import { SupabaseJwtPayload } from '../../auth/models/supabase-jwt.models';
import { CollectiviteRequestClass } from '../../collectivites/models/collectivite.request';
import {
calculTrajectoireRequestSchema,
Expand All @@ -29,21 +29,21 @@ import TrajectoiresXlsxService from '../services/trajectoires-xlsx.service';
* Création des classes de requête/réponse à partir du schema pour générer automatiquement la documentation OpenAPI et la validation des entrées
*/
export class CalculTrajectoireResponseClass extends createZodDto(
calculTrajectoireResponseSchema
calculTrajectoireResponseSchema,
) {}
export class CalculTrajectoireRequestClass extends createZodDto(
calculTrajectoireRequestSchema
calculTrajectoireRequestSchema,
) {}

export class ModeleTrajectoireTelechargementRequestClass extends createZodDto(
modeleTrajectoireTelechargementRequestSchema
modeleTrajectoireTelechargementRequestSchema,
) {}

export class VerificationTrajectoireRequestClass extends createZodDto(
verificationTrajectoireRequestSchema
verificationTrajectoireRequestSchema,
) {}
export class VerificationDonneesSNBCResponseClass extends createZodDto(
verificationDonneesSNBCResponseSchema
verificationDonneesSNBCResponseSchema,
) {}

@ApiTags('Trajectoires')
Expand All @@ -54,39 +54,39 @@ export class TrajectoiresController {
constructor(
private readonly trajectoiresDataService: TrajectoiresDataService,
private readonly trajectoiresSpreadsheetService: TrajectoiresSpreadsheetService,
private readonly trajectoiresXlsxService: TrajectoiresXlsxService
private readonly trajectoiresXlsxService: TrajectoiresXlsxService,
) {}

@Get('')
@ApiResponse({ type: CalculTrajectoireResponseClass })
async calculeTrajectoireSnbc(
@Query() request: CalculTrajectoireRequestClass,
@TokenInfo() tokenInfo: SupabaseJwtPayload
@TokenInfo() tokenInfo: SupabaseJwtPayload,
): Promise<CalculTrajectoireResponseClass> {
this.logger.log(
`Calcul de la trajectoire SNBC pour la collectivité ${request.collectivite_id}`
`Calcul de la trajectoire SNBC pour la collectivité ${request.collectiviteId}`,
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { spreadsheet_id, ...response } =
await this.trajectoiresSpreadsheetService.calculeTrajectoireSnbc(
request,
tokenInfo
tokenInfo,
);
return response;
}

@Delete('')
async deleteTrajectoireSnbc(
@Query() request: CollectiviteRequestClass,
@TokenInfo() tokenInfo: SupabaseJwtPayload
@TokenInfo() tokenInfo: SupabaseJwtPayload,
): Promise<void> {
this.logger.log(
`Suppression de la trajectoire SNBC pour la collectivité ${request.collectivite_id}`
`Suppression de la trajectoire SNBC pour la collectivité ${request.collectiviteId}`,
);
await this.trajectoiresDataService.deleteTrajectoireSnbc(
request.collectivite_id,
request.collectiviteId,
undefined,
tokenInfo
tokenInfo,
);
}

Expand All @@ -99,13 +99,13 @@ export class TrajectoiresController {
downloadModeleSnbc(
@Query() request: ModeleTrajectoireTelechargementRequestClass,
@Res() res: Response,
@Next() next: NextFunction
@Next() next: NextFunction,
) {
this.logger.log(`Téléchargement du modele de trajectoire SNBC`);
this.trajectoiresXlsxService.downloadModeleTrajectoireSnbc(
request,
res,
next
next,
);
}

Expand All @@ -118,16 +118,16 @@ export class TrajectoiresController {
@Query() request: CollectiviteRequestClass,
@TokenInfo() tokenInfo: SupabaseJwtPayload,
@Res() res: Response,
@Next() next: NextFunction
@Next() next: NextFunction,
) {
this.logger.log(
`Téléchargement de la trajectoire SNBC pour la collectivité ${request.collectivite_id}`
`Téléchargement de la trajectoire SNBC pour la collectivité ${request.collectiviteId}`,
);
this.trajectoiresXlsxService.downloadTrajectoireSnbc(
request,
tokenInfo,
res,
next
next,
);
}

Expand All @@ -139,16 +139,16 @@ export class TrajectoiresController {
})
async verificationDonneesSnbc(
@Query() request: VerificationTrajectoireRequestClass,
@TokenInfo() tokenInfo: SupabaseJwtPayload
@TokenInfo() tokenInfo: SupabaseJwtPayload,
): Promise<VerificationDonneesSNBCResponseClass> {
this.logger.log(
`Vérifie la possibilité de lancer le calcul de la trajectoire SNBC pour la collectivité ${request.collectivite_id}`
`Vérifie la possibilité de lancer le calcul de la trajectoire SNBC pour la collectivité ${request.collectiviteId}`,
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { valeurs, ...response } =
await this.trajectoiresDataService.verificationDonneesSnbc(
request,
tokenInfo
tokenInfo,
);
if (!request.epci_info) {
delete response.epci;
Expand Down
5 changes: 3 additions & 2 deletions backend/src/indicateurs/models/calcultrajectoire.models.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { extendApi, extendZodWithOpenApi } from '@anatine/zod-openapi';
import { z } from 'zod';
import { epciSchema } from '../../collectivites/models/collectivite.models';
import { epciSchema } from '../../collectivites/models/epci.table';
import { collectiviteRequestSchema } from '../../collectivites/models/collectivite.request';
import {
indicateurAvecValeursSchema,
IndicateurValeurType,
} from './indicateur.models';
} from './indicateur-valeur.table';

extendZodWithOpenApi(z);

export enum CalculTrajectoireReset {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/indicateurs/routers/trajectoires.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from 'zod';
import {
SupabaseJwtPayload,
SupabaseRole,
} from '../../auth/models/auth.models';
} from '../../auth/models/supabase-jwt.models';
import { TrpcService } from '../../trpc/services/trpc.service';
import TrajectoiresSpreadsheetService from '../services/trajectoires-spreadsheet.service';

Expand All @@ -18,7 +18,7 @@ export class TrajectoiresRouter {
snbc: this.trpc.procedure
.input(
z.object({
collectivite_id: z.number(),
collectiviteId: z.number(),
conserve_fichier_temporaire: z.boolean().optional(),
}),
)
Expand Down
Loading

0 comments on commit e356d7c

Please sign in to comment.