Skip to content

Commit

Permalink
add routes clients and pings
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitSerrano committed Oct 18, 2024
1 parent b3e29d8 commit 33c3a2a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 20 deletions.
12 changes: 7 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ETQP, je peux modifier le nombre de points pour toutes les questions quand je modifie le nombre de points pour un exo
ETQP, je veux pouvoir éditer le texte d'un texte à trous directement dans la page
ETQP, j'ai accès à un support (Crisp)
ETQBenoit, j'ai accès à un éditeur de BDD (Forest Admin)
ETQP, j'ai un onboarding qui me permet d'inscrire les écoles où je taffe
ETQDev, j'ai un script pour importer toutes les données de prod
ETQU, quand je vais sur /clients, je vois la liste des clients
ETQU, quand je clique sur un client, je suis redirigé vers clients/id
ETQU, sur la page /clients/id, j'ai un front qui affiche up ou down
ETQU, sur la page /clients/id, je vois trois encadrés : minutes, heures, jours
ETQU, sur la page /clients/id, je vois les données qui viennent du back-end
ETQU, sur la page /clients/id, je vois un résumé des derniers évènements
14 changes: 0 additions & 14 deletions src/client/src/lib/useUpdateDocumentTitle.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/modules/client/client.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function buildClientController() {
const clientController = {
createClient,
assertIsClientUp,
getAllClients,
};

return clientController;
Expand All @@ -19,4 +20,8 @@ function buildClientController() {
async function assertIsClientUp(params: { urlParams: { name: Client['name'] } }) {
return clientService.assertIsClientUp(params.urlParams.name);
}

async function getAllClients() {
return clientService.getAllClients();
}
}
5 changes: 5 additions & 0 deletions src/modules/client/client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ function buildClientService() {
const clientService = {
createClient,
assertIsClientUp,
getAllClients,
};

return clientService;

async function getAllClients() {
return clientRepository.find({});
}

async function createClient(name: Client['name']) {
const result = await clientRepository.insert({ name });
return { clientId: result.identifiers[0].id };
Expand Down
5 changes: 5 additions & 0 deletions src/modules/ping/ping.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ function buildPingController() {
const pingService = buildPingService();
const pingController = {
createPing,
getAllPings,
};

return pingController;

async function createPing(params: { urlParams: { clientId: string } }) {
return pingService.createPing(params.urlParams.clientId);
}

async function getAllPings() {
return pingService.getAllPings();
}
}
6 changes: 5 additions & 1 deletion src/modules/ping/ping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ function buildPingService() {

const pingService = {
createPing,
getAllPings,
assertHasClientBeenPingedRecently,
};

return pingService;

async function getAllPings() {
return pingRepository.find({ relations: ['client'] });
}

async function createPing(clientId: Client['id']) {
await pingRepository.insert({ client: { id: clientId } });
return true;
Expand All @@ -32,7 +37,6 @@ function buildPingService() {
createdAt: MoreThan(lastPingThresholdDate.toISOString()),
},
});
console.log(pings);
if (pings.length === 0) {
throw new Error(
`No ping found ${MAX_DELAY_SINCE_LAST_PING} ms ago for clientId ${clientId}`,
Expand Down
6 changes: 6 additions & 0 deletions src/router/clientRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const clientRoutes: Array<routeType<any, any, any>> = [
path: '/clients/:name/health',
controller: clientController.assertIsClientUp,
},

{
method: 'GET',
path: '/clients',
controller: clientController.getAllClients,
},
];

export { clientRoutes };
5 changes: 5 additions & 0 deletions src/router/pingRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const pingRoutes: Array<routeType<any, any, any>> = [
path: '/clients/:clientId/pings',
controller: pingController.createPing,
},
{
method: 'GET',
path: '/pings',
controller: pingController.getAllPings,
},
];

export { pingRoutes };

0 comments on commit 33c3a2a

Please sign in to comment.