diff --git a/server/src/dao/formations.dao.ts b/server/src/dao/formations.dao.ts index f3f9edf0..f411ba54 100644 --- a/server/src/dao/formations.dao.ts +++ b/server/src/dao/formations.dao.ts @@ -228,20 +228,15 @@ export const findFormationByIntituleCfdIdCertifInfoOrSlug = async ( ]) .where("formations.deleted_at", "is", null); - if (intitule) { - baseQuery = baseQuery.where(sql`catalogue_data->>'onisep_intitule'`, "ilike", `%${intitule}%`); - } - - if (cfd) { - baseQuery = baseQuery.where(sql`catalogue_data ->> 'cfd'`, "=", cfd); - } - - if (idCertifInfo) { - baseQuery = baseQuery.where(sql`catalogue_data ->> 'id_certifinfo'`, "=", idCertifInfo); - } - - if (slug) { - baseQuery = baseQuery.where("onisep_slug", "=", slug); + const conditions = [ + intitule ? sql`catalogue_data->>'onisep_intitule' ilike ${`%${intitule}%`}` : null, + cfd ? sql`catalogue_data ->> 'cfd' = ${cfd}` : null, + idCertifInfo ? sql`catalogue_data ->> 'id_certifinfo' = ${idCertifInfo}` : null, + slug ? sql`onisep_slug = ${slug}` : null, + ].filter(Boolean); + + if (conditions.length > 0) { + baseQuery = baseQuery.where((qb) => qb.or(conditions as any)); } return baseQuery.execute();