Skip to content

Commit

Permalink
Merge pull request #383 from mission-apprentissage/server/add-or-cond…
Browse files Browse the repository at this point in the history
…ition-in-iframe

[Server] Remplace la condition AND par OR dans la recherche de formation pour l'iframe
  • Loading branch information
yohanngab authored Dec 16, 2024
2 parents d659451 + c69a217 commit cca3172
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions server/src/dao/formations.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,15 @@ export const findFormationByIntituleCfdIdCertifInfoOrSlug = async (
])
.where("formations.deleted_at", "is", null);

if (intitule) {
baseQuery = baseQuery.where(sql<string>`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<string>`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();
Expand Down

0 comments on commit cca3172

Please sign in to comment.