Skip to content

Commit

Permalink
feat: etat qualification action pacea
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlbrjc committed Jan 22, 2025
1 parent 841f0db commit 3504b0f
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 119 deletions.
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 Down Expand Up @@ -72,7 +72,7 @@ export class GetActionsJeuneQueryHandler extends QueryHandler<

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

Expand Down
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
7 changes: 2 additions & 5 deletions src/application/queries/query-models/actions.query-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ export class ActionQueryModel {
@ApiProperty()
creator: string

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

@ApiProperty()
dateEcheance: string
Expand Down
24 changes: 10 additions & 14 deletions src/infrastructure/repositories/mappers/actions.mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ import {
} from '../../../application/queries/query-models/actions.query-model'
import { JeuneQueryModel } from '../../../application/queries/query-models/jeunes.query-model'
import { Action } from '../../../domain/action/action'
import { Jeune } from '../../../domain/jeune/jeune'
import { DateService } from '../../../utils/date-service'
import { ActionSqlModel } from '../../sequelize/models/action.sql-model'
import { JeuneSqlModel } from '../../sequelize/models/jeune.sql-model'

export function fromSqlToActionQueryModelWithJeune(
actionSqlModel: ActionSqlModel
): ActionQueryModel {
return {
...fromSqlToActionQueryModel(actionSqlModel),
jeune: fromSqlToJeuneQueryModel(actionSqlModel.jeune)
}
}

export function fromSqlToActionQueryModel(
actionSqlModel: ActionSqlModel
): ActionQueryModel {
return {
id: actionSqlModel.id,
Expand All @@ -40,8 +32,11 @@ export function fromSqlToActionQueryModel(
dateFinReelle: actionSqlModel.dateFinReelle
? DateService.fromJSDateToISOString(actionSqlModel.dateFinReelle)
: undefined,
etat: buildEtat(actionSqlModel),
qualification: buildQualificationQueryModel(actionSqlModel)
etat: buildEtat(actionSqlModel, {
qualifiable: actionSqlModel.jeune.dispositif === Jeune.Dispositif.CEJ
}),
qualification: buildQualificationQueryModel(actionSqlModel),
jeune: fromSqlToJeuneQueryModel(actionSqlModel.jeune)
}
}

Expand All @@ -56,16 +51,17 @@ function fromSqlToJeuneQueryModel(
}
}

export function buildEtat(
actionSqlModel: ActionSqlModel
function buildEtat(
actionSqlModel: ActionSqlModel,
{ qualifiable }: { qualifiable: boolean }
): Action.Qualification.Etat {
if (
actionSqlModel.codeQualification &&
actionSqlModel.heuresQualifiees !== null
) {
return Action.Qualification.Etat.QUALIFIEE
}
if (actionSqlModel.statut === Action.Statut.TERMINEE) {
if (qualifiable && actionSqlModel.statut === Action.Statut.TERMINEE) {
return Action.Qualification.Etat.A_QUALIFIER
}
return Action.Qualification.Etat.NON_QUALIFIABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(
actionTerminee2,
jeune,
Action.Qualification.Etat.A_QUALIFIER
),
uneActionQueryModelFromDomain(
actionTerminee3,
jeune,
Action.Qualification.Etat.A_QUALIFIER
),
uneActionQueryModelFromDomain(
actionTerminee1,
jeune,
Action.Qualification.Etat.A_QUALIFIER
)
])
Expand Down Expand Up @@ -186,9 +189,9 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(isSuccess(result)).to.be.true()
if (isSuccess(result)) {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(actionEnCours2),
uneActionQueryModelFromDomain(actionPasCommencee),
uneActionQueryModelFromDomain(actionEnCours1)
uneActionQueryModelFromDomain(actionEnCours2, jeune),
uneActionQueryModelFromDomain(actionPasCommencee, jeune),
uneActionQueryModelFromDomain(actionEnCours1, jeune)
])
}
})
Expand Down Expand Up @@ -243,14 +246,16 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(isSuccess(result)).to.be.true()
if (isSuccess(result)) {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(actionEnCours),
uneActionQueryModelFromDomain(actionPasCommencee),
uneActionQueryModelFromDomain(actionEnCours, jeune),
uneActionQueryModelFromDomain(actionPasCommencee, jeune),
uneActionQueryModelFromDomain(
actionTerminee2,
jeune,
Action.Qualification.Etat.A_QUALIFIER
),
uneActionQueryModelFromDomain(
actionTerminee1,
jeune,
Action.Qualification.Etat.A_QUALIFIER
)
])
Expand Down Expand Up @@ -318,7 +323,7 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(isSuccess(result)).to.be.true()
if (isSuccess(result)) {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(actionPage2)
uneActionQueryModelFromDomain(actionPage2, jeune)
])
expect(result.data.metadonnees.nombreTotal).to.equal(11)
}
Expand Down Expand Up @@ -370,11 +375,12 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(
actionTermineeRecente,
jeune,
Action.Qualification.Etat.A_QUALIFIER
),
uneActionQueryModelFromDomain(actionPasCommencee),
uneActionQueryModelFromDomain(actionEnCours),
uneActionQueryModelFromDomain(actionCanceled)
uneActionQueryModelFromDomain(actionPasCommencee, jeune),
uneActionQueryModelFromDomain(actionEnCours, jeune),
uneActionQueryModelFromDomain(actionCanceled, jeune)
])
}
})
Expand Down Expand Up @@ -427,11 +433,12 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(isSuccess(result)).to.be.true()
if (isSuccess(result)) {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(actionCanceled),
uneActionQueryModelFromDomain(actionEnCours),
uneActionQueryModelFromDomain(actionPasCommencee),
uneActionQueryModelFromDomain(actionCanceled, jeune),
uneActionQueryModelFromDomain(actionEnCours, jeune),
uneActionQueryModelFromDomain(actionPasCommencee, jeune),
uneActionQueryModelFromDomain(
actionTerminee,
jeune,
Action.Qualification.Etat.A_QUALIFIER
)
])
Expand Down Expand Up @@ -484,10 +491,12 @@ describe('GetActionsByJeuneQueryHandler', () => {

actionQMNonQualifiable = uneActionQueryModelFromDomain(
actionNonQualifiable,
jeune,
Action.Qualification.Etat.NON_QUALIFIABLE
)
actionQMQualifiee = uneActionQueryModelFromDomain(
actionQualifiee,
jeune,
Action.Qualification.Etat.QUALIFIEE,
{
code: Action.Qualification.Code.SANTE,
Expand All @@ -498,6 +507,7 @@ describe('GetActionsByJeuneQueryHandler', () => {
)
actionQMAQualifier = uneActionQueryModelFromDomain(
actionAQualifier,
jeune,
Action.Qualification.Etat.A_QUALIFIER
)

Expand Down Expand Up @@ -623,8 +633,8 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(isSuccess(result)).to.be.true()
if (isSuccess(result)) {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(actionEnCours),
uneActionQueryModelFromDomain(actionPasCommencee)
uneActionQueryModelFromDomain(actionEnCours, jeune),
uneActionQueryModelFromDomain(actionPasCommencee, jeune)
])
expect(result.data.metadonnees.nombreTotal).to.equal(4)
}
Expand Down Expand Up @@ -705,6 +715,7 @@ describe('GetActionsByJeuneQueryHandler', () => {
expect(result.data.actions).to.be.deep.equal([
uneActionQueryModelFromDomain(
actionCitoyennete,
jeune,
Action.Qualification.Etat.NON_QUALIFIABLE,
{
code: Action.Qualification.Code.CITOYENNETE,
Expand All @@ -715,6 +726,7 @@ describe('GetActionsByJeuneQueryHandler', () => {
),
uneActionQueryModelFromDomain(
actionCitoyennete2,
jeune,
Action.Qualification.Etat.NON_QUALIFIABLE,
{
code: Action.Qualification.Code.CITOYENNETE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('GetDetailActionQueryHandler', () => {

// Then
expect(actionQueryModel).to.deep.equal(
uneActionQueryModelTermineeAvecQualification(action)
uneActionQueryModelTermineeAvecQualification(action, jeune)
)
})
})
Expand All @@ -113,13 +113,7 @@ describe('GetDetailActionQueryHandler', () => {

// Then
expect(actionQueryModel).to.deep.equal({
...uneActionQueryModelFromDomain(action),
jeune: {
id: action.idJeune,
firstName: jeune.firstName,
lastName: jeune.lastName,
idConseiller: jeune.conseiller.id
},
...uneActionQueryModelFromDomain(action, jeune),
qualification: undefined
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GetCampagneQueryGetter } from '../../../src/application/queries/query-g
import { Core } from '../../../src/domain/core'
import { unUtilisateurJeune } from '../../fixtures/authentification.fixture'
import { uneCampagneQueryModel } from '../../fixtures/campagne.fixture'
import { uneActionQueryModelFromDomain } from '../../fixtures/query-models/action.query-model.fixtures'
import { uneActionQueryModel } from '../../fixtures/query-models/action.query-model.fixtures'
import { expect, StubbedClass, stubClass } from '../../utils'
import Structure = Core.Structure

Expand All @@ -20,7 +20,7 @@ describe('GetJeuneHomeActionsQueryHandler', () => {
let getJeuneHomeActionsQueryHandler: GetJeuneHomeActionsQueryHandler

const campagneQueryModel = uneCampagneQueryModel()
const actionsQueryModel = [uneActionQueryModelFromDomain()]
const actionsQueryModel = [uneActionQueryModel()]

beforeEach(() => {
getActionsByJeuneQueryHandler = stubClass(GetActionsJeuneQueryHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
unUtilisateurJeune
} from 'test/fixtures/authentification.fixture'
import { unJeune } from 'test/fixtures/jeune.fixture'
import { uneActionQueryModelSansJeune } from 'test/fixtures/query-models/action.query-model.fixtures'
import { uneActionQueryModel } from 'test/fixtures/query-models/action.query-model.fixtures'
import { unRendezVousQueryModel } from 'test/fixtures/query-models/rendez-vous.query-model.fixtures'
import { uneSessionJeuneMiloQueryModel } from 'test/fixtures/sessions.fixture'
import { uneActionDto } from 'test/fixtures/sql-models/action.sql-model'
Expand Down Expand Up @@ -169,11 +169,11 @@ describe('GetJeuneHomeAgendaQueryHandler', () => {
// Then
const expected: JeuneHomeAgendaQueryModel = {
actions: [
uneActionQueryModelSansJeune({
uneActionQueryModel({
id: lundiDernier.id,
dateEcheance: DateTime.fromJSDate(lundiDernier.dateEcheance).toISO()
}),
uneActionQueryModelSansJeune({
uneActionQueryModel({
id: dimancheEnHuit.id,
dateEcheance: DateTime.fromJSDate(
dimancheEnHuit.dateEcheance
Expand Down Expand Up @@ -208,11 +208,11 @@ describe('GetJeuneHomeAgendaQueryHandler', () => {
it('renvoie les actions triées par date', async () => {
// Then
const actionsQM: ActionQueryModel[] = [
uneActionQueryModelSansJeune({
uneActionQueryModel({
id: demain.id,
dateEcheance: DateTime.fromJSDate(demain.dateEcheance).toISO()
}),
uneActionQueryModelSansJeune({
uneActionQueryModel({
id: apresDemain.id,
dateEcheance: DateTime.fromJSDate(apresDemain.dateEcheance).toISO()
})
Expand Down
Loading

0 comments on commit 3504b0f

Please sign in to comment.