Skip to content

Commit

Permalink
Feat/us etat qualification pacea (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlbrjc committed Jan 27, 2025
1 parent e14c617 commit 18af3d4
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 454 deletions.
2 changes: 0 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ import { GetEvenementsEmploiQueryHandler } from './application/queries/get-evene
import { GetFavorisOffresEmploiJeuneQueryHandler } from './application/queries/get-favoris-offres-emploi-jeune.query.handler.db'
import { GetFavorisOffresImmersionJeuneQueryHandler } from './application/queries/get-favoris-offres-immersion-jeune.query.handler.db'
import { GetFavorisServiceCiviqueJeuneQueryHandler } from './application/queries/get-favoris-service-civique-jeune.query.handler.db'
import { GetHomeJeuneHandler } from './application/queries/get-home-jeune.query.handler'
import { GetIndicateursPourConseillerQueryHandler } from './application/queries/get-indicateurs-pour-conseiller.query.handler.db'
import { GetJeuneHomeActionsQueryHandler } from './application/queries/get-jeune-home-actions.query.handler'
import { GetJeuneHomeAgendaQueryHandler } from './application/queries/get-jeune-home-agenda.query.handler.db'
Expand Down Expand Up @@ -655,7 +654,6 @@ export function buildQueryCommandsProviders(): Provider[] {
DeleteFavoriOffreImmersionCommandHandler,
GetFavorisOffresEmploiJeuneQueryHandler,
GetFavorisOffresImmersionJeuneQueryHandler,
GetHomeJeuneHandler,
GetOffresEmploiQueryHandler,
GetOffresImmersionQueryHandler,
GetDetailOffreImmersionQueryHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueryHandler } from '../../../building-blocks/types/query-handler'
import { failure, Result, success } from '../../../building-blocks/types/result'
import { Action } from '../../../domain/action/action'
import { Authentification } from '../../../domain/authentification'
import { fromSqlToActionQueryModel } from '../../../infrastructure/repositories/mappers/actions.mappers'
import { fromSqlToActionQueryModelWithJeune } from '../../../infrastructure/repositories/mappers/actions.mappers'
import { ActionSqlModel } from '../../../infrastructure/sequelize/models/action.sql-model'
import { JeuneSqlModel } from '../../../infrastructure/sequelize/models/jeune.sql-model'
import { SequelizeInjectionToken } from '../../../infrastructure/sequelize/providers'
Expand All @@ -31,13 +31,6 @@ export interface ActionsJeuneQueryModel {
metadonnees: {
nombreTotal: number
nombreFiltrees: number
nombrePasCommencees: number
nombreEnCours: number
nombreTerminees: number
nombreAnnulees: number
nombreNonQualifiables: number
nombreAQualifier: number
nombreQualifiees: number
nombreActionsParPage: number
}
}
Expand All @@ -47,12 +40,6 @@ export class GetActionsJeuneQueryHandler extends QueryHandler<
GetActionsJeuneQuery,
Result<ActionsJeuneQueryModel>
> {
private readonly CASE_ETATS_QUALIFICATION = `CASE
WHEN qualification_heures IS NOT null THEN 'QUALIFIEE'
WHEN statut = 'done' THEN 'A_QUALIFIER'
ELSE 'NON_QUALIFIABLE'
END`

constructor(
@Inject(SequelizeInjectionToken) private readonly sequelize: Sequelize,
private jeuneAuthorizer: JeuneAuthorizer,
Expand All @@ -64,12 +51,10 @@ export class GetActionsJeuneQueryHandler extends QueryHandler<
async handle(
query: GetActionsJeuneQuery
): Promise<Result<ActionsJeuneQueryModel>> {
const [actionsFiltrees, statutRawCount, etatQualificationRawCount] =
await Promise.all([
this.findAndCountAllActionsFiltrees(query),
this.compterActionsParStatut(query.idJeune),
this.compterActionsParEtatQualification(query.idJeune)
])
const [actionsFiltrees, statutRawCount] = await Promise.all([
this.findAndCountAllActionsFiltrees(query),
this.compterActionsParStatut(query.idJeune)
])

if (!laPageExiste(actionsFiltrees.count, query.page)) {
return failure(new NonTrouveError('Page', query.page?.toString()))
Expand All @@ -78,25 +63,6 @@ export class GetActionsJeuneQueryHandler extends QueryHandler<
const metadonnees = {
nombreTotal: this.compterToutesLesActions(statutRawCount),
nombreFiltrees: actionsFiltrees.count,
nombrePasCommencees: this.getCompte(
statutRawCount,
Action.Statut.PAS_COMMENCEE
),
nombreEnCours: this.getCompte(statutRawCount, Action.Statut.EN_COURS),
nombreTerminees: this.getCompte(statutRawCount, Action.Statut.TERMINEE),
nombreAnnulees: this.getCompte(statutRawCount, Action.Statut.ANNULEE),
nombreNonQualifiables: this.getCompte(
etatQualificationRawCount,
Action.Qualification.Etat.NON_QUALIFIABLE
),
nombreAQualifier: this.getCompte(
etatQualificationRawCount,
Action.Qualification.Etat.A_QUALIFIER
),
nombreQualifiees: this.getCompte(
etatQualificationRawCount,
Action.Qualification.Etat.QUALIFIEE
),
nombreActionsParPage: LIMITE_NOMBRE_ACTIONS_PAR_PAGE
}

Expand All @@ -106,7 +72,7 @@ export class GetActionsJeuneQueryHandler extends QueryHandler<

return success({
metadonnees,
actions: actionsFiltrees.rows.map(fromSqlToActionQueryModel)
actions: actionsFiltrees.rows.map(fromSqlToActionQueryModelWithJeune)
})
}

Expand Down Expand Up @@ -166,42 +132,25 @@ export class GetActionsJeuneQueryHandler extends QueryHandler<
)
}

private compterActionsParEtatQualification(
idJeune: string
): Promise<Array<RawCount<Action.Qualification.Etat>>> {
return this.sequelize.query<RawCount<Action.Qualification.Etat>>(
`
SELECT ${this.CASE_ETATS_QUALIFICATION} AS value, COUNT(*)
FROM action
WHERE id_jeune = :idJeune
GROUP BY value;
`,
{
type: QueryTypes.SELECT,
replacements: {
idJeune
}
}
)
}

private compterToutesLesActions<T>(rawCount: Array<RawCount<T>>): number {
return rawCount.reduce((total, { count }) => total + parseInt(count), 0)
}

private getCompte<T>(rawCount: Array<RawCount<T>>, valueACompter: T): number {
const count = rawCount.find(({ value }) => value === valueACompter)?.count
return count ? parseInt(count) : 0
}

private generateWhere(query: GetActionsJeuneQuery): WhereOptions {
const where: WhereOptions = [{ id_jeune: query.idJeune }]

if (query.etats?.length) {
where.push(
Sequelize.where(this.sequelize.literal(this.CASE_ETATS_QUALIFICATION), {
[Op.in]: query.etats
})
Sequelize.where(
this.sequelize.literal(`CASE
WHEN qualification_heures IS NOT null THEN 'QUALIFIEE'
WHEN statut = 'done' AND dispositif = 'CEJ' THEN 'A_QUALIFIER'
ELSE 'NON_QUALIFIABLE'
END`),
{
[Op.in]: query.etats
}
)
)
}
if (query.statuts) where.push({ statut: query.statuts })
Expand Down
39 changes: 0 additions & 39 deletions src/application/queries/get-home-jeune.query.handler.ts

This file was deleted.

19 changes: 15 additions & 4 deletions src/application/queries/get-jeune-home-agenda.query.handler.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'src/config/feature-flipping'
import { Action } from 'src/domain/action/action'
import { Authentification } from 'src/domain/authentification'
import { fromSqlToActionQueryModel } from 'src/infrastructure/repositories/mappers/actions.mappers'
import { fromSqlToActionQueryModelWithJeune } from 'src/infrastructure/repositories/mappers/actions.mappers'
import { ActionSqlModel } from 'src/infrastructure/sequelize/models/action.sql-model'
import { ConseillerSqlModel } from 'src/infrastructure/sequelize/models/conseiller.sql-model'
import { JeuneSqlModel } from 'src/infrastructure/sequelize/models/jeune.sql-model'
Expand Down Expand Up @@ -75,7 +75,12 @@ export class GetJeuneHomeAgendaQueryHandler extends QueryHandler<
const { lundiDernier, dimancheEnHuit } =
this.recupererLesDatesEntreLundiDernierEtDeuxSemainesPlusTard(maintenant)
const [actions, rendezVous, actionsEnRetard] = await Promise.all([
this.recupererLesActions(query, lundiDernier, dimancheEnHuit),
this.recupererLesActions(
query,
lundiDernier,
dimancheEnHuit,
jeuneSqlModel
),
this.recupererLesRendezVous(
query,
lundiDernier,
Expand Down Expand Up @@ -213,7 +218,8 @@ export class GetJeuneHomeAgendaQueryHandler extends QueryHandler<
private async recupererLesActions(
query: GetJeuneHomeAgendaQuery,
dateDebut: DateTime,
dateFin: DateTime
dateFin: DateTime,
jeuneSqlModel: JeuneSqlModel
): Promise<ActionQueryModel[]> {
const actionsSqlModel = await ActionSqlModel.findAll({
where: {
Expand All @@ -226,7 +232,12 @@ export class GetJeuneHomeAgendaQueryHandler extends QueryHandler<
order: [['dateEcheance', 'ASC']]
})

return actionsSqlModel.map(fromSqlToActionQueryModel)
return actionsSqlModel.map(actionSqlModel =>
fromSqlToActionQueryModelWithJeune({
...actionSqlModel.dataValues,
jeune: jeuneSqlModel
} as ActionSqlModel)
)
}

private async recupererLeNombreDactionsEnRetard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DateTime } from 'luxon'
import { ActionQueryModel } from '../query-models/actions.query-model'
import { ActionSqlModel } from '../../../infrastructure/sequelize/models/action.sql-model'
import { Op } from 'sequelize'
import { fromSqlToActionQueryModel } from '../../../infrastructure/repositories/mappers/actions.mappers'
import { fromSqlToActionQueryModelWithJeune } from '../../../infrastructure/repositories/mappers/actions.mappers'
import { RendezVousJeuneQueryModel } from '../query-models/rendez-vous.query-model'
import { RendezVousSqlModel } from '../../../infrastructure/sequelize/models/rendez-vous.sql-model'
import { fromSqlToRendezVousJeuneQueryModel } from '../query-mappers/rendez-vous-milo.mappers'
Expand Down Expand Up @@ -72,7 +72,7 @@ export class GetMonSuiviMiloQueryHandler extends QueryHandler<
}

const [actions, rendezVous, sessionsMilo] = await Promise.all([
this.recupererLesActions(query),
this.recupererLesActions(query, jeuneSqlModel),
this.recupererLesRendezVous(query, utilisateur.type),
this.sessionsJeuneQueryGetter
.handle(query.idJeune, jeuneSqlModel.idPartenaire, query.accessToken, {
Expand Down Expand Up @@ -108,7 +108,8 @@ export class GetMonSuiviMiloQueryHandler extends QueryHandler<
}

private async recupererLesActions(
query: GetMonSuiviMiloQuery
query: GetMonSuiviMiloQuery,
jeuneSqlModel: JeuneSqlModel
): Promise<ActionQueryModel[]> {
const actionsSqlModel = await ActionSqlModel.findAll({
where: {
Expand All @@ -121,7 +122,12 @@ export class GetMonSuiviMiloQueryHandler extends QueryHandler<
order: [['dateEcheance', 'ASC']]
})

return actionsSqlModel.map(fromSqlToActionQueryModel)
return actionsSqlModel.map(actionSqlModel =>
fromSqlToActionQueryModelWithJeune({
...actionSqlModel.dataValues,
jeune: jeuneSqlModel
} as ActionSqlModel)
)
}

private async recupererLesRendezVous(
Expand Down
38 changes: 28 additions & 10 deletions src/application/queries/query-models/actions.query-model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { Action } from '../../../domain/action/action'
import { Demarche } from '../../../domain/demarche'
import { JeuneQueryModel } from './jeunes.query-model'

class CreateurQueryModel implements Action.Createur {
@ApiProperty()
Expand Down Expand Up @@ -31,6 +30,23 @@ export class QualificationActionQueryModel {
commentaireQualification?: string
}

export class BeneficiaireActionQueryModel {
@ApiProperty()
id: string

@ApiProperty()
lastName: string

@ApiProperty()
firstName: string

@ApiProperty()
idConseiller: string

@ApiProperty()
dispositif: string
}

export class ActionQueryModel {
@ApiProperty()
id: string
Expand All @@ -56,11 +72,8 @@ export class ActionQueryModel {
@ApiProperty()
creator: string

@ApiProperty({
type: JeuneQueryModel,
required: false
})
jeune?: JeuneQueryModel
@ApiProperty({ type: BeneficiaireActionQueryModel })
jeune: BeneficiaireActionQueryModel

@ApiProperty()
dateEcheance: string
Expand Down Expand Up @@ -90,16 +103,21 @@ export class CommentaireActionQueryModel {
}

export class ActionsMetadonneesQueryModel {
@ApiProperty()
nombreTotal: number
nombreEnCours: number
nombreTerminees: number
nombreAnnulees: number
nombrePasCommencees: number

@ApiProperty()
nombreFiltrees: number

@ApiProperty()
nombreActionsParPage: number
}

export class ListeActionsV2QueryModel {
@ApiProperty({ type: ActionQueryModel, isArray: true })
actions: ActionQueryModel[]

@ApiProperty({ type: ActionsMetadonneesQueryModel, isArray: true })
metadonnees: ActionsMetadonneesQueryModel
}

Expand Down
Loading

0 comments on commit 18af3d4

Please sign in to comment.