@@ -177,6 +177,31 @@ ${new Array(nbRows)
177177 ` ,
178178 [ departementCodes , search , limit , offset ] ,
179179 ] ,
180+ getByDepartementCodes2 : ( ) => `
181+ SELECT
182+ H.ID AS "id",
183+ A.DEPARTEMENT AS "departement",
184+ H.EMAIL AS EMAIL,
185+ H.TELEPHONE_1 AS TELEPHONE,
186+ H.NOM_GESTIONNAIRE AS "nomGestionnaire",
187+ A.LABEL AS ADRESSE,
188+ H.NOM AS "nom",
189+ ( SELECT VALUE FROM FRONT.HEBERGEMENT_TYPE WHERE ID = H.ID) AS "typeHebergement",
190+ H.VISITE_LOCAUX_AT AS "dateVisite",
191+ H.REGLEMENTATION_ERP AS "reglementationErp"
192+ FROM
193+ FRONT.HEBERGEMENT H
194+ LEFT JOIN FRONT.ADRESSE A ON A.ID = H.ADRESSE_ID
195+ WHERE
196+ A.DEPARTEMENT = ANY($1)
197+ AND (
198+ unaccent(h.nom) ILIKE '%' || unaccent($2) || '%'
199+ OR h.email ILIKE '%' || $2 || '%'
200+ OR unaccent(a.label) ILIKE '%' || unaccent($2) || '%'
201+ )
202+ AND CURRENT IS TRUE
203+ AND h.statut_id = (SELECT id FROM front.hebergement_statut WHERE value = 'actif');
204+ ` ,
180205 getById : `
181206 SELECT
182207 id,
@@ -311,12 +336,12 @@ ${new Array(nbRows)
311336 id = $1
312337 ` ,
313338 updateStatut : `
314- UPDATE
315- front.hebergement
339+ UPDATE
340+ front.hebergement
316341 SET statut_id = (SELECT id FROM front.hebergement_statut WHERE value = $3),
317342 edited_by = $2,
318343 edited_at = NOW()
319- WHERE id = $1
344+ WHERE id = $1
320345 AND current = TRUE
321346 ` ,
322347} ;
@@ -547,7 +572,6 @@ module.exports.updateStatut = async (userId, hebergementId, statut) => {
547572 return hebergementId ;
548573} ;
549574
550-
551575module . exports . getByDepartementCodes = async ( departementsCodes , params ) => {
552576 log . i ( "getByDepartementCodes - IN" ) ;
553577 const { rows } = await pool . query (
@@ -556,6 +580,79 @@ module.exports.getByDepartementCodes = async (departementsCodes, params) => {
556580 log . d ( "getByDepartementCodes - DONE" ) ;
557581 return rows [ 0 ] ;
558582} ;
583+ module . exports . getByDepartementCodes2 = async (
584+ departementsCodes ,
585+ queryParams ,
586+ ) => {
587+ const titles = [
588+ {
589+ key : "h.nom" ,
590+ queryKey : "nom" ,
591+ sortEnabled : true ,
592+ type : "default" ,
593+ } ,
594+ {
595+ key : "a.departement" ,
596+ queryKey : "departement" ,
597+ sortEnabled : true ,
598+ type : "default" ,
599+ } ,
600+ {
601+ key : "a.label" ,
602+ queryKey : "adresse" ,
603+ sortEnabled : true ,
604+ type : "default" ,
605+ } ,
606+ {
607+ key : " h.telephone_1" ,
608+ queryKey : "telephone" ,
609+ sortEnabled : true ,
610+ type : "default" ,
611+ } ,
612+ {
613+ key : " h.email" ,
614+ queryKey : "email" ,
615+ sortEnabled : true ,
616+ type : "default" ,
617+ } ,
618+ {
619+ key : "h.visite_locaux_at" ,
620+ queryKey : "dateVisite" ,
621+ sortEnabled : true ,
622+ type : "date" ,
623+ } ,
624+ {
625+ key : "h.reglementation_erp" ,
626+ queryKey : "reglementationErp" ,
627+ sortEnabled : true ,
628+ type : "default" ,
629+ } ,
630+ ] ;
631+ const filterParams = sanitizeFiltersParams ( queryParams , titles ) ;
632+ const queryGet = query . getByDepartementCodes2 ( ) ;
633+ const params = [ ...departementsCodes ] ;
634+ const filterQuery = applyFilters ( queryGet , params , filterParams ) ;
635+ const { limit, offset, sortBy, sortDirection } = sanitizePaginationParams (
636+ queryParams ,
637+ titles ,
638+ ) ;
639+ const paginatedQuery = applyPagination (
640+ filterQuery . query ,
641+ filterQuery . params ,
642+ limit ,
643+ offset ,
644+ sortBy ,
645+ sortDirection ,
646+ ) ;
647+ const result = await Promise . all ( [
648+ pool . query ( paginatedQuery . query , paginatedQuery . params ) ,
649+ pool . query ( paginatedQuery . countQuery , paginatedQuery . countQueryParams ) ,
650+ ] ) ;
651+ return {
652+ rows : result [ 0 ] . rows ,
653+ total : parseInt ( result [ 1 ] . rows [ 0 ] . total , 10 ) ,
654+ } ;
655+ } ;
559656
560657module . exports . getByUserId = async ( userId , queryParams ) => {
561658 log . i ( "getByUserId - IN" , { userId } ) ;
0 commit comments