From c234fe09f2c73d566a50b886d38c1a094f0774a5 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Fri, 16 Sep 2022 08:53:31 +0000 Subject: [PATCH] fix(annuaire): Remove unverified users from list --- src/users/services/userRegistry.service.spec.ts | 2 ++ src/users/services/userRegistry.service.ts | 11 +++++++++-- src/users/services/users.service.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/users/services/userRegistry.service.spec.ts b/src/users/services/userRegistry.service.spec.ts index 0df3a840e..87eafc904 100644 --- a/src/users/services/userRegistry.service.spec.ts +++ b/src/users/services/userRegistry.service.spec.ts @@ -14,6 +14,8 @@ describe('userRegistryService', () => { let service: UserRegistryService; const mockUserRegistryModel = { find: jest.fn(() => mockUserRegistryModel), + where: jest.fn(() => mockUserRegistryModel), + equals: jest.fn(() => mockUserRegistryModel), populate: jest.fn(() => mockUserRegistryModel), sort: jest.fn(() => mockUserRegistryModel), select: jest.fn(() => mockUserRegistryModel), diff --git a/src/users/services/userRegistry.service.ts b/src/users/services/userRegistry.service.ts index 1a7f687b5..b24ce7663 100644 --- a/src/users/services/userRegistry.service.ts +++ b/src/users/services/userRegistry.service.ts @@ -24,6 +24,8 @@ export class UserRegistryService { public async findAllForIndexation(): Promise<IUserRegistry[]> { return this.userModel .find() + .where('emailVerified') + .equals(true) .select('name surname _id job employer ') .populate('job employer') .sort({ surname: 1 }) @@ -33,6 +35,8 @@ export class UserRegistryService { public async countAllUserRegistry(): Promise<number> { return this.userModel .find() + .where('emailVerified') + .equals(true) .populate('employer') .populate('job') .select('name surname employer job _id ') @@ -46,6 +50,8 @@ export class UserRegistryService { const count = await this.countAllUserRegistry(); const docs = await this.userModel .find() + .where('emailVerified') + .equals(true) .populate('employer') .populate('job') .select('name surname employer job _id ') @@ -67,9 +73,8 @@ export class UserRegistryService { employersNames.findIndex((n) => user.employer.name === n) > -1 ); } - if (employersList?.length) { - return users.filter((user) => employersNames.findIndex((n) => user.employer.name === n) > -1); + return users.filter((user) => employersNames.findIndex((n) => user.employer?.name === n) > -1); } if (jobList?.length) { return users.filter((user) => jobNames.findIndex((n) => user.job.name === n) > -1); @@ -108,6 +113,8 @@ export class UserRegistryService { }, ], }) + .where('emailVerified') + .equals(true) .select('name surname employer job _id ') .populate('employer job') .sort({ surname: 1 }) diff --git a/src/users/services/users.service.ts b/src/users/services/users.service.ts index 19c9d58b6..9d3df36e2 100644 --- a/src/users/services/users.service.ts +++ b/src/users/services/users.service.ts @@ -18,8 +18,8 @@ import { JobDocument } from '../schemas/job.schema'; import { PersonalOfferDocument } from '../../personal-offers/schemas/personal-offer.schema'; import { UpdateDetailsDto } from '../dto/update-details.dto'; import { DescriptionDto } from '../dto/description.dto'; -import { UserRegistrySearchService } from './userRegistry-search.service'; import { IUserRegistry } from '../interfaces/userRegistry.interface'; +import { UserRegistrySearchService } from './userRegistry-search.service'; @Injectable() export class UsersService { -- GitLab