Skip to content

Commit

Permalink
feat(sessions-milo): ajout de la structure Milo pour le jeune
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzem committed Jun 22, 2023
1 parent cd08b36 commit 0a4d33f
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ import { ModifierConseillerCommandHandler } from './application/commands/modifie
import { HandleJobNotifierNouvellesOffresEmploiCommandHandler } from './application/commands/jobs/handle-job-notifier-nouvelles-offres-emploi.command'
import { HandleJobNotifierNouveauxServicesCiviqueCommandHandler } from './application/commands/jobs/handle-job-notification-recherche-service-civique.command.handler'
import { GetFavorisServiceCiviqueJeuneQueryHandler } from './application/queries/get-favoris-service-civique-jeune.query.handler.db'
import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from './application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command'
import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from './application/jobs/handle-job-recuperer-situations-jeunes-milo.command'
import { CampagnesController } from './infrastructure/routes/campagnes.controller'
import { Campagne, CampagneRepositoryToken } from './domain/campagne'
import { CampagneSqlRepository } from './infrastructure/repositories/campagne-sql.repository.db'
Expand Down Expand Up @@ -298,7 +298,7 @@ import {
RendezVousMilo,
MiloRendezVousRepositoryToken
} from './domain/rendez-vous/rendez-vous.milo'
import { MiloJeuneRepositoryToken } from './domain/jeune/jeune.milo'
import { MiloJeuneRepositoryToken } from './domain/milo/jeune.milo'
import { HandleJobFakeCommandHandler } from './application/commands/jobs/handle-job-fake.command'
import { MettreAJourLesJeunesCejPeCommandHandler } from './application/commands/mettre-a-jour-les-jeunes-cej-pe.command.handler'
import { UpdateAgenceConseillerCommandHandler } from './application/commands/support/update-agence-conseiller.command.handler'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Jeune, JeunesRepositoryToken } from '../../domain/jeune/jeune'
import {
JeuneMilo,
MiloJeuneRepositoryToken
} from '../../domain/jeune/jeune.milo'
} from '../../domain/milo/jeune.milo'
import { ConseillerAuthorizer } from '../authorizers/conseiller-authorizer'
import { IdentiteJeuneQueryModel } from '../queries/query-models/jeunes.query-model'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Inject, Injectable } from '@nestjs/common'
import { Job } from '../../../building-blocks/types/job'
import { JobHandler } from '../../../building-blocks/types/job-handler'
import { isFailure } from '../../../building-blocks/types/result'
import { Jeune, JeunesRepositoryToken } from '../../../domain/jeune/jeune'
import { Planificateur, ProcessJobType } from '../../../domain/planificateur'
import { SuiviJob, SuiviJobServiceToken } from '../../../domain/suivi-job'
import { DateService } from '../../../utils/date-service'
import { Job } from '../../building-blocks/types/job'
import { JobHandler } from '../../building-blocks/types/job-handler'
import { isFailure } from '../../building-blocks/types/result'
import { Jeune, JeunesRepositoryToken } from '../../domain/jeune/jeune'
import { Planificateur, ProcessJobType } from '../../domain/planificateur'
import { SuiviJob, SuiviJobServiceToken } from '../../domain/suivi-job'
import { DateService } from '../../utils/date-service'
import {
JeuneMilo,
MiloJeuneRepositoryToken
} from '../../../domain/jeune/jeune.milo'
} from '../../domain/milo/jeune.milo'

const PAGINATION_NOMBRE_DE_JEUNES_MAXIMUM = 100

Expand Down Expand Up @@ -71,6 +71,11 @@ export class HandleJobRecupererSituationsJeunesMiloCommandHandler extends JobHan
const jeuneAvecDateFinCEJ = Jeune.mettreAJour(jeune, { dateFinCEJ })
await this.jeuneRepository.save(jeuneAvecDateFinCEJ)

await this.miloRepository.saveStructureJeune(
jeune.id,
dossier.data.nomStructure
)

