Skip to content

Commit

Permalink
fixes annuaires
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Sep 19, 2023
1 parent 154b4e4 commit f27e234
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/api/annuaire/annuaire.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,48 @@ import express from 'express';
import { db } from '../../services/mongo.service';

const annuaire = db.collection('annuaire');
const rt = db.collection('relationtypes');
const router = new express.Router();

const lightProjection = {
_id: 0,
id: 1,
person: "$relatedObject.displayName",
personGender: "$relatedObject.gender",
structureName: "$resource.displayName",
startDate: 1,
endDate: 1,
status: 1,
active: 1,
endDatePrevisional: 1,
mandateEmail: 1,
mandateTemporary: 1,
personalEmail: 1,
mandatePhonenumber: 1,
personId: "$relatedObject.id",
structureId: "$resource.id",
relationType: "$relationType.name",
relationType: {
$cond: {
if: { $eq: ["$relatedObject.gender", 'Homme'] },
then: "$relationType.maleName",
else: {
$cond: {
if: { $eq: ["$relatedObject.gender", 'Homme'] },
then: "$relationType.feminineName",
else: "$relationType.name"
}
}
}
},
}


router.get('/annuaire/aggregations', async (req, res) => {
const relationTypes = await annuaire.distinct('relationType.name');
const relationTypesDocs = await rt
.find({ for: "persons" })
.project({ _id: 0, name: 1, priority: { $ifNull: ['$priority', 99] } })
.toArray();
const relationTypes = relationTypesDocs.sort((a, b) => a.priority - b.priority).map(rt => rt.name);
const structures = await annuaire.distinct('resource.displayName');
const categories = await annuaire.distinct('resource.categories.usualNameFr');
const mandateTypeGroups = await annuaire.distinct('relationType.mandateTypeGroup');
Expand Down

0 comments on commit f27e234

Please sign in to comment.