Skip to content
Snippets Groups Projects
Commit 449eef94 authored by Antonin COQUET's avatar Antonin COQUET
Browse files

count filter depends on actual filters

parent f7102873
No related branches found
No related tags found
3 merge requests!96release V1.10.0,!62Dev,!58Feat/structure filter
......@@ -187,39 +187,28 @@ export class StructuresService {
* @param key structure key
* @return [{id: 'key', count: 'value'}]
*/
public async countByStructureKey(key: string, selected: { cat: string; key: string }[]): Promise<any> {
console.log('key is:', key);
public async countByStructureKey(key: string, selected: { id: string; text: string }[]): Promise<any> {
const uniqueElements = await this.structureModel.distinct(key).exec();
console.log('unique elements:', uniqueElements);
return await Promise.all(
uniqueElements.map(async (value) => {
console.log(value);
let keyList: FilterQuery<DocumentDefinition<StructureDocument>>[] = [];
keyList.push({
[key]: { $elemMatch: { $eq: value } },
deletedAt: { $exists: false },
});
for (let val of selected) {
keyList.push({
//[val.key]: { $match: { $eq: val.cat } },
$match: { $eq: val.cat },
deletedAt: { $exists: false },
});
if (selected && selected.length > 0) {
for (let val of selected) {
keyList.push({
[val.text]: { $elemMatch: { $eq: val.id } },
deletedAt: { $exists: false },
});
}
}
return {
id: value,
count: await this.structureModel
.countDocuments({
$and: keyList,
// $and: [
// {
// [key]: { $elemMatch: { $eq: value } },
// deletedAt: { $exists: false },
// },
// {
// // ['proceduresAccompaniment']: { $elemMatch: { $eq: 'accompagnantCaf' } },
// },
// ],
})
.exec(),
};
......
......@@ -74,11 +74,11 @@ export class StructuresController {
return this.userService.updateStructureLinkedClaim(user.email, idStructure);
}
@Get('count')
@Post('count')
public async countCategories(
selectedFilter: { cat: string; key: string }[]
@Body()
selectedFilter: { id: string; text: string }[]
): Promise<Array<{ id: string; count: number }>> {
//const testFilter = [{ cat: 'poleEmploi', key: 'proceduresAccompaniment' }];
const data = await Promise.all([
this.structureService.countByStructureKey('proceduresAccompaniment', selectedFilter),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment