From eb5440fa0a28e80ee49efcd6cf45007f990b041a Mon Sep 17 00:00:00 2001 From: Guilhem CARRON <gcarron@grandlyon.com> Date: Thu, 24 Mar 2022 10:22:26 +0000 Subject: [PATCH] Feat/us82 remove structure count endpoints --- docker-compose.yml | 14 ++++++-- .../services/structure.service.spec.ts | 4 +-- .../structures-search.service.spec.ts | 2 +- src/structures/services/structures.service.ts | 36 ------------------- src/structures/structures.controller.spec.ts | 5 --- src/structures/structures.controller.ts | 24 ------------- src/users/users.service.ts | 2 +- 7 files changed, 15 insertions(+), 72 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c35a22a19..dfd119ce1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,8 @@ version: '2' services: service-ram: - image: registry.forge.grandlyon.com/web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server:dev + image: registry.forge.grandlyon.com/web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server:dev + container_name: resin-back ports: - ${SERVICE_API_BIND_PORT}:3000 extra_hosts: @@ -35,6 +36,7 @@ services: database-ram: image: bitnami/mongodb:4.2.3 user: root + container_name: resin-db environment: MONGODB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD} MONGODB_USERNAME: ${MONGO_NON_ROOT_USERNAME} @@ -50,7 +52,8 @@ services: mongo-express: image: mongo-express - restart: unless-stopped + restart: unless-stopped + container_name: resin-mongo-express depends_on: - database-ram networks: @@ -67,6 +70,7 @@ services: ghost: image: ghost:latest restart: always + container_name: resin-ghost ports: - ${GHOST_PORT}:2368 environment: @@ -78,11 +82,14 @@ services: database__connection__database: ghost # this url value is just an example, and is likely wrong for your environment! url: http://localhost:${GHOST_PORT} + depends_on: + - ghost-db volumes: - ghost-content:/var/lib/ghost/content ghost-db: image: mysql:5.7 + container_name: resin-ghost-db restart: always environment: MYSQL_ROOT_PASSWORD: ${GHOST_DB_PASSWORD} @@ -92,6 +99,7 @@ services: es01: image: elasticsearch:7.16.2 restart: unless-stopped + container_name: resin-es environment: node.name: es01 cluster.name: es-docker-cluster @@ -108,7 +116,7 @@ services: kib01: image: docker.elastic.co/kibana/kibana:7.6.1 restart: unless-stopped - container_name: kib01 + container_name: resin-kib ports: - ${KIBANA_PORT}:5601 environment: diff --git a/src/structures/services/structure.service.spec.ts b/src/structures/services/structure.service.spec.ts index 567946859..5f3b0a28c 100644 --- a/src/structures/services/structure.service.spec.ts +++ b/src/structures/services/structure.service.spec.ts @@ -428,7 +428,7 @@ describe('StructuresService', () => { updatedAt: 'Thu Jan 20 2022 10:06:19 GMT+0100 (heure normale d’Europe centrale)', dataShareConsentDate: new Date(), } as StructureDocument); - let res = await service.getAllDataConsentPendingStructures(user); + const res = await service.getAllDataConsentPendingStructures(user); expect(res.length).toBe(1); }); it('should get no consent', async () => { @@ -478,7 +478,7 @@ describe('StructuresService', () => { updatedAt: 'Thu Jan 20 2022 10:06:19 GMT+0100 (heure normale d’Europe centrale)', dataShareConsentDate: new Date(), } as StructureDocument); - let res = await service.getAllDataConsentPendingStructures(user); + const res = await service.getAllDataConsentPendingStructures(user); expect(res.length).toBe(0); }); }); diff --git a/src/structures/services/structures-search.service.spec.ts b/src/structures/services/structures-search.service.spec.ts index ed226632d..67fd4e9ae 100644 --- a/src/structures/services/structures-search.service.spec.ts +++ b/src/structures/services/structures-search.service.spec.ts @@ -49,7 +49,7 @@ describe('StructuresSearchService', () => { // wait for the new structures to be indexed before search await service.refreshIndexStructure(); // but we still need to wait the refresh to be done - await new Promise((r) => setTimeout(r, 1000)); + await new Promise((r) => setTimeout(r, 2000)); }); it('should find maisons de la métropole', async () => { diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index b16568d30..12a67717e 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -410,42 +410,6 @@ export class StructuresService { }); } - /** - * Count every value occurence of a given key - * @param key structure key - * @return [{id: 'key', count: 'value'}] - */ - public async countByStructureKey(key: string, selected: { id: string; text: string }[]): Promise<any> { - const uniqueElements = await this.structureModel.distinct(key).exec(); - return Promise.all( - uniqueElements.map(async (value) => { - const keyList: FilterQuery<DocumentDefinition<StructureDocument>>[] = []; - keyList.push({ - [key]: { $elemMatch: { $eq: value } }, - deletedAt: { $exists: false }, - accountVerified: true, - }); - if (selected && selected.length > 0) { - for (const val of selected) { - keyList.push({ - [val.text]: { $elemMatch: { $eq: val.id } }, - deletedAt: { $exists: false }, - accountVerified: true, - }); - } - } - return { - id: value, - count: await this.structureModel - .countDocuments({ - $and: keyList, - }) - .exec(), - }; - }) - ); - } - public getCoord(numero: string, address: string, zipcode: string): Observable<AxiosResponse<any>> { const req = 'https://download.data.grandlyon.com/geocoding/photon/api?q=' + numero + ' ' + address + ' ' + zipcode; Logger.log(`getCoord - Request : ${req}`, 'StructureService'); diff --git a/src/structures/structures.controller.spec.ts b/src/structures/structures.controller.spec.ts index 6404d10cf..2f569d8fa 100644 --- a/src/structures/structures.controller.spec.ts +++ b/src/structures/structures.controller.spec.ts @@ -143,11 +143,6 @@ describe('AuthController', () => { expect(res).toBeTruthy(); }); - it('should count', async () => { - const res = controller.countCategories([{ id: 'equipmentsAndServices', text: 'wifiEnAccesLibre' }]); - expect(res).toBeTruthy(); - }); - it('should search an address', async () => { const res = controller.searchAddress({ searchQuery: 'Rue Alphonse Daudet' }); expect(res).toBeTruthy(); diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index 24b25f37d..db0d06286 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -119,30 +119,6 @@ export class StructuresController { return this.userService.updateStructureLinkedClaim(user.email, idStructure, structure); } - @Post('count') - public async countCategories( - @Body() - selectedFilter: { id: string; text: string }[] - ): Promise<Array<{ id: string; count: number }>> { - const data = await Promise.all([ - this.structureService.countByStructureKey('proceduresAccompaniment', selectedFilter), - - this.structureService.countByStructureKey('accessRight', selectedFilter), - this.structureService.countByStructureKey('baseSkills', selectedFilter), - this.structureService.countByStructureKey('parentingHelp', selectedFilter), - this.structureService.countByStructureKey('digitalCultureSecurity', selectedFilter), - this.structureService.countByStructureKey('socialAndProfessional', selectedFilter), - - this.structureService.countByStructureKey('publicsAccompaniment', selectedFilter), - this.structureService.countByStructureKey('labelsQualifications', selectedFilter), - this.structureService.countByStructureKey('publics', selectedFilter), - this.structureService.countByStructureKey('accessModality', selectedFilter), - this.structureService.countByStructureKey('equipmentsAndServices', selectedFilter), - ]); - // Return a concat of all arrays - return data.reduce((a, b) => [...a, ...b]); - } - @Post('address') public async searchAddress(@Body() data: { searchQuery: string }) { return this.structureService.searchAddress(data); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index ce0e954d6..632c62408 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -223,7 +223,7 @@ export class UsersService { const html = await ejs.renderFile(ejsPath, { config, - status: status ? 'accepté' : 'refusée', + status: status ? 'acceptée' : 'refusée', name: structureName, }); this.mailerService.send(userEmail, jsonConfig.subject, html); -- GitLab