const situationsTriees = JeuneMilo.trierSituations(
dossier.data.situations
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { estMilo } from '../../domain/core'
import {
JeuneMilo,
MiloJeuneRepositoryToken
} from '../../domain/jeune/jeune.milo'
} from '../../domain/milo/jeune.milo'
import { ConseillerAuthorizer } from '../authorizers/conseiller-authorizer'
import { DossierJeuneMiloQueryModel } from './query-models/milo.query-model'

Expand Down
2 changes: 1 addition & 1 deletion src/application/queries/query-models/jeunes.query-model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { JeuneMilo } from '../../../domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../domain/milo/jeune.milo'
import { Jeune } from '../../../domain/jeune/jeune'

class SituationQueryModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export namespace JeuneMilo {
codePostal: string
situations: Situation[]
dateFinCEJ?: DateTime
nomStructure: string
}

export enum EtatSituation {
Expand All @@ -45,6 +46,10 @@ export namespace JeuneMilo {
export interface Repository {
getDossier(id: string): Promise<Result<Dossier>>
saveSituationsJeune(situations: Situations): Promise<void>
saveStructureJeune(
idJeune: string,
nomOfficielStructureMilo: string
): Promise<void>
getSituationsByJeune(idJeune: string): Promise<Situations | undefined>
creerJeune(
idDossier: string
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/jdd/situation.jdd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SituationsMiloDto } from '../sequelize/models/situations-milo.sql-model'
import { AsSql } from '../sequelize/types'
import { JeuneMilo } from '../../domain/jeune/jeune.milo'
import { JeuneMilo } from '../../domain/milo/jeune.milo'

export const uneSituationsMiloJdd = (
args: Partial<SituationsMiloDto> = {}
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/repositories/dto/milo.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JeuneMilo } from '../../../domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../domain/milo/jeune.milo'

export interface DossierMiloDto {
idDossier: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.excepti
import { firstValueFrom } from 'rxjs'
import { ErreurHttp } from '../../../building-blocks/types/domain-error'
import { Result, failure, success } from '../../../building-blocks/types/result'
import { JeuneMilo } from '../../../domain/milo/jeune.milo'
import { DateService } from '../../../utils/date-service'
import { RateLimiterService } from '../../../utils/rate-limiter.service'
import { JeuneSqlModel } from '../../sequelize/models/jeune.sql-model'
import { SituationsMiloSqlModel } from '../../sequelize/models/situations-milo.sql-model'
import { StructureMiloSqlModel } from '../../sequelize/models/structure-milo.sql-model'
import { DossierMiloDto } from '../dto/milo.dto'
import { JeuneMilo } from '../../../domain/jeune/jeune.milo'

@Injectable()
export class MiloJeuneHttpSqlRepository implements JeuneMilo.Repository {
Expand Down Expand Up @@ -57,7 +59,8 @@ export class MiloJeuneHttpSqlRepository implements JeuneMilo.Repository {
categorie: situation.categorieSituation,
dateFin: situation.dateFin ?? undefined
}
})
}),
nomStructure: dossierDto.data.structureRattachement.nomOfficiel
})
} catch (e) {
this.logger.error(e)
Expand Down Expand Up @@ -125,6 +128,26 @@ export class MiloJeuneHttpSqlRepository implements JeuneMilo.Repository {
)
}

async saveStructureJeune(
idJeune: string,
nomOfficielStructureMilo: string
): Promise<void> {
const structureSql = await StructureMiloSqlModel.findOne({
where: {
nomOfficiel: nomOfficielStructureMilo
}
})

if (structureSql) {
await JeuneSqlModel.update(
{
idStructureMilo: structureSql.id
},
{ where: { id: idJeune } }
)
}
}

