-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend/referentiels): mise à jour d'un statut d'une action et r…
…ecalcul du score, ajout de tRPC et des tests associés
- Loading branch information
Showing
15 changed files
with
710 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/src/referentiels/compute-score/compute-score.router.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import z from 'zod'; | ||
import { TrpcService } from '../../trpc/trpc.service'; | ||
import { getReferentielScoresRequestSchema } from '../models/get-referentiel-scores.request'; | ||
import { ReferentielType } from '../models/referentiel.enum'; | ||
import ReferentielsScoringService from '../services/referentiels-scoring.service'; | ||
|
||
export const computeScoreRequestSchema = z.object({ | ||
referentielId: z.nativeEnum(ReferentielType), | ||
collectiviteId: z.number().int(), | ||
parameters: getReferentielScoresRequestSchema, | ||
}); | ||
|
||
@Injectable() | ||
export class ComputeScoreRouter { | ||
constructor( | ||
private readonly trpc: TrpcService, | ||
private readonly service: ReferentielsScoringService | ||
) {} | ||
|
||
router = this.trpc.router({ | ||
computeScore: this.trpc.authedProcedure | ||
.input(computeScoreRequestSchema) | ||
.query(({ input, ctx }) => { | ||
return this.service.computeScoreForCollectivite( | ||
input.referentielId, | ||
input.collectiviteId, | ||
input.parameters, | ||
ctx.user | ||
); | ||
}), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
backend/src/referentiels/snapshots/score-snaphots.router.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import z from 'zod'; | ||
import { TrpcService } from '../../trpc/trpc.service'; | ||
import { ReferentielType } from '../models/referentiel.enum'; | ||
import { ScoreJalon } from '../models/score-jalon.enum'; | ||
import ReferentielsScoringSnapshotsService from '../services/referentiels-scoring-snapshots.service'; | ||
import ReferentielsScoringService from '../services/referentiels-scoring.service'; | ||
|
||
export const getScoreSnapshotInfosTrpcRequestSchema = z.object({ | ||
referentielId: z.nativeEnum(ReferentielType), | ||
collectiviteId: z.number().int(), | ||
parameters: z.object({ | ||
typesJalon: z.nativeEnum(ScoreJalon).array(), | ||
}), | ||
}); | ||
|
||
export const getFullScoreSnapshotTrpcRequestSchema = z.object({ | ||
referentielId: z.nativeEnum(ReferentielType), | ||
collectiviteId: z.number().int(), | ||
snapshotRef: z.string(), | ||
}); | ||
|
||
@Injectable() | ||
export class ScoreSnapshotsRouter { | ||
constructor( | ||
private readonly trpc: TrpcService, | ||
private readonly service: ReferentielsScoringSnapshotsService, | ||
private readonly referentielsScoringService: ReferentielsScoringService | ||
) {} | ||
|
||
router = this.trpc.router({ | ||
listSummary: this.trpc.authedProcedure | ||
.input(getScoreSnapshotInfosTrpcRequestSchema) | ||
.query(({ input, ctx }) => { | ||
return this.service.listSummary( | ||
input.collectiviteId, | ||
input.referentielId, | ||
input.parameters | ||
); | ||
}), | ||
getCurrentFullScore: this.trpc.authedProcedure | ||
.input( | ||
z.object({ | ||
referentielId: z.nativeEnum(ReferentielType), | ||
collectiviteId: z.number().int(), | ||
}) | ||
) | ||
.query(({ input, ctx }) => { | ||
return this.referentielsScoringService.getOrCreateCurrentScore( | ||
input.collectiviteId, | ||
input.referentielId | ||
); | ||
}), | ||
get: this.trpc.authedProcedure | ||
.input(getFullScoreSnapshotTrpcRequestSchema) | ||
.query(({ input, ctx }) => { | ||
if ( | ||
input.snapshotRef === | ||
ReferentielsScoringSnapshotsService.SCORE_COURANT_SNAPSHOT_REF | ||
) { | ||
return this.referentielsScoringService.getOrCreateCurrentScore( | ||
input.collectiviteId, | ||
input.referentielId | ||
); | ||
} else { | ||
return this.service.get( | ||
input.collectiviteId, | ||
input.referentielId, | ||
input.snapshotRef | ||
); | ||
} | ||
}), | ||
delete: this.trpc.authedProcedure | ||
.input(getFullScoreSnapshotTrpcRequestSchema) | ||
.query(({ input, ctx }) => { | ||
return this.service.delete( | ||
input.collectiviteId, | ||
input.referentielId, | ||
input.snapshotRef, | ||
ctx.user | ||
); | ||
}), | ||
}); | ||
} |
Oops, something went wrong.