Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Show changes
Commits on Source (2)
...@@ -16,7 +16,6 @@ describe('UserRegistryController', () => { ...@@ -16,7 +16,6 @@ describe('UserRegistryController', () => {
const userRegistryServiceMock = { const userRegistryServiceMock = {
findAllForIndexation: jest.fn(), findAllForIndexation: jest.fn(),
countAllUserRegistry: jest.fn(), countAllUserRegistry: jest.fn(),
findAllUserRegistry: jest.fn(),
findUsersByNameEmployerOrJobsGroup: jest.fn(), findUsersByNameEmployerOrJobsGroup: jest.fn(),
initUserRegistryIndex: jest.fn(), initUserRegistryIndex: jest.fn(),
populateES: jest.fn(), populateES: jest.fn(),
...@@ -103,12 +102,12 @@ describe('UserRegistryController', () => { ...@@ -103,12 +102,12 @@ describe('UserRegistryController', () => {
expect(reply).toStrictEqual([multipleUsers[0]]); expect(reply).toStrictEqual([multipleUsers[0]]);
}); });
it('should findAll with no searchTerm and no filter arrays', async () => { it('should findAll with no searchTerm and no filter arrays', async () => {
userRegistryServiceMock.findAllUserRegistry.mockResolvedValue(multipleUsers); userRegistryServiceMock.findUsersByNameEmployerOrJobsGroup.mockResolvedValue(multipleUsers);
const reply = await userRegistryController.findAll({ search: '' }, { page: 1 }); const reply = await userRegistryController.findAll({ search: '' }, { page: 1 });
expect(reply).toBe(multipleUsers); expect(reply).toBe(multipleUsers);
}); });
it('should findAll with empty search end undefined filters', async () => { it('should findAll with empty search end undefined filters', async () => {
userRegistryServiceMock.findAllUserRegistry.mockResolvedValue(multipleUsers); userRegistryServiceMock.findUsersByNameEmployerOrJobsGroup.mockResolvedValue(multipleUsers);
const reply = await userRegistryController.findAll({ search: '' }); const reply = await userRegistryController.findAll({ search: '' });
expect(reply).toBe(multipleUsers); expect(reply).toBe(multipleUsers);
}); });
......
...@@ -25,17 +25,13 @@ export class UsersRegistryController { ...@@ -25,17 +25,13 @@ export class UsersRegistryController {
@Query() query?: { search: string }, @Query() query?: { search: string },
@Body() filters?: { jobsGroup?: string[]; employer?: string[]; page: number } @Body() filters?: { jobsGroup?: string[]; employer?: string[]; page: number }
): Promise<UserRegistryPaginatedResponse> { ): Promise<UserRegistryPaginatedResponse> {
if (query.search || filters?.jobsGroup?.length || filters?.employer?.length) { this.logger.debug(`findAll with query '${query.search}' and ${JSON.stringify(filters)}`);
this.logger.debug(`findAll with query ${query.search}`); return this.userRegistryService.findUsersByNameEmployerOrJobsGroup(
return this.userRegistryService.findUsersByNameEmployerOrJobsGroup( query.search || '',
query.search || '', filters?.page || 1,
filters?.page || 1, filters?.jobsGroup || [],
filters?.jobsGroup || [], filters?.employer || []
filters?.employer || [] );
);
}
this.logger.debug('findAll without query');
return this.userRegistryService.findAllUserRegistry(filters?.page || 1);
} }
/** /**
......
...@@ -95,11 +95,11 @@ describe('userRegistryService', () => { ...@@ -95,11 +95,11 @@ describe('userRegistryService', () => {
mockUserRegistryModel.exec.mockResolvedValueOnce(result.length); mockUserRegistryModel.exec.mockResolvedValueOnce(result.length);
expect(await userRegistryService.countAllUserRegistry()).toBe(result.length); expect(await userRegistryService.countAllUserRegistry()).toBe(result.length);
}); });
it('should findAllUserRegistry with page number 1', async () => { it('should findAll UserRegistry with page number 1', async () => {
const res = { count: 1, docs: result }; const res = { count: 1, docs: result };
mockUserRegistryModel.exec.mockResolvedValueOnce(1);
mockUserRegistryModel.exec.mockResolvedValueOnce(result); mockUserRegistryModel.exec.mockResolvedValueOnce(result);
expect(await userRegistryService.findAllUserRegistry(1)).toStrictEqual(res); mockUserRegistrySearchService.search.mockResolvedValueOnce(result);
expect(await userRegistryService.findUsersByNameEmployerOrJobsGroup('', 1)).toStrictEqual(res);
}); });
}); });
describe('find with filter', () => { describe('find with filter', () => {
......
...@@ -49,23 +49,6 @@ export class UserRegistryService { ...@@ -49,23 +49,6 @@ export class UserRegistryService {
.exec(); .exec();
} }
public async findAllUserRegistry(page: number): Promise<UserRegistryPaginatedResponse> {
this.logger.debug('findAllUserRegistry');
const limit = this.maxPerPage * page;
const count = await this.countAllUserRegistry();
const docs = await this.userModel
.find({ email: { $ne: process.env.MAIL_CONTACT } })
.where('emailVerified')
.equals(true)
.populate('employer job')
.select('name surname employer job _id withAppointment')
.limit(limit)
.collation({ locale: 'fr' })
.sort({ surname: 1 })
.exec();
return { count: count, docs: docs };
}
private callbackFilter(users: IUser[], employersList: Employer[], jobsGroupsList: JobsGroupsDocument[]): IUser[] { private callbackFilter(users: IUser[], employersList: Employer[], jobsGroupsList: JobsGroupsDocument[]): IUser[] {
this.logger.debug('callbackFilter'); this.logger.debug('callbackFilter');
const jobsGroupsIds: string[] = jobsGroupsList.map((jobsGroup) => jobsGroup._id.toString()); const jobsGroupsIds: string[] = jobsGroupsList.map((jobsGroup) => jobsGroup._id.toString());
...@@ -91,7 +74,6 @@ export class UserRegistryService { ...@@ -91,7 +74,6 @@ export class UserRegistryService {
this.logger.debug('findUsersByNameEmployerOrJobsGroup'); this.logger.debug('findUsersByNameEmployerOrJobsGroup');
const results = await this.userRegistrySearchService.search(searchParam); const results = await this.userRegistrySearchService.search(searchParam);
const ids = results.map((result) => result.id); const ids = results.map((result) => result.id);
const limit = page * this.maxPerPage || this.maxPerPage;
const jobsGroupsList: JobsGroupsDocument[] = []; const jobsGroupsList: JobsGroupsDocument[] = [];
const employersList: Employer[] = []; const employersList: Employer[] = [];
if (jobsGroups) { if (jobsGroups) {
...@@ -119,7 +101,10 @@ export class UserRegistryService { ...@@ -119,7 +101,10 @@ export class UserRegistryService {
.then((res) => { .then((res) => {
return this.callbackFilter(res, employersList, jobsGroupsList); return this.callbackFilter(res, employersList, jobsGroupsList);
}); });
return { count: resultsWithFilter.length, docs: resultsWithFilter.splice(0, limit) }; return {
count: resultsWithFilter.length,
docs: resultsWithFilter.slice(this.maxPerPage * (page - 1), this.maxPerPage * page),
};
} }
public async initUserRegistryIndex() { public async initUserRegistryIndex() {
......