Skip to content

Commit

Permalink
feat: add route getSignalementById
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Jun 18, 2024
1 parent c0e25fb commit 10c147f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
5 changes: 4 additions & 1 deletion contexts/signalement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export function SignalementContextProvider(props: ChildrenProps) {

const fetchSignalements = useCallback(async () => {
const signalements = await SignalementsService.getSignalements(
baseLocale.commune
baseLocale.commune,
undefined,
undefined,
Signalement.status.PENDING
);
setSignalements(signalements);
}, [baseLocale.commune]);
Expand Down
18 changes: 18 additions & 0 deletions lib/openapi-signalement/services/SignalementsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,22 @@ export class SignalementsService {
});
}

/**
* Get signalement by id
* @param idSignalement
* @returns Signalement
* @throws ApiError
*/
public static getSignalementById(
idSignalement: string,
): CancelablePromise<Signalement> {
return __request(OpenAPI, {
method: 'GET',
url: '/signalements/{idSignalement}',
path: {
'idSignalement': idSignalement,
},
});
}

}
11 changes: 4 additions & 7 deletions pages/bal/[balId]/signalements/[idSignalement].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,8 @@ export async function getServerSideProps({ params }) {
const { baseLocale, commune, voies, toponymes }: BaseEditorProps =
await getBaseEditorProps(balId);

const signalements = await SignalementsService.getSignalements(
baseLocale.commune
);

const signalement = signalements.find(
(signalement) => signalement._id === params.idSignalement
const signalement = await SignalementsService.getSignalementById(
params.idSignalement
);

if (signalement.changesRequested.positions) {
Expand All @@ -258,7 +254,8 @@ export async function getServerSideProps({ params }) {
);
} else if (signalement.type === Signalement.type.LOCATION_TO_CREATE) {
existingLocation = voies.find(
(voie) => voie.nom === signalement.existingLocation.nom
(voie) =>
voie.nom === (signalement.existingLocation as ExistingVoie).nom
);
}

Expand Down
10 changes: 8 additions & 2 deletions pages/bal/[balId]/signalements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ function SignalementsPage({ baseLocale, signalements: initialSignalements }) {

const updateSignalements = async () => {
const signalements = await SignalementsService.getSignalements(
baseLocale.commune
baseLocale.commune,
undefined,
undefined,
Signalement.status.PENDING
);
setSignalements(signalements);
};
Expand Down Expand Up @@ -244,7 +247,10 @@ export async function getServerSideProps({ params }) {
await getBaseEditorProps(balId);

const signalements = await SignalementsService.getSignalements(
baseLocale.commune
baseLocale.commune,
undefined,
undefined,
Signalement.status.PENDING
);

return {
Expand Down

0 comments on commit 10c147f

Please sign in to comment.