async getSituationsByJeune(
idJeune: string
): Promise<JeuneMilo.Situations | undefined> {
Expand Down
3 changes: 2 additions & 1 deletion src/infrastructure/repositories/mappers/jeunes.mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export function toSqlJeune(
email: jeune.email ?? null,
structure: jeune.structure,
idPartenaire: jeune.idPartenaire ?? null,
partageFavoris: jeune.preferences.partageFavoris
partageFavoris: jeune.preferences.partageFavoris,
idStructureMilo: null
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn(
'jeune',
'id_structure_milo',
{
type: Sequelize.STRING,
allowNull: true,
references: {
model: 'structure_milo',
key: 'id'
}
},
{ transaction }
)
})
},

async down(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.removeColumn('jeune', 'id_structure_milo', {
transaction
})
})
}
}
4 changes: 2 additions & 2 deletions src/infrastructure/sequelize/models/conseiller.sql-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export class ConseillerSqlModel extends ConseillerDto {
@HasMany(() => JeuneSqlModel)
jeunes!: JeuneSqlModel[]

@BelongsTo(() => AgenceSqlModel, 'id_agence')
@BelongsTo(() => AgenceSqlModel)
agence?: AgenceSqlModel

@BelongsTo(() => StructureMiloSqlModel, 'id_structure_milo')
@BelongsTo(() => StructureMiloSqlModel)
structureMilo?: StructureMiloSqlModel

static async creer(conseillerDto: AsSql<ConseillerDto>): Promise<void> {
Expand Down
11 changes: 11 additions & 0 deletions src/infrastructure/sequelize/models/jeune.sql-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RendezVousJeuneAssociationSqlModel } from './rendez-vous-jeune-associat
import { RendezVousSqlModel } from './rendez-vous.sql-model'
import { SituationsMiloSqlModel } from './situations-milo.sql-model'
import { TransfertConseillerSqlModel } from './transfert-conseiller.sql-model'
import { StructureMiloSqlModel } from './structure-milo.sql-model'

export class JeuneDto extends Model {
@PrimaryKey
Expand Down Expand Up @@ -141,6 +142,13 @@ export class JeuneDto extends Model {
type: DataType.BOOLEAN
})
partageFavoris: boolean

@ForeignKey(() => StructureMiloSqlModel)
@Column({
field: 'id_structure_milo',
type: DataType.STRING
})
idStructureMilo?: string | null
}

