From 3ff46022154be47da065570edb8a21ec9115f794 Mon Sep 17 00:00:00 2001 From: Ha Minh Chien Date: Tue, 31 Dec 2024 14:03:46 +0700 Subject: [PATCH] feat(be): branch delete --- .../src/app/bio-product/use-case/delete.ts | 43 ++++--- .../src/app/branch/use-case/delete.ts | 53 ++++++-- .../src/app/diagnosis/use-case/delete.ts | 46 +++---- .../src/app/doctor/use-case/delete.ts | 36 +++--- .../src/app/instrument/use-case/delete.ts | 44 +++---- .../src/app/patient-type/use-case/delete.ts | 44 ++++--- .../src/app/patient/use-case/delete.ts | 35 +++--- .../src/app/print-form/use-case/delete.ts | 44 +++---- .../src/app/role/use-case/delete.ts | 34 ++--- .../src/app/sample-type/use-case/delete.ts | 58 +++++---- .../src/app/sample/module.ts | 2 - .../src/app/sample/use-case/delete-many.ts | 21 ---- .../src/app/sample/use-case/delete.ts | 34 ++--- .../src/app/test-category/use-case/delete.ts | 43 +++---- .../src/app/test-combo/use-case/delete.ts | 32 ++--- .../src/app/test-combo/use-case/update.ts | 28 +++-- .../src/app/test-element/use-case/delete.ts | 30 ++--- .../src/app/test/use-case/delete.ts | 61 +++++---- .../src/app/user/use-case/delete.ts | 41 +++--- .../http/shared/entity/bio-product.ts | 2 - .../http/shared/entity/diagnosis.ts | 1 - .../controller/http/shared/entity/doctor.ts | 1 - .../http/shared/entity/instrument.ts | 2 - .../http/shared/entity/patient-type.ts | 1 - .../controller/http/shared/entity/patient.ts | 1 - .../http/shared/entity/print-form.ts | 1 - .../src/controller/http/shared/entity/role.ts | 1 - .../http/shared/entity/sample-type.ts | 1 - .../controller/http/shared/entity/sample.ts | 6 - .../http/shared/entity/test-category.ts | 1 - .../http/shared/entity/test-combo.ts | 1 - .../http/shared/entity/test-element.ts | 1 - .../src/controller/http/shared/entity/test.ts | 6 - .../http/v1/bio-product/dto/response-dto.ts | 8 +- .../http/v1/branch/dto/request-dto.ts | 3 +- .../http/v1/diagnosis/dto/response-dto.ts | 5 +- .../http/v1/doctor/dto/response-dto.ts | 5 +- .../http/v1/instrument/dto/response-dto.ts | 3 +- .../http/v1/patient-type/dto/response-dto.ts | 5 +- .../http/v1/patient/dto/response-dto.ts | 5 +- .../http/v1/print-form/dto/response-dto.ts | 5 +- .../http/v1/role/dto/response-dto.ts | 5 +- .../http/v1/sample-type/dto/response-dto.ts | 5 +- .../http/v1/sample/dto/response-dto.ts | 3 +- .../http/v1/test-category/dto/response-dto.ts | 5 +- .../http/v1/test-combo/dto/response-dto.ts | 5 +- .../http/v1/test-element/dto/response-dto.ts | 3 +- .../http/v1/test/dto/response-dto.ts | 3 +- .../src/infra/mongo/bio-product/schema.ts | 4 +- .../src/infra/mongo/branch/schema.ts | 2 +- .../src/infra/mongo/diagnosis/schema.ts | 2 +- .../src/infra/mongo/doctor/schema.ts | 2 +- .../src/infra/mongo/instrument/schema.ts | 4 +- .../src/infra/mongo/patient-type/schema.ts | 2 +- .../src/infra/mongo/patient/schema.ts | 2 +- .../src/infra/mongo/print-form/schema.ts | 2 +- .../src/infra/mongo/role/schema.ts | 2 +- .../src/infra/mongo/sample-type/schema.ts | 2 +- .../src/infra/mongo/sample/schema.ts | 14 +-- .../src/infra/mongo/test-category/schema.ts | 2 +- .../src/infra/mongo/test-combo/schema.ts | 4 +- .../src/infra/mongo/test-element/schema.ts | 2 +- .../src/infra/mongo/test/schema.ts | 12 +- .../src/infra/mongo/user/schema.ts | 4 +- .../src/components/layout/AppBar/index.tsx | 30 ++--- .../src/components/table/CrudTable/index.tsx | 8 +- .../src/features/auth/state/slice.ts | 44 +++++++ .../components/BranchOriginSelector/index.tsx | 110 ++++++++++++++++ .../branch/components/BranchTable/index.tsx | 117 ++++++++++-------- .../src/features/branch/components/index.ts | 1 + .../src/infra/api/access-service/auth.ts | 1 + .../src/infra/api/access-service/branch.ts | 14 ++- .../src/shared/constants/index.ts | 2 +- libs/hcdc/src/entity/bio-product/entity.ts | 4 +- libs/hcdc/src/entity/branch/entity.ts | 2 +- libs/hcdc/src/entity/diagnosis/entity.ts | 2 +- libs/hcdc/src/entity/doctor/entity.ts | 2 +- libs/hcdc/src/entity/instrument/entity.ts | 4 +- libs/hcdc/src/entity/patient-type/entity.ts | 2 +- libs/hcdc/src/entity/patient/entity.ts | 2 +- libs/hcdc/src/entity/print-form/entity.ts | 2 +- libs/hcdc/src/entity/role/entity.ts | 2 +- libs/hcdc/src/entity/sample-type/entity.ts | 2 +- libs/hcdc/src/entity/sample/entity.ts | 14 +-- libs/hcdc/src/entity/test-category/entity.ts | 2 +- libs/hcdc/src/entity/test-combo/entity.ts | 4 +- libs/hcdc/src/entity/test-element/entity.ts | 2 +- libs/hcdc/src/entity/test/entity.ts | 12 +- libs/hcdc/src/entity/user/entity.ts | 4 +- .../src/adapter/mongo/repository.ts | 4 +- 90 files changed, 745 insertions(+), 533 deletions(-) delete mode 100644 apps/hcdc-access-service/src/app/sample/use-case/delete-many.ts create mode 100644 apps/hcdc-web-app/src/features/branch/components/BranchOriginSelector/index.tsx diff --git a/apps/hcdc-access-service/src/app/bio-product/use-case/delete.ts b/apps/hcdc-access-service/src/app/bio-product/use-case/delete.ts index b16019fd..d9777fbd 100644 --- a/apps/hcdc-access-service/src/app/bio-product/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/bio-product/use-case/delete.ts @@ -1,16 +1,16 @@ -import { AuthSubject, BioProductAction } from '@diut/hcdc' +import { AuthSubject, BioProduct, BioProductAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, BIOPRODUCT_REPO_TOKEN, - EEntityCannotDelete, IAuthContext, IBioProductRepository, ITestRepository, TEST_REPO_TOKEN, } from 'src/domain' -import { BioProductAssertExistsUseCase } from './assert-exists' +import { BioProductSearchUseCase } from './search' @Injectable() export class BioProductDeleteUseCase { @@ -21,30 +21,29 @@ export class BioProductDeleteUseCase { private readonly bioProductRepository: IBioProductRepository, @Inject(TEST_REPO_TOKEN) private readonly testRepository: ITestRepository, - private readonly bioProductAssertExistsUseCase: BioProductAssertExistsUseCase, + private readonly bioProductSearchUseCase: BioProductSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.bioProductAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.BioProduct, - BioProductAction.Delete, - entity, - ) - - const connectedTestCount = await this.testRepository.count({ - bioProductId: input.id, + const { items: bioProducts } = await this.bioProductSearchUseCase.execute({ + filter: input, }) - if (connectedTestCount > 0) { - throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) - } - await this.bioProductRepository.deleteById(input.id) + for (const bioProduct of bioProducts) { + assertPermission( + ability, + AuthSubject.BioProduct, + BioProductAction.Delete, + bioProduct, + ) - return entity + await this.testRepository.updateMany( + { bioProductId: bioProduct._id }, + { bioProductId: null }, + ) + + await this.bioProductRepository.deleteById(bioProduct._id) + } } } diff --git a/apps/hcdc-access-service/src/app/branch/use-case/delete.ts b/apps/hcdc-access-service/src/app/branch/use-case/delete.ts index a1135879..d7ad810c 100644 --- a/apps/hcdc-access-service/src/app/branch/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/branch/use-case/delete.ts @@ -1,14 +1,23 @@ -import { AuthSubject, BranchAction } from '@diut/hcdc' +import { AuthSubject, Branch, BranchAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' +import { DiagnosisDeleteUseCase } from 'src/app/diagnosis/use-case/delete' +import { DoctorDeleteUseCase } from 'src/app/doctor/use-case/delete' +import { PatientTypeDeleteUseCase } from 'src/app/patient-type/use-case/delete' +import { PatientDeleteUseCase } from 'src/app/patient/use-case/delete' +import { PrintFormDeleteUseCase } from 'src/app/print-form/use-case/delete' +import { RoleDeleteUseCase } from 'src/app/role/use-case/delete' +import { TestComboDeleteUseCase } from 'src/app/test-combo/use-case/delete' +import { TestDeleteUseCase } from 'src/app/test/use-case/delete' +import { UserDeleteUseCase } from 'src/app/user/use-case/delete' import { AUTH_CONTEXT_TOKEN, BRANCH_REPO_TOKEN, - EEntityCannotDelete, IAuthContext, IBranchRepository, } from 'src/domain' -import { BranchAssertExistsUseCase } from './assert-exists' +import { BranchSearchUseCase } from './search' @Injectable() export class BranchDeleteUseCase { @@ -17,20 +26,40 @@ export class BranchDeleteUseCase { private readonly authContext: IAuthContext, @Inject(BRANCH_REPO_TOKEN) private readonly branchRepository: IBranchRepository, - private readonly branchAssertExistsUseCase: BranchAssertExistsUseCase, + private readonly branchSearchUseCase: BranchSearchUseCase, + private readonly patientDeleteUseCase: PatientDeleteUseCase, + private readonly testDeleteUseCase: TestDeleteUseCase, + private readonly testComboDeleteUseCase: TestComboDeleteUseCase, + private readonly diagnosisDeleteUseCase: DiagnosisDeleteUseCase, + private readonly doctorDeleteUseCase: DoctorDeleteUseCase, + private readonly patientTypeDeleteUseCase: PatientTypeDeleteUseCase, + private readonly printFormDeleteUseCase: PrintFormDeleteUseCase, + private readonly userDeleteUseCase: UserDeleteUseCase, + private readonly roleDeleteUseCase: RoleDeleteUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.branchAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission(ability, AuthSubject.Branch, BranchAction.Delete, entity) + const { items: branches } = await this.branchSearchUseCase.execute(input) - throw new EEntityCannotDelete(`there are infinitely connected resources`) + for (const branch of branches) { + assertPermission(ability, AuthSubject.Branch, BranchAction.Delete, branch) - await this.branchRepository.deleteById(input.id) + // patient and all related sample + await this.patientDeleteUseCase.execute({ branchId: branch._id }) - return entity + // infra + await this.testComboDeleteUseCase.execute({ branchId: branch._id }) + await this.testDeleteUseCase.execute({ branchId: branch._id }) + await this.diagnosisDeleteUseCase.execute({ branchId: branch._id }) + await this.doctorDeleteUseCase.execute({ branchId: branch._id }) + await this.patientTypeDeleteUseCase.execute({ branchId: branch._id }) + await this.printFormDeleteUseCase.execute({ branchId: branch._id }) + await this.userDeleteUseCase.execute({ branchId: branch._id }) + await this.roleDeleteUseCase.execute({ branchId: branch._id }) + + // finally + await this.branchRepository.deleteById(branch._id) + } } } diff --git a/apps/hcdc-access-service/src/app/diagnosis/use-case/delete.ts b/apps/hcdc-access-service/src/app/diagnosis/use-case/delete.ts index 62652b12..3275eb11 100644 --- a/apps/hcdc-access-service/src/app/diagnosis/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/diagnosis/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, DiagnosisAction } from '@diut/hcdc' +import { AuthSubject, Diagnosis, DiagnosisAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { ISampleRepository, SAMPLE_REPO_TOKEN, } from 'src/domain' -import { DiagnosisAssertExistsUseCase } from './assert-exists' +import { DiagnosisSearchUseCase } from './search' @Injectable() export class DiagnosisDeleteUseCase { @@ -21,30 +22,33 @@ export class DiagnosisDeleteUseCase { private readonly diagnosisRepository: IDiagnosisRepository, @Inject(SAMPLE_REPO_TOKEN) private readonly sampleRepository: ISampleRepository, - private readonly diagnosisAssertExistsUseCase: DiagnosisAssertExistsUseCase, + private readonly diagnosisSearchUseCase: DiagnosisSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.diagnosisAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.Diagnosis, - DiagnosisAction.Delete, - entity, - ) - - const connectedSampleCount = await this.sampleRepository.count({ - diagnosisId: input.id, + const { items: diagnoses } = await this.diagnosisSearchUseCase.execute({ + filter: input, }) - if (connectedSampleCount > 0) { - throw new EEntityCannotDelete(`${connectedSampleCount} connected Sample`) - } - await this.diagnosisRepository.deleteById(input.id) + for (const diagnosis of diagnoses) { + assertPermission( + ability, + AuthSubject.Diagnosis, + DiagnosisAction.Delete, + diagnosis, + ) - return entity + const connectedSampleCount = await this.sampleRepository.count({ + diagnosisId: diagnosis._id, + }) + if (connectedSampleCount > 0) { + throw new EEntityCannotDelete( + `${connectedSampleCount} connected Sample`, + ) + } + + await this.diagnosisRepository.deleteById(diagnosis._id) + } } } diff --git a/apps/hcdc-access-service/src/app/doctor/use-case/delete.ts b/apps/hcdc-access-service/src/app/doctor/use-case/delete.ts index 2d384b2a..1b4e8493 100644 --- a/apps/hcdc-access-service/src/app/doctor/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/doctor/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, DoctorAction } from '@diut/hcdc' +import { AuthSubject, Doctor, DoctorAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { ISampleRepository, SAMPLE_REPO_TOKEN, } from 'src/domain' -import { DoctorAssertExistsUseCase } from './assert-exists' +import { DoctorSearchUseCase } from './search' @Injectable() export class DoctorDeleteUseCase { @@ -21,25 +22,28 @@ export class DoctorDeleteUseCase { private readonly doctorRepository: IDoctorRepository, @Inject(SAMPLE_REPO_TOKEN) private readonly sampleRepository: ISampleRepository, - private readonly doctorAssertExistsUseCase: DoctorAssertExistsUseCase, + private readonly doctorSearchUseCase: DoctorSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.doctorAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission(ability, AuthSubject.Doctor, DoctorAction.Delete, entity) - - const connectedSampleCount = await this.sampleRepository.count({ - doctorId: input.id, + const { items: doctors } = await this.doctorSearchUseCase.execute({ + filter: input, }) - if (connectedSampleCount > 0) { - throw new EEntityCannotDelete(`${connectedSampleCount} connected Sample`) - } - await this.doctorRepository.deleteById(input.id) + for (const doctor of doctors) { + assertPermission(ability, AuthSubject.Doctor, DoctorAction.Delete, doctor) - return entity + const connectedSampleCount = await this.sampleRepository.count({ + doctorId: doctor._id, + }) + if (connectedSampleCount > 0) { + throw new EEntityCannotDelete( + `${connectedSampleCount} connected Sample`, + ) + } + + await this.doctorRepository.deleteById(doctor._id) + } } } diff --git a/apps/hcdc-access-service/src/app/instrument/use-case/delete.ts b/apps/hcdc-access-service/src/app/instrument/use-case/delete.ts index 1ff0a393..65992861 100644 --- a/apps/hcdc-access-service/src/app/instrument/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/instrument/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, InstrumentAction } from '@diut/hcdc' +import { AuthSubject, Instrument, InstrumentAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { ITestRepository, TEST_REPO_TOKEN, } from 'src/domain' -import { InstrumentAssertExistsUseCase } from './assert-exists' +import { InstrumentSearchUseCase } from './search' @Injectable() export class InstrumentDeleteUseCase { @@ -21,30 +22,31 @@ export class InstrumentDeleteUseCase { private readonly instrumentRepository: IInstrumentRepository, @Inject(TEST_REPO_TOKEN) private readonly testRepository: ITestRepository, - private readonly instrumentAssertExistsUseCase: InstrumentAssertExistsUseCase, + private readonly instrumentSearchUseCase: InstrumentSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.instrumentAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.Instrument, - InstrumentAction.Delete, - entity, - ) - - const connectedTestCount = await this.testRepository.count({ - instrumentId: input.id, + const { items: instruments } = await this.instrumentSearchUseCase.execute({ + filter: input, }) - if (connectedTestCount > 0) { - throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) - } - await this.instrumentRepository.deleteById(input.id) + for (const instrument of instruments) { + assertPermission( + ability, + AuthSubject.Instrument, + InstrumentAction.Delete, + instrument, + ) - return entity + const connectedTestCount = await this.testRepository.count({ + instrumentId: instrument._id, + }) + if (connectedTestCount > 0) { + throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) + } + + await this.instrumentRepository.deleteById(instrument._id) + } } } diff --git a/apps/hcdc-access-service/src/app/patient-type/use-case/delete.ts b/apps/hcdc-access-service/src/app/patient-type/use-case/delete.ts index c9f8dbd0..22d3bb48 100644 --- a/apps/hcdc-access-service/src/app/patient-type/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/patient-type/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, PatientTypeAction } from '@diut/hcdc' +import { AuthSubject, PatientType, PatientTypeAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { PATIENTTYPE_REPO_TOKEN, SAMPLE_REPO_TOKEN, } from 'src/domain' -import { PatientTypeAssertExistsUseCase } from './assert-exists' +import { PatientTypeSearchUseCase } from './search' @Injectable() export class PatientTypeDeleteUseCase { @@ -21,30 +22,33 @@ export class PatientTypeDeleteUseCase { private readonly patientTypeRepository: IPatientTypeRepository, @Inject(SAMPLE_REPO_TOKEN) private readonly sampleRepository: ISampleRepository, - private readonly patientTypeAssertExistsUseCase: PatientTypeAssertExistsUseCase, + private readonly patientTypeSearchUseCase: PatientTypeSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.patientTypeAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.PatientType, - PatientTypeAction.Delete, - entity, + const { items: patientTypes } = await this.patientTypeSearchUseCase.execute( + { filter: input }, ) - const connectedSampleCount = await this.sampleRepository.count({ - patientTypeId: input.id, - }) - if (connectedSampleCount > 0) { - throw new EEntityCannotDelete(`${connectedSampleCount} connected Sample`) - } + for (const patientType of patientTypes) { + assertPermission( + ability, + AuthSubject.PatientType, + PatientTypeAction.Delete, + patientType, + ) - await this.patientTypeRepository.deleteById(input.id) + const connectedSampleCount = await this.sampleRepository.count({ + patientTypeId: patientType._id, + }) + if (connectedSampleCount > 0) { + throw new EEntityCannotDelete( + `${connectedSampleCount} connected Sample`, + ) + } - return entity + await this.patientTypeRepository.deleteById(patientType._id) + } } } diff --git a/apps/hcdc-access-service/src/app/patient/use-case/delete.ts b/apps/hcdc-access-service/src/app/patient/use-case/delete.ts index 9f68b927..72d3f99b 100644 --- a/apps/hcdc-access-service/src/app/patient/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/patient/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, PatientAction } from '@diut/hcdc' +import { AuthSubject, Patient, PatientAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -7,8 +8,8 @@ import { IPatientRepository, PATIENT_REPO_TOKEN, } from 'src/domain' -import { SampleDeleteManyUseCase } from '../../sample/use-case/delete-many' -import { PatientAssertExistsUseCase } from './assert-exists' +import { SampleDeleteUseCase } from '../../sample/use-case/delete' +import { PatientSearchUseCase } from './search' @Injectable() export class PatientDeleteUseCase { @@ -17,21 +18,27 @@ export class PatientDeleteUseCase { private readonly authContext: IAuthContext, @Inject(PATIENT_REPO_TOKEN) private readonly patientRepository: IPatientRepository, - private readonly patientAssertExistsUseCase: PatientAssertExistsUseCase, - private readonly sampleDeleteManyUseCase: SampleDeleteManyUseCase, + private readonly patientSearchUseCase: PatientSearchUseCase, + private readonly sampleDeleteUseCase: SampleDeleteUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.patientAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission(ability, AuthSubject.Patient, PatientAction.Delete, entity) + const { items: patients } = await this.patientSearchUseCase.execute({ + filter: input, + }) - // TODO: DB transaction - await this.sampleDeleteManyUseCase.execute({ patientId: input.id }) - await this.patientRepository.deleteById(input.id) + for (const patient of patients) { + assertPermission( + ability, + AuthSubject.Patient, + PatientAction.Delete, + patient, + ) - return entity + // TODO: DB transaction + await this.sampleDeleteUseCase.execute({ patientId: patient._id }) + await this.patientRepository.deleteById(patient._id) + } } } diff --git a/apps/hcdc-access-service/src/app/print-form/use-case/delete.ts b/apps/hcdc-access-service/src/app/print-form/use-case/delete.ts index 561081d2..a8383121 100644 --- a/apps/hcdc-access-service/src/app/print-form/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/print-form/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, PrintFormAction } from '@diut/hcdc' +import { AuthSubject, PrintForm, PrintFormAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { PRINTFORM_REPO_TOKEN, TEST_REPO_TOKEN, } from 'src/domain' -import { PrintFormAssertExistsUseCase } from './assert-exists' +import { PrintFormSearchUseCase } from './search' @Injectable() export class PrintFormDeleteUseCase { @@ -21,30 +22,31 @@ export class PrintFormDeleteUseCase { private readonly printFormRepository: IPrintFormRepository, @Inject(TEST_REPO_TOKEN) private readonly testRepository: ITestRepository, - private readonly printFormAssertExistsUseCase: PrintFormAssertExistsUseCase, + private readonly printFormSearchUseCase: PrintFormSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.printFormAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.PrintForm, - PrintFormAction.Delete, - entity, - ) - - const connectedTestCount = await this.testRepository.count({ - printFormIds: input.id, + const { items: printForms } = await this.printFormSearchUseCase.execute({ + filter: input, }) - if (connectedTestCount > 0) { - throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) - } - await this.printFormRepository.deleteById(input.id) + for (const printForm of printForms) { + assertPermission( + ability, + AuthSubject.PrintForm, + PrintFormAction.Delete, + printForm, + ) - return entity + const connectedTestCount = await this.testRepository.count({ + printFormIds: { $elemMatch: { $eq: printForm._id } }, + }) + if (connectedTestCount > 0) { + throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) + } + + await this.printFormRepository.deleteById(printForm._id) + } } } diff --git a/apps/hcdc-access-service/src/app/role/use-case/delete.ts b/apps/hcdc-access-service/src/app/role/use-case/delete.ts index 15664250..b8ea8e59 100644 --- a/apps/hcdc-access-service/src/app/role/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/role/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, RoleAction } from '@diut/hcdc' +import { AuthSubject, Role, RoleAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { ROLE_REPO_TOKEN, USER_REPO_TOKEN, } from 'src/domain' -import { RoleAssertExistsUseCase } from './assert-exists' +import { RoleSearchUseCase } from './search' @Injectable() export class RoleDeleteUseCase { @@ -21,25 +22,26 @@ export class RoleDeleteUseCase { private readonly roleRepository: IRoleRepository, @Inject(USER_REPO_TOKEN) private readonly userRepository: IUserRepository, - private readonly roleAssertExistsUseCase: RoleAssertExistsUseCase, + private readonly roleSearchUseCase: RoleSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.roleAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission(ability, AuthSubject.Role, RoleAction.Delete, entity) - - const connectedUserCount = await this.userRepository.count({ - roleIds: { $elemMatch: { $eq: input.id } }, + const { items: roles } = await this.roleSearchUseCase.execute({ + filter: input, }) - if (connectedUserCount > 0) { - throw new EEntityCannotDelete(`${connectedUserCount} connected User`) - } - await this.roleRepository.deleteById(input.id) + for (const role of roles) { + assertPermission(ability, AuthSubject.Role, RoleAction.Delete, role) - return entity + const connectedUserCount = await this.userRepository.count({ + roleIds: { $elemMatch: { $eq: role._id } }, + }) + if (connectedUserCount > 0) { + throw new EEntityCannotDelete(`${connectedUserCount} connected User`) + } + + await this.roleRepository.deleteById(role._id) + } } } diff --git a/apps/hcdc-access-service/src/app/sample-type/use-case/delete.ts b/apps/hcdc-access-service/src/app/sample-type/use-case/delete.ts index f869013c..0dd75dc0 100644 --- a/apps/hcdc-access-service/src/app/sample-type/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/sample-type/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, SampleTypeAction } from '@diut/hcdc' +import { AuthSubject, SampleType, SampleTypeAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -12,7 +13,7 @@ import { SAMPLE_REPO_TOKEN, TEST_REPO_TOKEN, } from 'src/domain' -import { SampleTypeAssertExistsUseCase } from './assert-exists' +import { SampleTypeSearchUseCase } from './search' @Injectable() export class SampleTypeDeleteUseCase { @@ -25,37 +26,40 @@ export class SampleTypeDeleteUseCase { private readonly testRepository: ITestRepository, @Inject(SAMPLE_REPO_TOKEN) private readonly sampleRepository: ISampleRepository, - private readonly sampleTypeAssertExistsUseCase: SampleTypeAssertExistsUseCase, + private readonly sampleTypeSearchUseCase: SampleTypeSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.sampleTypeAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.SampleType, - SampleTypeAction.Delete, - entity, - ) - - const connectedSampleCount = await this.sampleRepository.count({ - diagnosisId: input.id, + const { items: sampleTypes } = await this.sampleTypeSearchUseCase.execute({ + filter: input, }) - if (connectedSampleCount > 0) { - throw new EEntityCannotDelete(`${connectedSampleCount} connected Sample`) - } - const connectedTestCount = await this.testRepository.count({ - bioProductId: input.id, - }) - if (connectedTestCount > 0) { - throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) - } + for (const sampleType of sampleTypes) { + assertPermission( + ability, + AuthSubject.SampleType, + SampleTypeAction.Delete, + sampleType, + ) + + const connectedSampleCount = await this.sampleRepository.count({ + sampleTypeIds: sampleType._id, + }) + if (connectedSampleCount > 0) { + throw new EEntityCannotDelete( + `${connectedSampleCount} connected Sample`, + ) + } - await this.sampleTypeRepository.deleteById(input.id) + const connectedTestCount = await this.testRepository.count({ + sampleTypeId: sampleType._id, + }) + if (connectedTestCount > 0) { + throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) + } - return entity + await this.sampleTypeRepository.deleteById(sampleType._id) + } } } diff --git a/apps/hcdc-access-service/src/app/sample/module.ts b/apps/hcdc-access-service/src/app/sample/module.ts index 59073d8d..09e657a5 100644 --- a/apps/hcdc-access-service/src/app/sample/module.ts +++ b/apps/hcdc-access-service/src/app/sample/module.ts @@ -3,7 +3,6 @@ import { SampleAssertExistsUseCase } from './use-case/assert-exists' import { SampleAuthorizePopulatesUseCase } from './use-case/authorize-populates' import { SampleCreateUseCase } from './use-case/create' import { SampleDeleteUseCase } from './use-case/delete' -import { SampleDeleteManyUseCase } from './use-case/delete-many' import { SampleDownloadResultImageUseCase } from './use-case/download-result-image' import { SampleFindOneUseCase } from './use-case/find-one' import { SampleGeneratePrintUrlUseCase } from './use-case/generate-print-url' @@ -27,7 +26,6 @@ export const sampleMetadata: ModuleMetadata = { SampleUpdateInfoUseCase, SampleUpdateResultUseCase, SampleDeleteUseCase, - SampleDeleteManyUseCase, SampleSearchUseCase, SampleAssertExistsUseCase, SampleValidateUseCase, diff --git a/apps/hcdc-access-service/src/app/sample/use-case/delete-many.ts b/apps/hcdc-access-service/src/app/sample/use-case/delete-many.ts deleted file mode 100644 index 08a85b29..00000000 --- a/apps/hcdc-access-service/src/app/sample/use-case/delete-many.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Sample } from '@diut/hcdc' -import { Injectable } from '@nestjs/common' -import { FilterQuery } from 'mongoose' -import { SampleDeleteUseCase } from './delete' -import { SampleSearchUseCase } from './search' - -@Injectable() -export class SampleDeleteManyUseCase { - constructor( - private readonly sampleSearchUseCase: SampleSearchUseCase, - private readonly sampleDeleteUseCase: SampleDeleteUseCase, - ) {} - - async execute(input: FilterQuery) { - const samples = await this.sampleSearchUseCase.execute({ filter: input }) - - for (const sample of samples.items) { - await this.sampleDeleteUseCase.execute({ id: sample._id }) - } - } -} diff --git a/apps/hcdc-access-service/src/app/sample/use-case/delete.ts b/apps/hcdc-access-service/src/app/sample/use-case/delete.ts index c28bf051..151784b8 100644 --- a/apps/hcdc-access-service/src/app/sample/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/sample/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, SampleAction } from '@diut/hcdc' +import { AuthSubject, Sample, SampleAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -13,7 +14,7 @@ import { StorageBucket, StorageKeyFactory, } from 'src/domain' -import { SampleAssertExistsUseCase } from './assert-exists' +import { SampleSearchUseCase } from './search' @Injectable() export class SampleDeleteUseCase { @@ -22,28 +23,29 @@ export class SampleDeleteUseCase { private readonly authContext: IAuthContext, @Inject(SAMPLE_REPO_TOKEN) private readonly sampleRepository: ISampleRepository, - private readonly sampleAssertExistsUseCase: SampleAssertExistsUseCase, + private readonly sampleSearchUseCase: SampleSearchUseCase, @Inject(STORAGE_SERVICE_TOKEN) private readonly storageService: IStorageService, @Inject(STORAGE_BUCKET_TOKEN) private readonly storageBucket: IStorageBucket, ) {} - async execute(input: { id: string }) { - const entity = await this.sampleAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission(ability, AuthSubject.Sample, SampleAction.Delete, entity) - - await this.storageService.deleteKeysMatch({ - bucket: this.storageBucket.get(StorageBucket.SAMPLE_IMAGES), - prefix: StorageKeyFactory[StorageBucket.SAMPLE_IMAGES].resultImage({ - sampleId: input.id, - }), + const { items: samples } = await this.sampleSearchUseCase.execute({ + filter: input, }) - await this.sampleRepository.deleteById(input.id) - return entity + for (const sample of samples) { + assertPermission(ability, AuthSubject.Sample, SampleAction.Delete, sample) + + await this.storageService.deleteKeysMatch({ + bucket: this.storageBucket.get(StorageBucket.SAMPLE_IMAGES), + prefix: StorageKeyFactory[StorageBucket.SAMPLE_IMAGES].resultImage({ + sampleId: sample._id, + }), + }) + await this.sampleRepository.deleteById(sample._id) + } } } diff --git a/apps/hcdc-access-service/src/app/test-category/use-case/delete.ts b/apps/hcdc-access-service/src/app/test-category/use-case/delete.ts index 8ec7784b..bfeb6d24 100644 --- a/apps/hcdc-access-service/src/app/test-category/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/test-category/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, TestCategoryAction } from '@diut/hcdc' +import { AuthSubject, TestCategory, TestCategoryAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -10,7 +11,7 @@ import { TESTCATEGORY_REPO_TOKEN, TEST_REPO_TOKEN, } from 'src/domain' -import { TestCategoryAssertExistsUseCase } from './assert-exists' +import { TestCategorySearchUseCase } from './search' @Injectable() export class TestCategoryDeleteUseCase { @@ -21,30 +22,30 @@ export class TestCategoryDeleteUseCase { private readonly testCategoryRepository: ITestCategoryRepository, @Inject(TEST_REPO_TOKEN) private readonly testRepository: ITestRepository, - private readonly testCategoryAssertExistsUseCase: TestCategoryAssertExistsUseCase, + private readonly testCategorySearchUseCase: TestCategorySearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.testCategoryAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.TestCategory, - TestCategoryAction.Delete, - entity, - ) + const { items: testCategories } = + await this.testCategorySearchUseCase.execute({ filter: input }) - const connectedTestCount = await this.testRepository.count({ - testCategoryId: input.id, - }) - if (connectedTestCount > 0) { - throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) - } + for (const testCategory of testCategories) { + assertPermission( + ability, + AuthSubject.TestCategory, + TestCategoryAction.Delete, + testCategory, + ) - await this.testCategoryRepository.deleteById(input.id) + const connectedTestCount = await this.testRepository.count({ + testCategoryId: testCategory._id, + }) + if (connectedTestCount > 0) { + throw new EEntityCannotDelete(`${connectedTestCount} connected Test`) + } - return entity + await this.testCategoryRepository.deleteById(testCategory._id) + } } } diff --git a/apps/hcdc-access-service/src/app/test-combo/use-case/delete.ts b/apps/hcdc-access-service/src/app/test-combo/use-case/delete.ts index dc550f53..7568502c 100644 --- a/apps/hcdc-access-service/src/app/test-combo/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/test-combo/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, TestComboAction } from '@diut/hcdc' +import { AuthSubject, TestCombo, TestComboAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -7,7 +8,7 @@ import { ITestComboRepository, TESTCOMBO_REPO_TOKEN, } from 'src/domain' -import { TestComboAssertExistsUseCase } from './assert-exists' +import { TestComboSearchUseCase } from './search' @Injectable() export class TestComboDeleteUseCase { @@ -16,23 +17,24 @@ export class TestComboDeleteUseCase { private readonly authContext: IAuthContext, @Inject(TESTCOMBO_REPO_TOKEN) private readonly testComboRepository: ITestComboRepository, - private readonly testComboAssertExistsUseCase: TestComboAssertExistsUseCase, + private readonly testComboSearchUseCase: TestComboSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.testComboAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.TestCombo, - TestComboAction.Delete, - entity, - ) + const { items: testCombos } = await this.testComboSearchUseCase.execute({ + filter: input, + }) - await this.testComboRepository.deleteById(input.id) + for (const testCombo of testCombos) { + assertPermission( + ability, + AuthSubject.TestCombo, + TestComboAction.Delete, + testCombo, + ) - return entity + await this.testComboRepository.deleteById(testCombo._id) + } } } diff --git a/apps/hcdc-access-service/src/app/test-combo/use-case/update.ts b/apps/hcdc-access-service/src/app/test-combo/use-case/update.ts index 9796597a..31b7afde 100644 --- a/apps/hcdc-access-service/src/app/test-combo/use-case/update.ts +++ b/apps/hcdc-access-service/src/app/test-combo/use-case/update.ts @@ -7,7 +7,7 @@ import { ITestComboRepository, TESTCOMBO_REPO_TOKEN, } from 'src/domain' -import { TestComboAssertExistsUseCase } from './assert-exists' +import { TestComboSearchUseCase } from './search' import { TestComboValidateUseCase } from './validate' @Injectable() @@ -17,21 +17,31 @@ export class TestComboUpdateUseCase { private readonly testComboRepository: ITestComboRepository, @Inject(AUTH_CONTEXT_TOKEN) private readonly authContext: IAuthContext, - private readonly testComboAssertExistsUseCase: TestComboAssertExistsUseCase, + private readonly testComboSearchUseCase: TestComboSearchUseCase, private readonly testComboValidateUseCase: TestComboValidateUseCase, ) {} async execute(...input: Parameters) { - const entity = await this.testComboAssertExistsUseCase.execute(input[0]) const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.TestCombo, - TestComboAction.Update, - entity, + const { items: testCombos } = await this.testComboSearchUseCase.execute( + input[0], ) await this.testComboValidateUseCase.execute(input[1]) - return this.testComboRepository.update(...input) + for (const testCombo of testCombos) { + assertPermission( + ability, + AuthSubject.TestCombo, + TestComboAction.Update, + testCombo, + ) + + await this.testComboRepository.update( + { _id: testCombo._id }, + input[1], + input?.[2], + input?.[3], + ) + } } } diff --git a/apps/hcdc-access-service/src/app/test-element/use-case/delete.ts b/apps/hcdc-access-service/src/app/test-element/use-case/delete.ts index 922bb7db..8e0075b4 100644 --- a/apps/hcdc-access-service/src/app/test-element/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/test-element/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, TestElementAction } from '@diut/hcdc' +import { AuthSubject, TestElement, TestElementAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -7,7 +8,7 @@ import { ITestElementRepository, TESTELEMENT_REPO_TOKEN, } from 'src/domain' -import { TestElementAssertExistsUseCase } from './assert-exists' +import { TestElementSearchUseCase } from './search' @Injectable() export class TestElementDeleteUseCase { @@ -16,23 +17,24 @@ export class TestElementDeleteUseCase { private readonly authContext: IAuthContext, @Inject(TESTELEMENT_REPO_TOKEN) private readonly testElementRepository: ITestElementRepository, - private readonly testElementAssertExistsUseCase: TestElementAssertExistsUseCase, + private readonly testElementSearchUseCase: TestElementSearchUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.testElementAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission( - ability, - AuthSubject.TestElement, - TestElementAction.Delete, - entity, + const { items: testElements } = await this.testElementSearchUseCase.execute( + { filter: input }, ) - await this.testElementRepository.deleteById(input.id) + for (const testElement of testElements) { + assertPermission( + ability, + AuthSubject.TestElement, + TestElementAction.Delete, + testElement, + ) - return entity + await this.testElementRepository.deleteById(testElement._id) + } } } diff --git a/apps/hcdc-access-service/src/app/test/use-case/delete.ts b/apps/hcdc-access-service/src/app/test/use-case/delete.ts index b6476056..01e6234e 100644 --- a/apps/hcdc-access-service/src/app/test/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/test/use-case/delete.ts @@ -1,16 +1,18 @@ -import { AuthSubject, TestAction } from '@diut/hcdc' +import { AuthSubject, Test, TestAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' +import { BioProductDeleteUseCase } from 'src/app/bio-product/use-case/delete' +import { InstrumentDeleteUseCase } from 'src/app/instrument/use-case/delete' +import { TestComboUpdateUseCase } from 'src/app/test-combo/use-case/update' +import { TestElementDeleteUseCase } from 'src/app/test-element/use-case/delete' import { AUTH_CONTEXT_TOKEN, - EEntityCannotDelete, IAuthContext, - ITestElementRepository, ITestRepository, - TESTELEMENT_REPO_TOKEN, TEST_REPO_TOKEN, } from 'src/domain' -import { TestAssertExistsUseCase } from './assert-exists' +import { TestSearchUseCase } from './search' @Injectable() export class TestDeleteUseCase { @@ -19,29 +21,42 @@ export class TestDeleteUseCase { private readonly authContext: IAuthContext, @Inject(TEST_REPO_TOKEN) private readonly testRepository: ITestRepository, - @Inject(TESTELEMENT_REPO_TOKEN) - private readonly testElementRepository: ITestElementRepository, - private readonly testAssertExistsUseCase: TestAssertExistsUseCase, + private readonly testSearchUseCase: TestSearchUseCase, + private readonly testElementDeleteUseCase: TestElementDeleteUseCase, + private readonly bioProductDeleteUseCase: BioProductDeleteUseCase, + private readonly instrumentDeleteUseCase: InstrumentDeleteUseCase, + private readonly testComboUpdateUseCase: TestComboUpdateUseCase, ) {} - async execute(input: { id: string }) { - const entity = await this.testAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const { ability } = this.authContext.getData() - assertPermission(ability, AuthSubject.Test, TestAction.Delete, entity) - - const connectedElementCount = await this.testElementRepository.count({ - testId: input.id, + const { items: tests } = await this.testSearchUseCase.execute({ + filter: input, }) - if (connectedElementCount > 0) { - throw new EEntityCannotDelete( - `${connectedElementCount} connected TestElement`, - ) - } - await this.testRepository.deleteById(input.id) + for (const test of tests) { + assertPermission(ability, AuthSubject.Test, TestAction.Delete, test) - return entity + await this.testElementDeleteUseCase.execute({ + testId: test._id, + }) + await this.bioProductDeleteUseCase.execute({ + testId: test._id, + }) + await this.instrumentDeleteUseCase.execute({ + testId: test._id, + }) + + await this.testComboUpdateUseCase.execute( + { + testIds: { $elemMatch: { $eq: test._id } }, + }, + { + $pull: { testIds: test._id }, + }, + ) + + await this.testRepository.deleteById(test._id) + } } } diff --git a/apps/hcdc-access-service/src/app/user/use-case/delete.ts b/apps/hcdc-access-service/src/app/user/use-case/delete.ts index 68dc549d..388c73dc 100644 --- a/apps/hcdc-access-service/src/app/user/use-case/delete.ts +++ b/apps/hcdc-access-service/src/app/user/use-case/delete.ts @@ -1,5 +1,6 @@ -import { AuthSubject, UserAction } from '@diut/hcdc' +import { AuthSubject, User, UserAction } from '@diut/hcdc' import { Inject, Injectable } from '@nestjs/common' +import { FilterQuery } from 'mongoose' import { assertPermission } from 'src/app/auth/common' import { AUTH_CONTEXT_TOKEN, @@ -11,7 +12,7 @@ import { IUserRepository, USER_REPO_TOKEN, } from 'src/domain' -import { UserAssertExistsUseCase } from './assert-exists' +import { UserSearchUseCase } from './search' @Injectable() export class UserDeleteUseCase { @@ -20,29 +21,31 @@ export class UserDeleteUseCase { private readonly authContext: IAuthContext, @Inject(USER_REPO_TOKEN) private readonly userRepository: IUserRepository, - private readonly userAssertExistsUseCase: UserAssertExistsUseCase, + private readonly userSearchUseCase: UserSearchUseCase, @Inject(AUTH_SERVICE_TOKEN) private readonly authService: IAuthService, ) {} - async execute(input: { id: string }) { - const entity = await this.userAssertExistsUseCase.execute({ - _id: input.id, - }) + async execute(input: FilterQuery) { const authContext = this.authContext.getData() - assertPermission( - authContext.ability, - AuthSubject.User, - UserAction.Delete, - entity, - ) + const { items: users } = await this.userSearchUseCase.execute({ + filter: input, + }) + + for (const user of users) { + assertPermission( + authContext.ability, + AuthSubject.User, + UserAction.Delete, + user, + ) - await this.userRepository.deleteById(input.id) - await this.authService.invalidate({ - type: AuthType.Internal, - user: { _id: entity._id }, - } as AuthContextData) + await this.userRepository.deleteById(input.id) - return entity + await this.authService.invalidate({ + type: AuthType.Internal, + user: { _id: user._id }, + } as AuthContextData) + } } } diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/bio-product.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/bio-product.ts index 244d0038..ba372854 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/bio-product.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/bio-product.ts @@ -12,11 +12,9 @@ export const exampleBioProduct = { testId: exampleMongoObjectId, test: { required: false, - nullable: true, }, branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/diagnosis.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/diagnosis.ts index 9a513340..219ac25b 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/diagnosis.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/diagnosis.ts @@ -12,6 +12,5 @@ export const exampleDiagnosis = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/doctor.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/doctor.ts index 2d97a1fc..4f34f481 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/doctor.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/doctor.ts @@ -12,6 +12,5 @@ export const exampleDoctor = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/instrument.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/instrument.ts index 8f40af5e..881abfdf 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/instrument.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/instrument.ts @@ -12,11 +12,9 @@ export const exampleInstrument = { testId: exampleMongoObjectId, test: { required: false, - nullable: true, }, branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/patient-type.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/patient-type.ts index 176b01f8..3f81bf56 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/patient-type.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/patient-type.ts @@ -12,6 +12,5 @@ export const examplePatientType = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/patient.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/patient.ts index 1c47f236..4610de98 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/patient.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/patient.ts @@ -27,6 +27,5 @@ export const examplePatient = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/print-form.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/print-form.ts index 57f47407..65a52168 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/print-form.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/print-form.ts @@ -24,6 +24,5 @@ export const examplePrintForm = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/role.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/role.ts index 34ac723f..d9d49702 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/role.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/role.ts @@ -18,6 +18,5 @@ export const exampleRole = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/sample-type.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/sample-type.ts index 599f5886..c2e726de 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/sample-type.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/sample-type.ts @@ -12,6 +12,5 @@ export const exampleSampleType = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/sample.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/sample.ts index fe13c5dc..1f37338a 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/sample.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/sample.ts @@ -78,27 +78,22 @@ export const exampleSample = { patientId: exampleMongoObjectId, patient: { required: false, - nullable: true, }, doctorId: exampleMongoObjectId, doctor: { required: false, - nullable: true, }, patientTypeId: exampleMongoObjectId, patientType: { required: false, - nullable: true, }, diagnosisId: exampleMongoObjectId, diagnosis: { required: false, - nullable: true, }, originId: exampleMongoObjectId, origin: { required: false, - nullable: true, }, sampleTypeIds: exampleMongoObjectIds, sampleTypes: { @@ -108,6 +103,5 @@ export const exampleSample = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/test-category.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/test-category.ts index 72237fc6..7b37fe32 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/test-category.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/test-category.ts @@ -15,6 +15,5 @@ export const exampleTestCategory = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/test-combo.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/test-combo.ts index 50d8c38b..a30e42d5 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/test-combo.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/test-combo.ts @@ -17,6 +17,5 @@ export const exampleTestCombo = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/test-element.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/test-element.ts index 756254e5..cdd9ef9f 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/test-element.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/test-element.ts @@ -57,6 +57,5 @@ export const exampleTestElement = { branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/shared/entity/test.ts b/apps/hcdc-access-service/src/controller/http/shared/entity/test.ts index e443b89d..67a05175 100644 --- a/apps/hcdc-access-service/src/controller/http/shared/entity/test.ts +++ b/apps/hcdc-access-service/src/controller/http/shared/entity/test.ts @@ -13,31 +13,25 @@ export const exampleTest = { bioProductId: { ...exampleMongoObjectId, nullable: true }, bioProduct: { required: false, - nullable: true, }, instrumentId: { ...exampleMongoObjectId, nullable: true }, instrument: { required: false, - nullable: true, }, sampleTypeId: { ...exampleMongoObjectId, nullable: true }, sampleType: { required: false, - nullable: true, }, testCategoryId: exampleMongoObjectId, testCategory: { required: false, - nullable: true, }, printFormIds: exampleMongoObjectIds, printForms: { required: false, - isArray: true, }, branchId: exampleMongoObjectId, branch: { required: false, - nullable: true, }, } satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/controller/http/v1/bio-product/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/bio-product/dto/response-dto.ts index 438e2167..7ac09c56 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/bio-product/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/bio-product/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -20,9 +20,8 @@ export class BioProductResponseDto extends BioProductUnpopulatedResponseDto { }) @ValidateNested() @Type(() => TestUnpopulatedResponseDto) - @IsNullable() @IsOptional() - test?: TestUnpopulatedResponseDto | null + test?: TestUnpopulatedResponseDto @Expose() @ApiProperty({ @@ -31,7 +30,6 @@ export class BioProductResponseDto extends BioProductUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/branch/dto/request-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/branch/dto/request-dto.ts index 9cbe13fa..0a1c4986 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/branch/dto/request-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/branch/dto/request-dto.ts @@ -7,6 +7,7 @@ import { IsEnum, IsNotEmpty, IsNumber, + IsObject, IsString, Min, } from 'class-validator' @@ -38,7 +39,7 @@ export class BranchRequestDto { @Expose() @ApiProperty(exampleBranch.reportConfig) - @IsNotEmpty() + @IsObject() reportConfig: BranchReportConfig @Expose() diff --git a/apps/hcdc-access-service/src/controller/http/v1/diagnosis/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/diagnosis/dto/response-dto.ts index 12f7429a..aa26fa83 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/diagnosis/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/diagnosis/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class DiagnosisResponseDto extends DiagnosisUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/doctor/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/doctor/dto/response-dto.ts index 89d2c931..3d0df97c 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/doctor/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/doctor/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class DoctorResponseDto extends DoctorUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/instrument/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/instrument/dto/response-dto.ts index 2580cfd5..a400962b 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/instrument/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/instrument/dto/response-dto.ts @@ -31,7 +31,6 @@ export class InstrumentResponseDto extends InstrumentUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/patient-type/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/patient-type/dto/response-dto.ts index cd93e85a..a81e2388 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/patient-type/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/patient-type/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class PatientTypeResponseDto extends PatientTypeUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/patient/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/patient/dto/response-dto.ts index 3626cfbc..e4218f19 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/patient/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/patient/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class PatientResponseDto extends PatientUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/print-form/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/print-form/dto/response-dto.ts index cee920cb..49ca986c 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/print-form/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/print-form/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class PrintFormResponseDto extends PrintFormUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/role/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/role/dto/response-dto.ts index a6c5f220..1ec2fffe 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/role/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/role/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class RoleResponseDto extends RoleUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/sample-type/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/sample-type/dto/response-dto.ts index fe8d07e5..98513013 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/sample-type/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/sample-type/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class SampleTypeResponseDto extends SampleTypeUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/sample/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/sample/dto/response-dto.ts index bf56ae7d..c7ab1082 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/sample/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/sample/dto/response-dto.ts @@ -127,9 +127,8 @@ export class SampleResponseDto extends SampleUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } export class OmittedSampleResponseDto extends OmitType(SampleResponseDto, [ diff --git a/apps/hcdc-access-service/src/controller/http/v1/test-category/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/test-category/dto/response-dto.ts index 58b4a81a..e74105e9 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/test-category/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/test-category/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsOptional, ValidateNested } from 'class-validator' @@ -19,7 +19,6 @@ export class TestCategoryResponseDto extends TestCategoryUnpopulatedResponseDto }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/test-combo/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/test-combo/dto/response-dto.ts index 1e42e039..93107087 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/test-combo/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/test-combo/dto/response-dto.ts @@ -1,4 +1,4 @@ -import { BaseResourceResponseDto, IsNullable } from '@diut/nestjs-infra' +import { BaseResourceResponseDto } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType } from '@nestjs/swagger' import { Expose, Type } from 'class-transformer' import { IsArray, IsOptional, ValidateNested } from 'class-validator' @@ -31,7 +31,6 @@ export class TestComboResponseDto extends TestComboUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/test-element/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/test-element/dto/response-dto.ts index 30c33dbb..ca1f4b0c 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/test-element/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/test-element/dto/response-dto.ts @@ -31,7 +31,6 @@ export class TestElementResponseDto extends TestElementUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/controller/http/v1/test/dto/response-dto.ts b/apps/hcdc-access-service/src/controller/http/v1/test/dto/response-dto.ts index b7a97fd8..da730c4c 100644 --- a/apps/hcdc-access-service/src/controller/http/v1/test/dto/response-dto.ts +++ b/apps/hcdc-access-service/src/controller/http/v1/test/dto/response-dto.ts @@ -80,7 +80,6 @@ export class TestResponseDto extends TestUnpopulatedResponseDto { }) @ValidateNested() @Type(() => BranchUnpopulatedResponseDto) - @IsNullable() @IsOptional() - branch?: BranchUnpopulatedResponseDto | null + branch?: BranchUnpopulatedResponseDto } diff --git a/apps/hcdc-access-service/src/infra/mongo/bio-product/schema.ts b/apps/hcdc-access-service/src/infra/mongo/bio-product/schema.ts index aefaa449..74cd4f47 100644 --- a/apps/hcdc-access-service/src/infra/mongo/bio-product/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/bio-product/schema.ts @@ -36,9 +36,9 @@ export class BioProductSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) testId: string - test?: TestSchema | null + test?: TestSchema @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/branch/schema.ts b/apps/hcdc-access-service/src/infra/mongo/branch/schema.ts index 1064364f..cb76ae5c 100644 --- a/apps/hcdc-access-service/src/infra/mongo/branch/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/branch/schema.ts @@ -36,5 +36,5 @@ export class BranchSchema extends BaseSchema { @Prop({ required: true, type: [Types.ObjectId] }) sampleOriginIds: string[] - sampleOrigins?: (BranchSchema | null)[] + sampleOrigins?: BranchSchema[] } diff --git a/apps/hcdc-access-service/src/infra/mongo/diagnosis/schema.ts b/apps/hcdc-access-service/src/infra/mongo/diagnosis/schema.ts index 4328b7f9..e92b57fd 100644 --- a/apps/hcdc-access-service/src/infra/mongo/diagnosis/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/diagnosis/schema.ts @@ -27,5 +27,5 @@ export class DiagnosisSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/doctor/schema.ts b/apps/hcdc-access-service/src/infra/mongo/doctor/schema.ts index 69211697..7f5fcfcd 100644 --- a/apps/hcdc-access-service/src/infra/mongo/doctor/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/doctor/schema.ts @@ -27,5 +27,5 @@ export class DoctorSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/instrument/schema.ts b/apps/hcdc-access-service/src/infra/mongo/instrument/schema.ts index b07bce00..4fd58d9d 100644 --- a/apps/hcdc-access-service/src/infra/mongo/instrument/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/instrument/schema.ts @@ -36,9 +36,9 @@ export class InstrumentSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) testId: string - test?: TestSchema | null + test?: TestSchema @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/patient-type/schema.ts b/apps/hcdc-access-service/src/infra/mongo/patient-type/schema.ts index c81c860f..123e665f 100644 --- a/apps/hcdc-access-service/src/infra/mongo/patient-type/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/patient-type/schema.ts @@ -27,5 +27,5 @@ export class PatientTypeSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/patient/schema.ts b/apps/hcdc-access-service/src/infra/mongo/patient/schema.ts index ee2f672f..64456e92 100644 --- a/apps/hcdc-access-service/src/infra/mongo/patient/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/patient/schema.ts @@ -43,5 +43,5 @@ export class PatientSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/print-form/schema.ts b/apps/hcdc-access-service/src/infra/mongo/print-form/schema.ts index dac5439f..e901ef52 100644 --- a/apps/hcdc-access-service/src/infra/mongo/print-form/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/print-form/schema.ts @@ -46,5 +46,5 @@ export class PrintFormSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/role/schema.ts b/apps/hcdc-access-service/src/infra/mongo/role/schema.ts index 62110e29..421d3644 100644 --- a/apps/hcdc-access-service/src/infra/mongo/role/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/role/schema.ts @@ -38,5 +38,5 @@ export class RoleSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/sample-type/schema.ts b/apps/hcdc-access-service/src/infra/mongo/sample-type/schema.ts index 8bffa837..00756b72 100644 --- a/apps/hcdc-access-service/src/infra/mongo/sample-type/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/sample-type/schema.ts @@ -27,5 +27,5 @@ export class SampleTypeSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/sample/schema.ts b/apps/hcdc-access-service/src/infra/mongo/sample/schema.ts index 4766c9cd..8e8bf2b5 100644 --- a/apps/hcdc-access-service/src/infra/mongo/sample/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/sample/schema.ts @@ -218,29 +218,29 @@ export class SampleSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) patientId: string - patient?: PatientSchema | null + patient?: PatientSchema @Prop({ required: true, type: Types.ObjectId }) doctorId: string - doctor?: DoctorSchema | null + doctor?: DoctorSchema @Prop({ required: true, type: Types.ObjectId }) patientTypeId: string - patientType?: PatientTypeSchema | null + patientType?: PatientTypeSchema @Prop({ required: true, type: Types.ObjectId }) diagnosisId: string - diagnosis?: DiagnosisSchema | null + diagnosis?: DiagnosisSchema @Prop({ required: true, type: Types.ObjectId }) originId: string - origin?: BranchSchema | null + origin?: BranchSchema @Prop({ required: true, type: [Types.ObjectId] }) sampleTypeIds: string[] - sampleTypes?: (SampleTypeSchema | null)[] + sampleTypes?: SampleTypeSchema[] @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/test-category/schema.ts b/apps/hcdc-access-service/src/infra/mongo/test-category/schema.ts index 8ec67b01..876dbc51 100644 --- a/apps/hcdc-access-service/src/infra/mongo/test-category/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/test-category/schema.ts @@ -30,5 +30,5 @@ export class TestCategorySchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/test-combo/schema.ts b/apps/hcdc-access-service/src/infra/mongo/test-combo/schema.ts index f57d5bd4..c08dafc0 100644 --- a/apps/hcdc-access-service/src/infra/mongo/test-combo/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/test-combo/schema.ts @@ -36,9 +36,9 @@ export class TestComboSchema extends BaseSchema { @Prop({ required: true, type: [Types.ObjectId] }) testIds: string[] - tests?: (TestSchema | null)[] + tests?: TestSchema[] @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/test-element/schema.ts b/apps/hcdc-access-service/src/infra/mongo/test-element/schema.ts index 7b9c02ed..f5e493bb 100644 --- a/apps/hcdc-access-service/src/infra/mongo/test-element/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/test-element/schema.ts @@ -83,5 +83,5 @@ export class TestElementSchema extends BaseSchema { @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/test/schema.ts b/apps/hcdc-access-service/src/infra/mongo/test/schema.ts index ee91a2f8..bee52a8e 100644 --- a/apps/hcdc-access-service/src/infra/mongo/test/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/test/schema.ts @@ -75,25 +75,25 @@ export class TestSchema extends BaseSchema { @Prop({ required: false, type: Types.ObjectId }) bioProductId: string | null - bioProduct?: BioProductSchema | null + bioProduct?: BioProductSchema @Prop({ required: false, type: Types.ObjectId }) instrumentId: string | null - instrument?: InstrumentSchema | null + instrument?: InstrumentSchema @Prop({ required: false, type: Types.ObjectId }) sampleTypeId: string | null - sampleType?: SampleTypeSchema | null + sampleType?: SampleTypeSchema @Prop({ required: true, type: Types.ObjectId }) testCategoryId: string - testCategory?: TestCategorySchema | null + testCategory?: TestCategorySchema @Prop({ required: false, type: Types.ObjectId }) printFormIds: string[] - printForms?: (PrintFormSchema | null)[] + printForms?: PrintFormSchema[] @Prop({ required: true, type: Types.ObjectId }) branchId: string - branch?: BranchSchema | null + branch?: BranchSchema } diff --git a/apps/hcdc-access-service/src/infra/mongo/user/schema.ts b/apps/hcdc-access-service/src/infra/mongo/user/schema.ts index 592d7a5c..72b74fcb 100644 --- a/apps/hcdc-access-service/src/infra/mongo/user/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/user/schema.ts @@ -50,9 +50,9 @@ export class UserSchema extends BaseSchema { @Prop({ required: true, type: [Types.ObjectId] }) branchIds: string[] - branches?: (BranchSchema | null)[] + branches?: BranchSchema[] @Prop({ required: true, type: [Types.ObjectId] }) roleIds: string[] - roles?: (RoleSchema | null)[] + roles?: RoleSchema[] } diff --git a/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx b/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx index c4af1fe9..80a2eb34 100644 --- a/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx +++ b/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx @@ -85,20 +85,22 @@ export function AppBar({ drawerWidth }: AppBarProps) { } }} > - {branches?.map((branch) => ( - - {branch.name} - - ))} + {branches + ?.toSorted((a, b) => a.displayIndex - b.displayIndex) + .map((branch) => ( + + {branch.name} + + ))} ({ }} cellOutline loading={isLoading} - paginationMode={rowCount != undefined ? 'server' : undefined} + paginationMode={ + rowCount != undefined + ? 'server' + : page !== undefined + ? 'client' + : undefined + } rowCount={rowCount} page={page} onPageChange={onPageChange} diff --git a/apps/hcdc-web-app/src/features/auth/state/slice.ts b/apps/hcdc-web-app/src/features/auth/state/slice.ts index 68f5d6f5..f7ce8de6 100644 --- a/apps/hcdc-web-app/src/features/auth/state/slice.ts +++ b/apps/hcdc-web-app/src/features/auth/state/slice.ts @@ -3,6 +3,7 @@ import { createSlice } from '@reduxjs/toolkit' import { persistReducer } from 'redux-persist' import storage from 'redux-persist/lib/storage' import { authApi } from 'src/infra/api/access-service/auth' +import { branchApi } from 'src/infra/api/access-service/branch' import { userLogout } from './actions' import { AuthState, @@ -51,6 +52,49 @@ export const authSlice = createSlice({ // @ts-ignore unauthenticatedState.data = undefined }) + builder.addMatcher( + branchApi.endpoints.branchUpdateById.matchFulfilled, + ( + state, + { + meta: { + arg: { + originalArgs: { branchUpdateRequestDto, id }, + }, + }, + }, + ) => { + if (state.isAuthenticated === true) { + state.data.branches = state.data.branches.map((branch) => { + if (branch._id === id) { + return { + ...branch, + ...branchUpdateRequestDto, + } + } + return branch + }) + } + }, + ) + builder.addMatcher( + branchApi.endpoints.branchDeleteById.matchFulfilled, + (state, { payload }) => { + if (state.isAuthenticated === true) { + state.data.branches = state.data.branches.filter((branch) => { + return branch._id !== payload._id + }) + } + }, + ) + builder.addMatcher( + branchApi.endpoints.branchCreate.matchFulfilled, + (state, { payload }) => { + if (state.isAuthenticated === true) { + state.data.branches.push(payload) + } + }, + ) builder.addMatcher( authApi.endpoints.authLogin.matchFulfilled, (state, { payload }) => { diff --git a/apps/hcdc-web-app/src/features/branch/components/BranchOriginSelector/index.tsx b/apps/hcdc-web-app/src/features/branch/components/BranchOriginSelector/index.tsx new file mode 100644 index 00000000..0e0d9dcc --- /dev/null +++ b/apps/hcdc-web-app/src/features/branch/components/BranchOriginSelector/index.tsx @@ -0,0 +1,110 @@ +import { + Box, + Button, + Divider, + List, + ListItem, + ListItemButton, + ListItemText, +} from '@mui/material' +import { useEffect, useState } from 'react' +import { SideAction } from 'src/components/ui' +import { authSlice } from 'src/features/auth' +import { + BranchResponseDto, + useBranchUpdateByIdMutation, +} from 'src/infra/api/access-service/branch' +import { useTypedSelector } from 'src/infra/redux' + +interface BranchOriginSelectorProps { + branch: BranchResponseDto | null + onClose: Function +} + +export function BranchOriginSelector(props: BranchOriginSelectorProps) { + const [selectedIds, setSelectedIds] = useState(new Set()) + const branches = useTypedSelector(authSlice.selectors.selectBranches)! + + useEffect(() => { + if (props.branch) { + setSelectedIds(new Set(props.branch.sampleOriginIds)) + } + }, [props.branch?._id]) + + const toggleSelected = (branchId: string) => () => { + setSelectedIds((idSet) => { + if (idSet.has(branchId)) { + idSet.delete(branchId) + } else { + idSet.add(branchId) + } + return new Set(idSet) + }) + } + + const [updateBranch, { isLoading }] = useBranchUpdateByIdMutation() + + const handleSubmit = async () => { + if (props.branch) { + await updateBranch({ + id: props.branch._id, + branchUpdateRequestDto: { + sampleOriginIds: Array.from(selectedIds), + }, + }) + props.onClose() + } + } + + return ( + + + + + + {branches.map((branch) => { + return ( + + + + + + ) + })} + + + + ) +} diff --git a/apps/hcdc-web-app/src/features/branch/components/BranchTable/index.tsx b/apps/hcdc-web-app/src/features/branch/components/BranchTable/index.tsx index a9058e45..e23afb01 100644 --- a/apps/hcdc-web-app/src/features/branch/components/BranchTable/index.tsx +++ b/apps/hcdc-web-app/src/features/branch/components/BranchTable/index.tsx @@ -1,11 +1,14 @@ +import { ReportTypeValues } from '@diut/hcdc' +import { useState } from 'react' import { CrudTable } from 'src/components/table' +import { authSlice } from 'src/features/auth' import { + BranchResponseDto, useBranchCreateMutation, - useBranchSearchQuery, useBranchUpdateByIdMutation, - useLazyBranchSearchQuery, } from 'src/infra/api/access-service/branch' -import { usePagination } from 'src/shared/hooks' +import { useTypedSelector } from 'src/infra/redux' +import { BranchOriginSelector } from '../BranchOriginSelector' import { branchColumns } from './columns' type BranchTableProps = { @@ -16,62 +19,72 @@ type BranchTableProps = { } export function BranchTable(props: BranchTableProps) { - const { filterObj } = usePagination({ - offset: props.page, - limit: props.pageSize, - sort: { displayIndex: 1 }, - filter: {}, - }) + const branches = useTypedSelector(authSlice.selectors.selectBranches)! - const { data, isFetching } = useBranchSearchQuery(filterObj) - const [searchBranchs] = useLazyBranchSearchQuery() + const [openBranchOriginAction, setOpenBranchOriginAction] = + useState(null) const [createBranch, { isLoading: isCreating }] = useBranchCreateMutation() const [updateBranch, { isLoading: isUpdating }] = useBranchUpdateByIdMutation() return ( - { - // ui similar to role select + <> + { + setOpenBranchOriginAction(item) + }, }, - }, - ]} - onItemCreate={async (item) => { - await createBranch({ - type: 'Internal', - name: item.name, - displayIndex: item.displayIndex, - address: item.address, - sampleOriginIds: [], - }).unwrap() - }} - onItemUpdate={async (newItem) => { - await updateBranch({ - id: newItem._id, - branchUpdateRequestDto: { - name: newItem.name, - displayIndex: newItem.displayIndex, - address: newItem.address, - sampleOriginIds: newItem.sampleOriginIds, - }, - }).unwrap() - }} - onRefresh={async () => { - await searchBranchs(filterObj).unwrap() - }} - /> + ]} + onItemCreate={async (item) => { + const { _id } = await createBranch({ + type: 'Internal', + name: item.name, + displayIndex: item.displayIndex, + address: item.address, + sampleOriginIds: [], + reportConfig: Object.fromEntries( + ReportTypeValues.map((reportType) => [ + reportType, + { testIds: [] }, + ]), + ), + }).unwrap() + await updateBranch({ + id: _id, + branchUpdateRequestDto: { + sampleOriginIds: [_id], + }, + }).unwrap() + }} + onItemUpdate={async (newItem) => { + await updateBranch({ + id: newItem._id, + branchUpdateRequestDto: { + name: newItem.name, + displayIndex: newItem.displayIndex, + address: newItem.address, + }, + }).unwrap() + }} + /> + { + setOpenBranchOriginAction(null) + }} + /> + ) } diff --git a/apps/hcdc-web-app/src/features/branch/components/index.ts b/apps/hcdc-web-app/src/features/branch/components/index.ts index 1806d753..00c58543 100644 --- a/apps/hcdc-web-app/src/features/branch/components/index.ts +++ b/apps/hcdc-web-app/src/features/branch/components/index.ts @@ -1 +1,2 @@ +export * from './BranchOriginSelector' export * from './BranchTable' diff --git a/apps/hcdc-web-app/src/infra/api/access-service/auth.ts b/apps/hcdc-web-app/src/infra/api/access-service/auth.ts index c552e12f..662e9bca 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/auth.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/auth.ts @@ -78,6 +78,7 @@ export type BranchUnpopulatedResponseDto = { address: string type: 'Internal' | 'External' sampleOriginIds: string[] + reportConfig: object } export type RoleUnpopulatedResponseDto = { _id: string diff --git a/apps/hcdc-web-app/src/infra/api/access-service/branch.ts b/apps/hcdc-web-app/src/infra/api/access-service/branch.ts index 72e96fc0..a7126b7f 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/branch.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/branch.ts @@ -78,6 +78,7 @@ export type BranchUnpopulatedResponseDto = { name: string address: string type: 'Internal' | 'External' + reportConfig: object sampleOriginIds: string[] } export type BranchResponseDto = { @@ -86,6 +87,7 @@ export type BranchResponseDto = { name: string address: string type: 'Internal' | 'External' + reportConfig: object sampleOriginIds: string[] sampleOrigins?: BranchUnpopulatedResponseDto[] } @@ -102,12 +104,12 @@ export type HttpErrorResponse = { | 'AUTHN_JWT_INVALID_TOKEN' | 'AUTHN_LOGIN_INVALID_USERNAME' | 'AUTHN_LOGIN_INVALID_PASSWORD' - | 'AUTHN_COOKIE_ACCESS_TOKEN_NOT_FOUND' - | 'AUTHN_PAYLOAD_NOT_FOUND' - | 'AUTHN_PAYLOAD_USER_NOT_FOUND' + | 'AUTHN_COOKIE_NOT_FOUND' + | 'AUTHN_PAYLOAD_INVALID' | 'AUTHZ' | 'AUTHZ_AUTHENTICATION_REQUIRED' | 'AUTHZ_PERMISSION_DENIED' + | 'AUTHZ_CONTEXT_INVALID' | 'ENTITY' | 'ENTITY_NOT_FOUND' | 'ENTITY_CANNOT_DELETE' @@ -130,8 +132,10 @@ export type PopulateOptionDto = { export type BranchSearchRequestDto = { offset?: number limit?: number - projection?: unknown + /** mongoose Query.sort() */ sort?: object + projection?: object + /** mongoose FilterQuery */ filter?: object populates?: PopulateOptionDto[] } @@ -140,6 +144,7 @@ export type BranchCreateRequestDto = { name: string address: string type: 'Internal' | 'External' + reportConfig: object sampleOriginIds: string[] } export type BranchUpdateRequestDto = { @@ -147,6 +152,7 @@ export type BranchUpdateRequestDto = { name?: string address?: string type?: 'Internal' | 'External' + reportConfig?: object sampleOriginIds?: string[] } export const { diff --git a/apps/hcdc-web-app/src/shared/constants/index.ts b/apps/hcdc-web-app/src/shared/constants/index.ts index 47218990..706ba83c 100644 --- a/apps/hcdc-web-app/src/shared/constants/index.ts +++ b/apps/hcdc-web-app/src/shared/constants/index.ts @@ -1 +1 @@ -export const ROWS_PER_PAGE_OPTIONS = [10, 30, 100] +export const ROWS_PER_PAGE_OPTIONS = [1, 10, 30, 100] diff --git a/libs/hcdc/src/entity/bio-product/entity.ts b/libs/hcdc/src/entity/bio-product/entity.ts index c7b1ccca..db49128e 100644 --- a/libs/hcdc/src/entity/bio-product/entity.ts +++ b/libs/hcdc/src/entity/bio-product/entity.ts @@ -8,10 +8,10 @@ export type BioProduct = BaseEntity & { name: string testId: string - test?: Test | null + test?: Test branchId: string - branch?: Branch | null + branch?: Branch } export enum BioProductAction { diff --git a/libs/hcdc/src/entity/branch/entity.ts b/libs/hcdc/src/entity/branch/entity.ts index 1a66a4f8..ea5dd31d 100644 --- a/libs/hcdc/src/entity/branch/entity.ts +++ b/libs/hcdc/src/entity/branch/entity.ts @@ -26,7 +26,7 @@ export type Branch = BaseEntity & { reportConfig: BranchReportConfig sampleOriginIds: string[] - sampleOrigins?: (Omit | null)[] + sampleOrigins?: Omit[] } export enum BranchAction { diff --git a/libs/hcdc/src/entity/diagnosis/entity.ts b/libs/hcdc/src/entity/diagnosis/entity.ts index 9a1f5657..56a4c275 100644 --- a/libs/hcdc/src/entity/diagnosis/entity.ts +++ b/libs/hcdc/src/entity/diagnosis/entity.ts @@ -7,7 +7,7 @@ export type Diagnosis = BaseEntity & { name: string branchId: string - branch?: Branch | null + branch?: Branch } export enum DiagnosisAction { diff --git a/libs/hcdc/src/entity/doctor/entity.ts b/libs/hcdc/src/entity/doctor/entity.ts index e6a006d8..e5aaf987 100644 --- a/libs/hcdc/src/entity/doctor/entity.ts +++ b/libs/hcdc/src/entity/doctor/entity.ts @@ -7,7 +7,7 @@ export type Doctor = BaseEntity & { name: string branchId: string - branch?: Branch | null + branch?: Branch } export enum DoctorAction { diff --git a/libs/hcdc/src/entity/instrument/entity.ts b/libs/hcdc/src/entity/instrument/entity.ts index b3afcbd0..0553606f 100644 --- a/libs/hcdc/src/entity/instrument/entity.ts +++ b/libs/hcdc/src/entity/instrument/entity.ts @@ -8,10 +8,10 @@ export type Instrument = BaseEntity & { name: string testId: string - test?: Test | null + test?: Test branchId: string - branch?: Branch | null + branch?: Branch } export enum InstrumentAction { diff --git a/libs/hcdc/src/entity/patient-type/entity.ts b/libs/hcdc/src/entity/patient-type/entity.ts index 45d2aed1..db878510 100644 --- a/libs/hcdc/src/entity/patient-type/entity.ts +++ b/libs/hcdc/src/entity/patient-type/entity.ts @@ -7,7 +7,7 @@ export type PatientType = BaseEntity & { name: string branchId: string - branch?: Branch | null + branch?: Branch } export enum PatientTypeAction { diff --git a/libs/hcdc/src/entity/patient/entity.ts b/libs/hcdc/src/entity/patient/entity.ts index 05352dd0..0a03fd92 100644 --- a/libs/hcdc/src/entity/patient/entity.ts +++ b/libs/hcdc/src/entity/patient/entity.ts @@ -29,7 +29,7 @@ export type Patient = BaseEntity & { SSN: string branchId: string - branch?: Branch | null + branch?: Branch } export enum PatientAction { diff --git a/libs/hcdc/src/entity/print-form/entity.ts b/libs/hcdc/src/entity/print-form/entity.ts index 0325e08c..bb02f522 100644 --- a/libs/hcdc/src/entity/print-form/entity.ts +++ b/libs/hcdc/src/entity/print-form/entity.ts @@ -24,7 +24,7 @@ export type PrintForm = BaseEntity & { template: PrintTemplate branchId: string - branch?: Branch | null + branch?: Branch } export enum PrintFormAction { diff --git a/libs/hcdc/src/entity/role/entity.ts b/libs/hcdc/src/entity/role/entity.ts index eec32c3b..5908d93c 100644 --- a/libs/hcdc/src/entity/role/entity.ts +++ b/libs/hcdc/src/entity/role/entity.ts @@ -10,7 +10,7 @@ export type Role = BaseEntity & { permissions: PermissionRule[] branchId: string - branch?: Branch | null + branch?: Branch } export enum RoleAction { diff --git a/libs/hcdc/src/entity/sample-type/entity.ts b/libs/hcdc/src/entity/sample-type/entity.ts index af5b92e8..485687ef 100644 --- a/libs/hcdc/src/entity/sample-type/entity.ts +++ b/libs/hcdc/src/entity/sample-type/entity.ts @@ -7,7 +7,7 @@ export type SampleType = BaseEntity & { name: string branchId: string - branch?: Branch | null + branch?: Branch } export enum SampleTypeAction { diff --git a/libs/hcdc/src/entity/sample/entity.ts b/libs/hcdc/src/entity/sample/entity.ts index 2371d650..10a28699 100644 --- a/libs/hcdc/src/entity/sample/entity.ts +++ b/libs/hcdc/src/entity/sample/entity.ts @@ -54,25 +54,25 @@ export type Sample = BaseEntity & { printedBy?: User | null patientId: string - patient?: Patient | null + patient?: Patient doctorId: string - doctor?: Doctor | null + doctor?: Doctor patientTypeId: string - patientType?: PatientType | null + patientType?: PatientType diagnosisId: string - diagnosis?: Diagnosis | null + diagnosis?: Diagnosis originId: string - origin?: Branch | null + origin?: Branch sampleTypeIds: string[] - sampleTypes?: (SampleType | null)[] + sampleTypes?: SampleType[] branchId: string - branch?: Branch | null + branch?: Branch } export const sampleInfoFieldNames = [ diff --git a/libs/hcdc/src/entity/test-category/entity.ts b/libs/hcdc/src/entity/test-category/entity.ts index dec5ca43..633cb52b 100644 --- a/libs/hcdc/src/entity/test-category/entity.ts +++ b/libs/hcdc/src/entity/test-category/entity.ts @@ -8,7 +8,7 @@ export type TestCategory = BaseEntity & { reportIndex: number branchId: string - branch?: Branch | null + branch?: Branch } export enum TestCategoryAction { diff --git a/libs/hcdc/src/entity/test-combo/entity.ts b/libs/hcdc/src/entity/test-combo/entity.ts index e5c9a28f..e41c2107 100644 --- a/libs/hcdc/src/entity/test-combo/entity.ts +++ b/libs/hcdc/src/entity/test-combo/entity.ts @@ -8,10 +8,10 @@ export type TestCombo = BaseEntity & { name: string testIds: string[] - tests?: (Test | null)[] + tests?: Test[] branchId: string - branch?: Branch | null + branch?: Branch } export enum TestComboAction { diff --git a/libs/hcdc/src/entity/test-element/entity.ts b/libs/hcdc/src/entity/test-element/entity.ts index 1ea51317..4f2f79b5 100644 --- a/libs/hcdc/src/entity/test-element/entity.ts +++ b/libs/hcdc/src/entity/test-element/entity.ts @@ -30,7 +30,7 @@ export type TestElement = BaseEntity & { test?: Test | null branchId: string - branch?: Branch | null + branch?: Branch } export enum TestElementAction { diff --git a/libs/hcdc/src/entity/test/entity.ts b/libs/hcdc/src/entity/test/entity.ts index 97dcb19f..44048802 100644 --- a/libs/hcdc/src/entity/test/entity.ts +++ b/libs/hcdc/src/entity/test/entity.ts @@ -13,22 +13,22 @@ export type Test = BaseEntity & { shouldDisplayWithChildren: boolean bioProductId: string | null - bioProduct?: BioProduct | null + bioProduct?: BioProduct instrumentId: string | null - instrument?: Instrument | null + instrument?: Instrument sampleTypeId: string | null - sampleType?: SampleType | null + sampleType?: SampleType testCategoryId: string - testCategory?: TestCategory | null + testCategory?: TestCategory printFormIds: string[] - printForms?: (PrintForm | null)[] + printForms?: PrintForm[] branchId: string - branch?: Branch | null + branch?: Branch } export enum TestAction { diff --git a/libs/hcdc/src/entity/user/entity.ts b/libs/hcdc/src/entity/user/entity.ts index 409103f3..dad1f731 100644 --- a/libs/hcdc/src/entity/user/entity.ts +++ b/libs/hcdc/src/entity/user/entity.ts @@ -12,10 +12,10 @@ export type User = BaseEntity & { inlinePermissions: PermissionRule[] branchIds: string[] - branches?: (Branch | null)[] + branches?: Branch[] roleIds: string[] - roles?: (Role | null)[] + roles?: Role[] } export enum UserAction { diff --git a/libs/nestjs-infra/src/adapter/mongo/repository.ts b/libs/nestjs-infra/src/adapter/mongo/repository.ts index 4cbc614f..eeaa7bc4 100644 --- a/libs/nestjs-infra/src/adapter/mongo/repository.ts +++ b/libs/nestjs-infra/src/adapter/mongo/repository.ts @@ -3,7 +3,7 @@ import { UpdateOptions } from 'mongodb' import { FilterQuery, Model, - MongooseQueryOptions, + MongooseUpdateQueryOptions, PipelineStage, QueryOptions, SortOrder, @@ -222,7 +222,7 @@ export abstract class MongoRepository { public async updateMany( filter: FilterQuery, data: UpdateQuery, - options?: UpdateOptions & Omit, 'lean'>, + options?: UpdateOptions & Omit, 'lean'>, isDeleted: boolean | null = false, ) { let filterObj = filter