Skip to content

Commit

Permalink
Nettoyer évènements phase dossier (#184)
Browse files Browse the repository at this point in the history
* Meilleure gestion des évènements phase dossier vis à vis des "faux traitements" retournées par l'API DS

* Afficher une phase "Accompagnement amont" à la création du dossier

* fix type

* Rajout sync complet
  • Loading branch information
DavidBruant authored Feb 27, 2025
1 parent 19516c7 commit 62513ad
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex) {

await knex.schema.alterTable('évènement_phase_dossier', function (table) {
table.string('DS_emailAgentTraitant')
table.text('DS_motivation')
});

};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex) {

await knex.schema.alterTable('évènement_phase_dossier', function (table) {
table.dropColumn('DS_emailAgentTraitant')
table.dropColumn('DS_motivation')
});

};
11 changes: 9 additions & 2 deletions scripts/front-end/components/Dossier/DossierInstruction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
dossier: dossier.id,
horodatage: new Date(),
phase: dossierParams.phase,
cause_personne: null
cause_personne: null, // sera rempli côté serveur avec le bon PersonneId
DS_emailAgentTraitant: null,
DS_motivation: null
}
]
}
Expand Down Expand Up @@ -79,7 +81,12 @@
<span title={formatDateAbsolue(horodatage)}>{formatDateRelative(horodatage)}</span>
</li>
{/each}
<li><strong>Dépôt dossier</strong> - <span title={formatDateAbsolue(dossier.date_dépôt)}>{formatDateRelative(dossier.date_dépôt)}</span>
<li>
<TagPhase phase="Accompagnement amont"></TagPhase>
-
<strong>Dépôt dossier</strong>
-
<span title={formatDateAbsolue(dossier.date_dépôt)}>{formatDateRelative(dossier.date_dépôt)}</span>
</ol>
</section>

Expand Down
36 changes: 32 additions & 4 deletions scripts/server/database/dossier.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,22 @@ export async function dumpDossierTraitements(idToTraitements, databaseConnection
const évènementsPhaseDossier = [];

for(const [dossierId, apiTraitements] of idToTraitements){
for(const {dateTraitement, state} of apiTraitements){
for(const {dateTraitement, state, emailAgentTraitant, motivation} of apiTraitements){
évènementsPhaseDossier.push({
phase: traitementPhaseToDossierPhase(state),
horodatage: new Date(dateTraitement),
dossier: dossierId,
cause_personne: null // signifie que c'est l'outil de sync DS qui est la cause
cause_personne: null, // signifie que c'est l'outil de sync DS qui est la cause
DS_emailAgentTraitant: emailAgentTraitant,
DS_motivation: motivation
})
}
};

return databaseConnection('évènement_phase_dossier')
.insert(évènementsPhaseDossier)
.onConflict(['dossier', 'phase', 'horodatage'])
.ignore()
.merge()
}

/**
Expand Down Expand Up @@ -562,6 +564,11 @@ export async function getDossiersRésumésByCap(cap, databaseConnection = direct
dossier.phase = évènementPhaseDossier.phase
dossier.date_début_phase = évènementPhaseDossier.horodatage
}
else{
// dépôt du dossier
dossier.phase = 'Accompagnement amont'
dossier.date_début_phase = dossier.date_dépôt
}
}

return dossiers
Expand Down Expand Up @@ -628,6 +635,13 @@ export async function getDerniersÉvènementsPhaseDossiers(cap_dossier, database
)
.where({"arête_cap_dossier__groupe_instructeurs.cap_dossier": cap_dossier})
.distinctOn('dossier')
.andWhere(function () {
// DS créé des mauvais "traitement" qui ne sont pas des changements de phase
// On peut les détecter avec 'DS_emailAgentTraitant IS NULL'
// Si un évènement_phase_dossier n'a ni de 'cause_personne' ni de 'DS_emailAgentTraitant',
// on ne veut pas le refléter côté interface
this.whereNotNull('cause_personne').orWhereNotNull('DS_emailAgentTraitant');
})
.orderBy([
{ column: 'dossier', order: 'asc' },
{ column: 'horodatage', order: 'desc' }
Expand All @@ -650,6 +664,13 @@ export async function getÉvènementsPhaseDossiers(cap_dossier, databaseConnecti
{'arête_cap_dossier__groupe_instructeurs.groupe_instructeurs': 'arête_groupe_instructeurs__dossier.groupe_instructeurs'}
)
.where({"arête_cap_dossier__groupe_instructeurs.cap_dossier": cap_dossier})
.andWhere(function () {
// DS créé des mauvais "traitement" qui ne sont pas des changements de phase
// On peut les détecter avec 'DS_emailAgentTraitant IS NULL'
// Si un évènement_phase_dossier n'a ni de 'cause_personne' ni de 'DS_emailAgentTraitant',
// on ne veut pas le refléter côté interface
this.whereNotNull('cause_personne').orWhereNotNull('DS_emailAgentTraitant');
})
}

/**
Expand All @@ -661,7 +682,14 @@ async function getÉvènementsPhaseDossier(idDossier, databaseConnection = direc

return databaseConnection('évènement_phase_dossier')
.select('*')
.where({'dossier': idDossier})
.where({'dossier': idDossier})
.andWhere(function () {
// DS créé des mauvais "traitement" qui ne sont pas des changements de phase
// On peut les détecter avec 'DS_emailAgentTraitant IS NULL'
// Si un évènement_phase_dossier n'a ni de 'cause_personne' ni de 'DS_emailAgentTraitant',
// on ne veut pas le refléter côté interface
this.whereNotNull('cause_personne').orWhereNotNull('DS_emailAgentTraitant');
})
.orderBy('horodatage', 'desc');

}
Expand Down
2 changes: 1 addition & 1 deletion scripts/server/synchro-complète-si nécessaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ remettre une date dans le passé
*/

const DATE_SYNCHRONISATION_COMPLÈTE = '2025-01-28'
const DATE_SYNCHRONISATION_COMPLÈTE = '2025-02-28'

export default async function(){
if((new Date()).getTime() < new Date(DATE_SYNCHRONISATION_COMPLÈTE).getTime()){
Expand Down
12 changes: 12 additions & 0 deletions scripts/types/database/public/ÉvènementPhaseDossier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default interface VNementPhaseDossier {
horodatage: Date;

cause_personne: PersonneId | null;

DS_emailAgentTraitant: string | null;

DS_motivation: string | null;
}

/** Represents the initializer for the table public.évènement_phase_dossier */
Expand All @@ -25,6 +29,10 @@ export interface VNementPhaseDossierInitializer {
horodatage: Date;

cause_personne?: PersonneId | null;

DS_emailAgentTraitant?: string | null;

DS_motivation?: string | null;
}

/** Represents the mutator for the table public.évènement_phase_dossier */
Expand All @@ -36,4 +44,8 @@ export interface VNementPhaseDossierMutator {
horodatage?: Date;

cause_personne?: PersonneId | null;

DS_emailAgentTraitant?: string | null;

DS_motivation?: string | null;
}

0 comments on commit 62513ad

Please sign in to comment.