Skip to content

Commit

Permalink
Merge pull request #1077 from MTES-MCT/issue/2289
Browse files Browse the repository at this point in the history
#patch (2289) Ajouter la liste des opérateurs par action financée
  • Loading branch information
superfeedboy authored Jan 9, 2025
2 parents 6248476 + c9999b2 commit 6723a0f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 66 deletions.
18 changes: 18 additions & 0 deletions packages/api/server/models/actionModel/fetchReport/fetchReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ export default (requestedYear: number): Promise<ActionReportRow[]> => sequelize.
topics ON topics.uid = action_topics.fk_topic
GROUP BY
fk_action
),
action_operators AS (
SELECT
fk_action,
array_agg(users.first_name || ' ' ||
users.last_name|| ' [' ||
organizations."name" || ']') AS operators
FROM
action_operators
LEFT JOIN
users ON users.user_id = action_operators.fk_user
LEFT JOIN
organizations ON organizations.organization_id = users.fk_organization
GROUP BY
fk_action
)
SELECT
d.code AS "departement_code",
Expand All @@ -161,6 +176,7 @@ export default (requestedYear: number): Promise<ActionReportRow[]> => sequelize.
ELSE 'Non communiqué'
END AS "location_type",
topics,
operators,
actions.goals,
m.nombre_personnes,
m.nombre_menages,
Expand Down Expand Up @@ -204,6 +220,8 @@ export default (requestedYear: number): Promise<ActionReportRow[]> => sequelize.
regions r ON r.code = d.fk_region
LEFT JOIN
actiontopics at ON at.fk_action = actions.action_id
LEFT JOIN
action_operators ao ON ao.fk_action = actions.action_id
LEFT JOIN
metrics m ON m.action_id = actions.action_id
LEFT JOIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import ExcelJS from 'exceljs';
import departementsOrdonnes from '#server/utils/departementsOrdonnes';
import columnToNumber from '#server/utils/excelUtils';
import { DepartementObject, ActionItem } from './exportActions.d';
import { ActionReportRow } from '#root/types/resources/Action.d';
import { ActionReportRow, ActionItem } from '#root/types/resources/Action.d';

type DepartementObject = {
departement: string,
data: []
};

/**
* Regroupe et trie les données par département
Expand Down Expand Up @@ -36,14 +39,15 @@ function regrouperEtTrierParDepartement(data: ActionReportRow[]): DepartementObj

const sectionTitles = [
{ name: 'ACTION', range: { from: 'A1', to: 'J1' } },
{ name: 'INDICATEURS GÉNÉRAUX', range: { from: 'K1', to: 'N1' } },
{ name: 'SANTÉ', range: { from: 'O1', to: 'O1' } },
{ name: 'EMPLOI', range: { from: 'P1', to: 'Q1' } },
{ name: 'HÉBERGEMENT/LOGEMENT', range: { from: 'R1', to: 'U1' } },
{ name: 'SCOLARISATION', range: { from: 'V1', to: 'AB1' } },
{ name: 'FINANCEMENT', range: { from: 'AC1', to: 'AN1' } },
{ name: 'COMMENTAIRES', range: { from: 'AO1', to: 'AQ1' } },
{ name: 'MISE À JOUR', range: { from: 'AR1', to: 'AR1' } },
{ name: 'OPÉRATEURS', range: { from: 'K1', to: 'K1' } },
{ name: 'INDICATEURS GÉNÉRAUX', range: { from: 'L1', to: 'O1' } },
{ name: 'SANTÉ', range: { from: 'P1', to: 'P1' } },
{ name: 'EMPLOI', range: { from: 'Q1', to: 'R1' } },
{ name: 'HÉBERGEMENT/LOGEMENT', range: { from: 'S1', to: 'V1' } },
{ name: 'SCOLARISATION', range: { from: 'W1', to: 'AC1' } },
{ name: 'FINANCEMENT', range: { from: 'AD1', to: 'AO1' } },
{ name: 'COMMENTAIRES', range: { from: 'AP1', to: 'AR1' } },
{ name: 'MISE À JOUR', range: { from: 'AS1', to: 'AS1' } },
];

const headers = [
Expand All @@ -57,6 +61,7 @@ const headers = [
{ label: 'Lieu', width: '4' },
{ label: 'Champs d\'intervention', width: '7' },
{ label: 'Objectifs de l\'action', width: '10' },
{ label: 'Opérateurs', width: '7' },
{ label: 'Nombre total de personnes concernées par l\'action', width: '5' },
{ label: 'Nombre de ménages', width: '5' },
{ label: 'Nombre de femmes', width: '5' },
Expand Down Expand Up @@ -161,6 +166,7 @@ export default (data: ActionReportRow[]) => {

// Ajouter les lignes de données
donneeParDepartement.data.forEach((item: ActionItem) => {
// Traiter les opérateurs (nom, prénom, organisation)
worksheet.addRow([
item.departement_name,
item.region_code,
Expand All @@ -172,6 +178,7 @@ export default (data: ActionReportRow[]) => {
item.location_type,
item.topics.join(', '),
item.goals,
item.operators.join('\n'),
item.nombre_personnes,
item.nombre_menages,
item.nombre_femmes,
Expand Down
51 changes: 0 additions & 51 deletions packages/api/server/services/action/exportActions.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ExcelJS from 'exceljs';
import { AuthUser } from '#server/middlewares/authMiddleware';
import creerClasseurExcel from './exportActions.creerClasseurExcel';

import { ActionReportRow } from '#root/types/resources/Action.d';


export default async (user: AuthUser, data: ActionReportRow[]): Promise<ExcelJS.Buffer> => creerClasseurExcel(data);
export default async (data: ActionReportRow[]): Promise<ExcelJS.Buffer> => creerClasseurExcel(data);
2 changes: 1 addition & 1 deletion packages/api/server/services/action/exportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export default async (user: AuthUser, year: string) => {
throw new ServiceError('fetch_failed', new Error('Il n\'y a aucune action à exporter'));
}

const buffer = await generateExportFile(user, data);
const buffer = await generateExportFile(data);
return buffer;
};
8 changes: 6 additions & 2 deletions packages/api/types/resources/Action.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import ActionLocationType from './ActionLocationType.d';
import { ActionRawComment } from './ActionCommentRaw.d';
import { ActionEnrichedComment } from './ActionCommentEnriched.d';

export type ActionReportRow = {
departement_code: string,
export type ActionItem = {
departement_name: string,
region_code: string,
region_name: string,
Expand All @@ -15,6 +14,7 @@ export type ActionReportRow = {
ended_at: string | null,
location_type: string,
topics: string[],
operators: string[],
goals: string,
nombre_personnes: number | null,
nombre_menages: number | null,
Expand Down Expand Up @@ -52,6 +52,10 @@ export type ActionReportRow = {
last_update: string | null,
};

export type ActionReportRow = {
departement_code: string,
} & ActionItem;


type ActionUser = {
id: number,
Expand Down

0 comments on commit 6723a0f

Please sign in to comment.