Skip to content

Commit

Permalink
Fix cmpl_type visible condition (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
obieler authored Nov 3, 2023
1 parent 25b8ae3 commit 7f7f737
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/services/unit.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ const ldapUtil = require('../utils/ldap.util');
const cadidbService = require('./cadidb.service');
const peopleService = require('./people.service');

const visibleConditionByCmplType = `
(
cmpl_type IS NULL OR cmpl_type = '' OR
(cmpl_type NOT LIKE ('%Z%') AND cmpl_type IN ('FS', 'F', 'E', 'X', 'S'))
)
`;

async function get (params) {
const lang = params.hl || 'fr';
const q = params.q;
Expand All @@ -23,12 +30,11 @@ async function get (params) {

async function searchUnits (q, lang) {
const query = 'SELECT sigle, libelle, libelle_en, hierarchie ' +
'FROM Unites_v2 WHERE cmpl_type <> ? AND ' +
'(sigle LIKE ? OR libelle LIKE ? OR libelle_en LIKE ?) AND ' +
'hierarchie NOT LIKE ?';
const values = [
'Z', '%' + q + '%', '%' + q + '%', '%' + q + '%', 'TECHNIQUE%'
];
'FROM Unites_v2 ' +
'WHERE (sigle LIKE ? OR libelle LIKE ? OR libelle_en LIKE ?) ' +
`AND ${visibleConditionByCmplType}` +
'AND hierarchie NOT LIKE ?';
const values = ['%' + q + '%', '%' + q + '%', '%' + q + '%', 'TECHNIQUE%'];

const results = await cadidbService.sendQuery(query, values, 'searchUnits');
const formattedResults = results.map((dict) => {
Expand Down Expand Up @@ -70,9 +76,10 @@ async function getUnit (acro, lang) {
'resp_prenom_usuel, url, faxes, adresse, cmpl_type, ghost, ' +
'has_accreds ' +
'FROM Unites_v2 ' +
'WHERE sigle = ? AND cmpl_type <> ? AND ' +
'hierarchie NOT LIKE ?';
const values = [acro, 'Z', 'TECHNIQUE%'];
'WHERE sigle = ? ' +
`AND ${visibleConditionByCmplType} ` +
'AND hierarchie NOT LIKE ?';
const values = [acro, 'TECHNIQUE%'];

const results = await cadidbService.sendQuery(query, values, 'getUnit');
if (results.length !== 1) {
Expand Down Expand Up @@ -163,9 +170,9 @@ async function getUnitPath (hierarchy, lang) {
async function getSubunits (unitId, lang) {
const query = 'SELECT sigle, libelle, libelle_en ' +
'FROM Unites_v2 ' +
'WHERE id_parent = ? AND ' +
'(ghost = 1 OR ISNULL(cmpl_type) OR cmpl_type <> ?)';
const values = [unitId, 'Z'];
'WHERE id_parent = ? ' +
`AND ${visibleConditionByCmplType}`;
const values = [unitId];

const results = await cadidbService.sendQuery(query, values, 'getSubunits');
const formattedResults = results.map((dict) => {
Expand Down

0 comments on commit 7f7f737

Please sign in to comment.