@Table({
Expand All @@ -166,6 +174,9 @@ export class JeuneSqlModel extends JeuneDto {
@HasOne(() => SituationsMiloSqlModel)
situations?: SituationsMiloSqlModel

@BelongsTo(() => StructureMiloSqlModel)
structureMilo?: StructureMiloSqlModel

static async creer(jeuneDto: AsSql<JeuneDto>): Promise<JeuneSqlModel> {
return JeuneSqlModel.create(jeuneDto)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Table
} from 'sequelize-typescript'
import { JeuneSqlModel } from './jeune.sql-model'
import { JeuneMilo } from '../../../domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../domain/milo/jeune.milo'

export interface Situation {
etat: JeuneMilo.EtatSituation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Chat } from '../../../src/domain/chat'
import { Conseiller } from '../../../src/domain/conseiller/conseiller'
import { Core, estMilo } from '../../../src/domain/core'
import { Jeune } from '../../../src/domain/jeune/jeune'
import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../src/domain/milo/jeune.milo'
import { DateService } from '../../../src/utils/date-service'
import { IdService } from '../../../src/utils/id-service'
import { unUtilisateurConseiller } from '../../fixtures/authentification.fixture'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StubbedType, stubInterface } from '@salesforce/ts-sinon'
import { SinonSandbox } from 'sinon'
import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from 'src/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command'
import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from 'src/application/jobs/handle-job-recuperer-situations-jeunes-milo.command'
import { ErreurHttp } from 'src/building-blocks/types/domain-error'
import { failure, success } from 'src/building-blocks/types/result'
import { Core } from 'src/domain/core'
Expand All @@ -9,9 +9,9 @@ import { SuiviJob } from 'src/domain/suivi-job'
import { uneDatetime } from 'test/fixtures/date.fixture'
import { unJeune } from 'test/fixtures/jeune.fixture'
import { unDossierMilo } from 'test/fixtures/milo.fixture'
import { DateService } from '../../../../src/utils/date-service'
import { createSandbox, expect, StubbedClass, stubClass } from '../../../utils'
import { JeuneMilo } from '../../../../src/domain/jeune/jeune.milo'
import { DateService } from '../../../src/utils/date-service'
import { createSandbox, expect, StubbedClass, stubClass } from '../../utils'
import { JeuneMilo } from '../../../src/domain/milo/jeune.milo'

describe('HandleJobRecupererSituationsJeunesMiloCommandHandler', () => {
let handleJobRecupererSituationsJeunesMiloCommandHandler: HandleJobRecupererSituationsJeunesMiloCommandHandler
Expand Down Expand Up @@ -60,6 +60,7 @@ describe('HandleJobRecupererSituationsJeunesMiloCommandHandler', () => {
await handleJobRecupererSituationsJeunesMiloCommandHandler.handle()

// Then
expect(miloRepository.saveStructureJeune).to.have.callCount(0)
expect(miloRepository.saveSituationsJeune).to.have.callCount(0)
expect(result.succes).to.equal(true)
expect(result.resultat).to.deep.equal({
Expand Down Expand Up @@ -90,6 +91,9 @@ describe('HandleJobRecupererSituationsJeunesMiloCommandHandler', () => {
await handleJobRecupererSituationsJeunesMiloCommandHandler.handle()

// Then
expect(
miloRepository.saveStructureJeune
).to.have.been.calledOnceWithExactly(jeune1.id, 'ML')
expect(miloRepository.saveSituationsJeune).to.have.callCount(1)
expect(
miloRepository.saveSituationsJeune
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
GetDetailJeuneQuery,
GetDetailJeuneQueryHandler
} from '../../../src/application/queries/get-detail-jeune.query.handler.db'
import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../src/domain/milo/jeune.milo'
import {
unUtilisateurConseiller,
unUtilisateurJeune
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
GetDossierMiloJeuneQueryHandler
} from '../../../src/application/queries/get-dossier-milo-jeune.query.handler'
import { estMilo } from '../../../src/domain/core'
import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../src/domain/milo/jeune.milo'
import { unUtilisateurConseiller } from '../../fixtures/authentification.fixture'
import { unDossierMilo } from '../../fixtures/milo.fixture'
import { StubbedClass, createSandbox, expect, stubClass } from '../../utils'
Expand Down
2 changes: 1 addition & 1 deletion test/domain/jeune/jeune.milo.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '../../utils'
import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo'
import { JeuneMilo } from '../../../src/domain/milo/jeune.milo'

describe('Milo', () => {
const situationsPrevuEmploi = {
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/milo.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SituationsMiloDto } from 'src/infrastructure/sequelize/models/situations-milo.sql-model'
import { AsSql } from 'src/infrastructure/sequelize/types'
import { JeuneMilo } from '../../src/domain/jeune/jeune.milo'
import { JeuneMilo } from '../../src/domain/milo/jeune.milo'

export const unDossierMilo = (
args: Partial<JeuneMilo.Dossier> = {}
Expand All @@ -12,7 +12,8 @@ export const unDossierMilo = (
dateDeNaissance: '1888-09-01',
codePostal: '91580',
email: 'jack.dawson@milo.com',
situations: []
situations: [],
nomStructure: 'ML'
}
return { ...defaults, ...args }
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/sql-models/jeune.sql-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function unJeuneDto(
installationId: '123456',
instanceId: 'abcdef',
partageFavoris: true,
timezone: 'Europe/Paris'
timezone: 'Europe/Paris',
idStructureMilo: null
}

return { ...defaults, ...args }
Expand Down
Loading

0 comments on commit 0a4d33f

Please sign in to comment.