From 466cef356a526bdf51e4c18a6272598177700d6a Mon Sep 17 00:00:00 2001 From: PaulEntourage Date: Fri, 17 Nov 2023 10:15:03 +0100 Subject: [PATCH] [EN-6259] feat: backoffice admin offres --- src/opportunities/dto/create-opportunity.pipe.ts | 2 +- src/opportunities/opportunities.controller.ts | 4 ++-- src/opportunities/opportunities.service.ts | 11 ++++++++++- src/utils/misc/getFiltersObjectsFromQueryParams.ts | 2 -- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/opportunities/dto/create-opportunity.pipe.ts b/src/opportunities/dto/create-opportunity.pipe.ts index a57dff2b..5a456aaf 100644 --- a/src/opportunities/dto/create-opportunity.pipe.ts +++ b/src/opportunities/dto/create-opportunity.pipe.ts @@ -24,7 +24,7 @@ export class CreateOpportunityPipe forbidNonWhitelisted: true, forbidUnknownValues: true, }); - + if (errors.length > 0) { throw new BadRequestException(); } diff --git a/src/opportunities/opportunities.controller.ts b/src/opportunities/opportunities.controller.ts index fe7d4cba..23d9fd32 100644 --- a/src/opportunities/opportunities.controller.ts +++ b/src/opportunities/opportunities.controller.ts @@ -357,6 +357,8 @@ export class OpportunitiesController { query: { type: OfferAdminTab; search: string; + offset: number; + limit: number; } & FilterParams ) { return this.opportunitiesService.findAll(query); @@ -422,9 +424,7 @@ export class OpportunitiesController { search: string; } & FilterParams ) { - console.log(query); const { type, search, businessLines, department, contracts } = query - console.log(type); return this.opportunitiesService.adminCountOfferByType(type, search,businessLines, department, contracts); } diff --git a/src/opportunities/opportunities.service.ts b/src/opportunities/opportunities.service.ts index c30dab0d..90daf359 100644 --- a/src/opportunities/opportunities.service.ts +++ b/src/opportunities/opportunities.service.ts @@ -161,6 +161,8 @@ export class OpportunitiesService { query: { type: OfferAdminTab; search: string; + offset: number; + limit: number; } & FilterParams ) { const { @@ -182,12 +184,16 @@ export class OpportunitiesService { delete filterOptions.isPublic; } + const limit = query.limit || LIMIT; + const opportunities = await this.opportunityModel.findAll({ ...options, where: { ...searchOptions, ...filterOptions, }, + offset: query.offset ? query.offset * limit : 0, + limit, }); const cleanedOpportunites = opportunities.map((opportunity) => { @@ -1080,7 +1086,6 @@ export class OpportunitiesService { const pendingOpportunitiesCount = await this.opportunityModel.count({ where: { - status: type ? type : '', ...searchOptions, ...filterOptions, department, @@ -1089,6 +1094,10 @@ export class OpportunitiesService { }, }); + // const cleanedOpportunites = pendingOpportunitiesCount.map((opportunity) => { + // return opportunity.toJSON(); + // }); + console.log({type, search, businessLines, department, contracts}); return {pending: pendingOpportunitiesCount} diff --git a/src/utils/misc/getFiltersObjectsFromQueryParams.ts b/src/utils/misc/getFiltersObjectsFromQueryParams.ts index fc3f9218..11cac38e 100644 --- a/src/utils/misc/getFiltersObjectsFromQueryParams.ts +++ b/src/utils/misc/getFiltersObjectsFromQueryParams.ts @@ -19,10 +19,8 @@ export function getFiltersObjectsFromQueryParams( let filters = {} as FilterObject; - if (filtersConst) { _.forEach(Object.keys(params), (paramKey) => { - console.log(paramKey); const filter = findConstant(filtersConst, paramKey as K); if (filter) { const valueArray = params[paramKey as K];