diff --git a/apps/hcdc-access-service/package.json b/apps/hcdc-access-service/package.json index 3235f360..0c8b1d11 100644 --- a/apps/hcdc-access-service/package.json +++ b/apps/hcdc-access-service/package.json @@ -12,12 +12,12 @@ "lint": "tsc && rimraf dist" }, "dependencies": { - "@casl/ability": "^6.5.0", - "@casl/mongoose": "^7.2.2", "@diut/common": "workspace:*", "@diut/hcdc": "workspace:*", "@diut/nestjs-infra": "workspace:*", "@diut/services": "workspace:*", + "@casl/ability": "^6.5.0", + "@casl/mongoose": "^7.2.2", "@nestjs/cli": "^10.3.2", "@nestjs/common": "^10.3.3", "@nestjs/config": "^3.2.0", @@ -28,7 +28,6 @@ "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.3.3", "@nestjs/swagger": "^7.3.0", - "@ucast/mongo2js": "^1.3.4", "argon2": "^0.31.2", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", diff --git a/apps/hcdc-access-service/src/domain/auth/setup-subject.ts b/apps/hcdc-access-service/src/domain/auth/setup-subject.ts new file mode 100644 index 00000000..4ef69f68 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/auth/setup-subject.ts @@ -0,0 +1,22 @@ +import '@casl/mongoose' + +declare module '@casl/mongoose' { + interface RecordTypes { + BioProduct: true + Branch: true + Diagnosis: true + Doctor: true + Instrument: true + Patient: true + PatientType: true + PrintForm: true + Role: true + Sample: true + SampleType: true + Test: true + TestCategory: true + TestCombo: true + TestElement: true + User: true + } +} diff --git a/apps/hcdc-access-service/src/domain/auth/utils.ts b/apps/hcdc-access-service/src/domain/auth/utils.ts index c2cd521d..d0886e16 100644 --- a/apps/hcdc-access-service/src/domain/auth/utils.ts +++ b/apps/hcdc-access-service/src/domain/auth/utils.ts @@ -1,44 +1,22 @@ -import { - MongoAbility, - subject as assignSubject, - buildMongoQueryMatcher, - createMongoAbility, -} from '@casl/ability' -import { $or, or } from '@ucast/mongo2js' +import { MongoAbility } from '@casl/ability' import type { FilterQuery } from 'mongoose' import { accessibleBy } from '@casl/mongoose' import type { PopulatePath } from '@diut/nestjs-infra' - -import { AuthAction, AuthActionUnionType } from './action' import { + AUTH_ACTION_ALL, + AUTH_SUBJECT_ALL, + AuthAction, + AuthActionUnionType, AuthSubject, AuthSubjectUnionType, + BaseEntity, SubjectEntityMapping, -} from './subject' + checkPermission, +} from '@diut/hcdc' + import { EAuthzPermissionDenied } from 'src/domain/exception' -import { AUTH_ACTION_ALL, AUTH_SUBJECT_ALL } from './constants' -import { BaseEntity, PermissionRule } from '../entity' import { EntityFindOneOptions } from '../interface' -const conditionsMatcher = buildMongoQueryMatcher({ $or }, { or }) - -export function createAbility(permissionRules: PermissionRule[]) { - return createMongoAbility(permissionRules, { conditionsMatcher }) -} - -export function checkPermission( - ability: MongoAbility, - subject: TSubject | typeof AUTH_SUBJECT_ALL, - action: (typeof AuthAction)[TSubject][number] | typeof AUTH_ACTION_ALL, - object?: Partial | null, -) { - if (object != undefined) { - return ability.can(action, assignSubject(subject, object)) - } - - return ability.can(action, subject) -} - export function assertPermission( ability: MongoAbility, subject: TSubject | typeof AUTH_SUBJECT_ALL, diff --git a/apps/hcdc-access-service/src/domain/entity/base-entity.ts b/apps/hcdc-access-service/src/domain/entity/base-entity.ts index a3813ba7..6bfcceec 100644 --- a/apps/hcdc-access-service/src/domain/entity/base-entity.ts +++ b/apps/hcdc-access-service/src/domain/entity/base-entity.ts @@ -1,17 +1,8 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { BaseEntity } from '@diut/hcdc' import { ApiPropertyOptions } from '@nestjs/swagger' import { omit } from 'lodash' -export type BaseEntity = { - _id: string - - createdAt: Date - updatedAt: Date - - isDeleted: boolean - deletedAt?: Date -} - export const exampleBaseEntity = { _id: exampleMongoObjectId, createdAt: { diff --git a/apps/hcdc-access-service/src/domain/entity/bio-product/auth.ts b/apps/hcdc-access-service/src/domain/entity/bio-product/auth.ts deleted file mode 100644 index f06a229a..00000000 --- a/apps/hcdc-access-service/src/domain/entity/bio-product/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum BioProductAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - BioProduct: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/bio-product/example.ts b/apps/hcdc-access-service/src/domain/entity/bio-product/example.ts index 8241cc65..2484b724 100644 --- a/apps/hcdc-access-service/src/domain/entity/bio-product/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/bio-product/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { BioProduct } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { BioProduct } from './entity' export const exampleBioProduct = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/bio-product/index.ts b/apps/hcdc-access-service/src/domain/entity/bio-product/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/bio-product/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/bio-product/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/branch/auth.ts b/apps/hcdc-access-service/src/domain/entity/branch/auth.ts deleted file mode 100644 index 176dd473..00000000 --- a/apps/hcdc-access-service/src/domain/entity/branch/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum BranchAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Branch: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/branch/example.ts b/apps/hcdc-access-service/src/domain/entity/branch/example.ts index 0b15b50f..c2350236 100644 --- a/apps/hcdc-access-service/src/domain/entity/branch/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/branch/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectIds } from '@diut/nestjs-infra' +import { exampleMongoObjectIds } from '@diut/common' +import { Branch, BranchType } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Branch, BranchType } from './entity' export const exampleBranch = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/branch/index.ts b/apps/hcdc-access-service/src/domain/entity/branch/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/branch/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/branch/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/diagnosis/auth.ts b/apps/hcdc-access-service/src/domain/entity/diagnosis/auth.ts deleted file mode 100644 index e761b162..00000000 --- a/apps/hcdc-access-service/src/domain/entity/diagnosis/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum DiagnosisAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Diagnosis: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/diagnosis/example.ts b/apps/hcdc-access-service/src/domain/entity/diagnosis/example.ts index bdf77141..44ec597f 100644 --- a/apps/hcdc-access-service/src/domain/entity/diagnosis/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/diagnosis/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { Diagnosis } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Diagnosis } from './entity' export const exampleDiagnosis = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/diagnosis/index.ts b/apps/hcdc-access-service/src/domain/entity/diagnosis/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/diagnosis/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/diagnosis/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/doctor/auth.ts b/apps/hcdc-access-service/src/domain/entity/doctor/auth.ts deleted file mode 100644 index 9405f1eb..00000000 --- a/apps/hcdc-access-service/src/domain/entity/doctor/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum DoctorAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Doctor: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/doctor/example.ts b/apps/hcdc-access-service/src/domain/entity/doctor/example.ts index c1d04ddb..35b79d9c 100644 --- a/apps/hcdc-access-service/src/domain/entity/doctor/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/doctor/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { Doctor } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Doctor } from './entity' export const exampleDoctor = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/doctor/index.ts b/apps/hcdc-access-service/src/domain/entity/doctor/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/doctor/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/doctor/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/instrument/auth.ts b/apps/hcdc-access-service/src/domain/entity/instrument/auth.ts deleted file mode 100644 index a10d3753..00000000 --- a/apps/hcdc-access-service/src/domain/entity/instrument/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum InstrumentAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Instrument: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/instrument/example.ts b/apps/hcdc-access-service/src/domain/entity/instrument/example.ts index 3b8606f6..ecfd54a4 100644 --- a/apps/hcdc-access-service/src/domain/entity/instrument/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/instrument/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { Instrument } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Instrument } from './entity' export const exampleInstrument = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/instrument/index.ts b/apps/hcdc-access-service/src/domain/entity/instrument/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/instrument/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/instrument/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/patient-type/auth.ts b/apps/hcdc-access-service/src/domain/entity/patient-type/auth.ts deleted file mode 100644 index bf9ae4a8..00000000 --- a/apps/hcdc-access-service/src/domain/entity/patient-type/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum PatientTypeAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - PatientType: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/patient-type/example.ts b/apps/hcdc-access-service/src/domain/entity/patient-type/example.ts index a897b1e4..e6556601 100644 --- a/apps/hcdc-access-service/src/domain/entity/patient-type/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/patient-type/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { PatientType } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { PatientType } from './entity' export const examplePatientType = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/patient-type/index.ts b/apps/hcdc-access-service/src/domain/entity/patient-type/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/patient-type/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/patient-type/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/patient/auth.ts b/apps/hcdc-access-service/src/domain/entity/patient/auth.ts deleted file mode 100644 index 420a0cde..00000000 --- a/apps/hcdc-access-service/src/domain/entity/patient/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum PatientAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Patient: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/patient/example.ts b/apps/hcdc-access-service/src/domain/entity/patient/example.ts index cb83f30b..62ca590c 100644 --- a/apps/hcdc-access-service/src/domain/entity/patient/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/patient/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { Patient, PatientGender } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Patient, PatientGender } from './entity' export const examplePatient = { externalId: { diff --git a/apps/hcdc-access-service/src/domain/entity/patient/index.ts b/apps/hcdc-access-service/src/domain/entity/patient/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/patient/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/patient/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/permission-rule/example.ts b/apps/hcdc-access-service/src/domain/entity/permission-rule/example.ts index aa0066f1..b1562f32 100644 --- a/apps/hcdc-access-service/src/domain/entity/permission-rule/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/permission-rule/example.ts @@ -1,6 +1,7 @@ +import { PermissionRule } from '@diut/hcdc' + import { AuthActionValues, AuthSubjectValues } from 'src/domain/auth' import { EntityDataExample } from '../base-entity' -import { PermissionRule } from './entity' export const examplePermissionRule = { subject: { diff --git a/apps/hcdc-access-service/src/domain/entity/permission-rule/index.ts b/apps/hcdc-access-service/src/domain/entity/permission-rule/index.ts index 7ef54e26..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/permission-rule/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/permission-rule/index.ts @@ -1,2 +1 @@ -export * from './entity' export * from './example' diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/auth.ts b/apps/hcdc-access-service/src/domain/entity/print-form/auth.ts deleted file mode 100644 index 00cf401a..00000000 --- a/apps/hcdc-access-service/src/domain/entity/print-form/auth.ts +++ /dev/null @@ -1,15 +0,0 @@ -import '@casl/mongoose' - -export enum PrintFormAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', - OverrideAuthor = 'OverrideAuthor', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - PrintForm: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/example.ts b/apps/hcdc-access-service/src/domain/entity/print-form/example.ts index 33a10be2..ce8c007a 100644 --- a/apps/hcdc-access-service/src/domain/entity/print-form/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/print-form/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { PrintForm, PrintTemplate } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { PrintForm, PrintTemplate } from './entity' export const examplePrintForm = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/index.ts b/apps/hcdc-access-service/src/domain/entity/print-form/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/print-form/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/print-form/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/role/auth.ts b/apps/hcdc-access-service/src/domain/entity/role/auth.ts deleted file mode 100644 index 8fb1f564..00000000 --- a/apps/hcdc-access-service/src/domain/entity/role/auth.ts +++ /dev/null @@ -1,16 +0,0 @@ -import '@casl/mongoose' - -export enum RoleAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', - AssignToUser = 'AssignToUser', - AssignUserInline = 'AssignUserInline', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Role: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/role/example.ts b/apps/hcdc-access-service/src/domain/entity/role/example.ts index 1c6c7cb4..55c9d46b 100644 --- a/apps/hcdc-access-service/src/domain/entity/role/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/role/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { Role } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Role } from './entity' export const exampleRole = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/role/index.ts b/apps/hcdc-access-service/src/domain/entity/role/index.ts index 61284153..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/role/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/role/index.ts @@ -1,3 +1 @@ -export * from './entity' -export * from './auth' export * from './example' diff --git a/apps/hcdc-access-service/src/domain/entity/sample-type/auth.ts b/apps/hcdc-access-service/src/domain/entity/sample-type/auth.ts deleted file mode 100644 index 89997333..00000000 --- a/apps/hcdc-access-service/src/domain/entity/sample-type/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum SampleTypeAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - SampleType: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/sample-type/example.ts b/apps/hcdc-access-service/src/domain/entity/sample-type/example.ts index 3013ad42..5ac4673b 100644 --- a/apps/hcdc-access-service/src/domain/entity/sample-type/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/sample-type/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { SampleType } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { SampleType } from './entity' export const exampleSampleType = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/sample-type/index.ts b/apps/hcdc-access-service/src/domain/entity/sample-type/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/sample-type/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/sample-type/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/sample/auth.ts b/apps/hcdc-access-service/src/domain/entity/sample/auth.ts deleted file mode 100644 index 68b58c47..00000000 --- a/apps/hcdc-access-service/src/domain/entity/sample/auth.ts +++ /dev/null @@ -1,18 +0,0 @@ -import '@casl/mongoose' - -export enum SampleAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - UpdateInfo = 'UpdateInfo', - UpdateResult = 'UpdateResult', - Delete = 'Delete', - ExportReport = 'ExportReport', - PrintResult = 'PrintResult', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Sample: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/sample/example.ts b/apps/hcdc-access-service/src/domain/entity/sample/example.ts index c85e3c94..f60f9296 100644 --- a/apps/hcdc-access-service/src/domain/entity/sample/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/sample/example.ts @@ -2,10 +2,10 @@ import { exampleDate, exampleMongoObjectId, exampleMongoObjectIds, -} from '@diut/nestjs-infra' +} from '@diut/common' +import { SampleResultTestElement, SampleResultTest, Sample } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { SampleResultTestElement, SampleResultTest, Sample } from './entity' import { exampleBioProduct } from '../bio-product' import { exampleInstrument } from '../instrument' diff --git a/apps/hcdc-access-service/src/domain/entity/sample/index.ts b/apps/hcdc-access-service/src/domain/entity/sample/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/sample/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/sample/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/test-category/auth.ts b/apps/hcdc-access-service/src/domain/entity/test-category/auth.ts deleted file mode 100644 index fd50ab42..00000000 --- a/apps/hcdc-access-service/src/domain/entity/test-category/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum TestCategoryAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - TestCategory: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/test-category/example.ts b/apps/hcdc-access-service/src/domain/entity/test-category/example.ts index f954bf44..81f982db 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-category/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/test-category/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { TestCategory } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { TestCategory } from './entity' export const exampleTestCategory = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/test-category/index.ts b/apps/hcdc-access-service/src/domain/entity/test-category/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-category/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/test-category/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/test-combo/auth.ts b/apps/hcdc-access-service/src/domain/entity/test-combo/auth.ts deleted file mode 100644 index ffe1f453..00000000 --- a/apps/hcdc-access-service/src/domain/entity/test-combo/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum TestComboAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - TestCombo: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/test-combo/example.ts b/apps/hcdc-access-service/src/domain/entity/test-combo/example.ts index 969bffbd..725c427b 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-combo/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/test-combo/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId, exampleMongoObjectIds } from '@diut/nestjs-infra' +import { exampleMongoObjectId, exampleMongoObjectIds } from '@diut/common' +import { TestCombo } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { TestCombo } from './entity' export const exampleTestCombo = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/test-combo/index.ts b/apps/hcdc-access-service/src/domain/entity/test-combo/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-combo/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/test-combo/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/test-element/auth.ts b/apps/hcdc-access-service/src/domain/entity/test-element/auth.ts deleted file mode 100644 index 622df664..00000000 --- a/apps/hcdc-access-service/src/domain/entity/test-element/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum TestElementAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - TestElement: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/test-element/example.ts b/apps/hcdc-access-service/src/domain/entity/test-element/example.ts index 7fcd196c..8bd39505 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-element/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/test-element/example.ts @@ -1,8 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { TestElement, PatientCategory } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { TestElement } from './entity' -import { PatientCategory } from '../patient' export const exampleNormalRule = { category: { diff --git a/apps/hcdc-access-service/src/domain/entity/test-element/index.ts b/apps/hcdc-access-service/src/domain/entity/test-element/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-element/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/test-element/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/test/auth.ts b/apps/hcdc-access-service/src/domain/entity/test/auth.ts deleted file mode 100644 index 61f945ec..00000000 --- a/apps/hcdc-access-service/src/domain/entity/test/auth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import '@casl/mongoose' - -export enum TestAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - Test: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/test/example.ts b/apps/hcdc-access-service/src/domain/entity/test/example.ts index d6cb267a..4e6c5d48 100644 --- a/apps/hcdc-access-service/src/domain/entity/test/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/test/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectId } from '@diut/nestjs-infra' +import { exampleMongoObjectId } from '@diut/common' +import { Test } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { Test } from './entity' export const exampleTest = { displayIndex: { diff --git a/apps/hcdc-access-service/src/domain/entity/test/index.ts b/apps/hcdc-access-service/src/domain/entity/test/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/test/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/test/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/user/auth.ts b/apps/hcdc-access-service/src/domain/entity/user/auth.ts deleted file mode 100644 index f418a105..00000000 --- a/apps/hcdc-access-service/src/domain/entity/user/auth.ts +++ /dev/null @@ -1,15 +0,0 @@ -import '@casl/mongoose' - -export enum UserAction { - Create = 'Create', - Read = 'Read', - Update = 'Update', - Delete = 'Delete', - ChangePassword = 'ChangePassword', -} - -declare module '@casl/mongoose' { - interface RecordTypes { - User: true - } -} diff --git a/apps/hcdc-access-service/src/domain/entity/user/example.ts b/apps/hcdc-access-service/src/domain/entity/user/example.ts index 4edcfff2..fecead78 100644 --- a/apps/hcdc-access-service/src/domain/entity/user/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/user/example.ts @@ -1,7 +1,7 @@ -import { exampleMongoObjectIds } from '@diut/nestjs-infra' +import { exampleMongoObjectIds } from '@diut/common' +import { User } from '@diut/hcdc' import { EntityDataExample } from '../base-entity' -import { User } from './entity' export const exampleUser = { username: { diff --git a/apps/hcdc-access-service/src/domain/entity/user/index.ts b/apps/hcdc-access-service/src/domain/entity/user/index.ts index 3b1b1117..d40c188c 100644 --- a/apps/hcdc-access-service/src/domain/entity/user/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/user/index.ts @@ -1,3 +1 @@ -export * from './entity' export * from './example' -export * from './auth' diff --git a/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/create.dto.ts b/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/create.dto.ts index 1ce033da..dc3297bd 100644 --- a/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/create.dto.ts +++ b/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/create.dto.ts @@ -1,8 +1,4 @@ -import { - BaseResourceResponseDto, - IsObjectId, - exampleMongoObjectIds, -} from '@diut/nestjs-infra' +import { BaseResourceResponseDto, IsObjectId } from '@diut/nestjs-infra' import { ApiProperty, IntersectionType, @@ -10,6 +6,7 @@ import { PickType, } from '@nestjs/swagger' import { Expose } from 'class-transformer' +import { exampleMongoObjectIds } from '@diut/common' import { SampleRequestDto } from './request-dto' import { sampleInfoFieldNames } from 'src/domain' diff --git a/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/update-info.dto.ts b/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/update-info.dto.ts index a63cc36c..c18f3a09 100644 --- a/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/update-info.dto.ts +++ b/apps/hcdc-access-service/src/presentation/http/v1/sample/dto/update-info.dto.ts @@ -4,13 +4,10 @@ import { PartialType, PickType, } from '@nestjs/swagger' -import { - BaseResourceResponseDto, - IsObjectId, - exampleMongoObjectIds, -} from '@diut/nestjs-infra' +import { BaseResourceResponseDto, IsObjectId } from '@diut/nestjs-infra' import { Expose } from 'class-transformer' import { IsOptional } from 'class-validator' +import { exampleMongoObjectIds } from '@diut/common' import { SampleRequestDto } from './request-dto' import { sampleInfoFieldNames } from 'src/domain' diff --git a/libs/common/src/constant.ts b/libs/common/src/constant.ts index 08f9d9e0..5018fc0f 100644 --- a/libs/common/src/constant.ts +++ b/libs/common/src/constant.ts @@ -1,2 +1,18 @@ export const DATETIME_FORMAT = 'dd/MM/yyyy HH:mm' export const DATEONLY_FORMAT = 'dd/MM/yyyy' + +export const exampleMongoObjectId = { + example: '634180269de1f07e47bbf494', +} + +export const exampleMongoObjectIds = { + example: ['634180269de1f07e47bbf494'], + type: () => 'string', + isArray: true, +} + +export const exampleDate = { + format: 'date-time', + // example: '2018-03-20T09:12:28Z', + example: new Date('2018-03-20T09:12:28Z'), +} diff --git a/libs/hcdc/package.json b/libs/hcdc/package.json index 533eb827..5c2e14f0 100644 --- a/libs/hcdc/package.json +++ b/libs/hcdc/package.json @@ -16,6 +16,9 @@ "dev": "tsc --watch --preserveWatchOutput" }, "dependencies": { + "@diut/common": "workspace:*", + "@casl/ability": "^6.5.0", + "@ucast/mongo2js": "^1.3.4", "lodash": "^4.17.21" }, "devDependencies": { diff --git a/apps/hcdc-access-service/src/domain/auth/action.ts b/libs/hcdc/src/auth/action.ts similarity index 100% rename from apps/hcdc-access-service/src/domain/auth/action.ts rename to libs/hcdc/src/auth/action.ts diff --git a/apps/hcdc-access-service/src/domain/auth/constants.ts b/libs/hcdc/src/auth/constants.ts similarity index 100% rename from apps/hcdc-access-service/src/domain/auth/constants.ts rename to libs/hcdc/src/auth/constants.ts diff --git a/libs/hcdc/src/auth/index.ts b/libs/hcdc/src/auth/index.ts new file mode 100644 index 00000000..bcbeab45 --- /dev/null +++ b/libs/hcdc/src/auth/index.ts @@ -0,0 +1,4 @@ +export * from './action' +export * from './subject' +export * from './utils' +export * from './constants' diff --git a/apps/hcdc-access-service/src/domain/auth/subject.ts b/libs/hcdc/src/auth/subject.ts similarity index 92% rename from apps/hcdc-access-service/src/domain/auth/subject.ts rename to libs/hcdc/src/auth/subject.ts index 02dc48d3..939a4c69 100644 --- a/apps/hcdc-access-service/src/domain/auth/subject.ts +++ b/libs/hcdc/src/auth/subject.ts @@ -1,5 +1,3 @@ -import { RecordTypes } from '@casl/mongoose' - import { BioProduct, Branch, @@ -38,7 +36,7 @@ export const AuthSubject = { Patient: 'Patient', TestCombo: 'TestCombo', Sample: 'Sample', -} satisfies Record +} as const export type AuthSubjectUnionType = keyof typeof AuthSubject diff --git a/libs/hcdc/src/auth/utils.ts b/libs/hcdc/src/auth/utils.ts new file mode 100644 index 00000000..1f72a545 --- /dev/null +++ b/libs/hcdc/src/auth/utils.ts @@ -0,0 +1,31 @@ +import { + MongoAbility, + subject as assignSubject, + buildMongoQueryMatcher, + createMongoAbility, +} from '@casl/ability' +import { $or, or } from '@ucast/mongo2js' + +import { AuthAction } from './action' +import { AuthSubject, SubjectEntityMapping } from './subject' +import { AUTH_ACTION_ALL, AUTH_SUBJECT_ALL } from './constants' +import { PermissionRule } from '../entity' + +const conditionsMatcher = buildMongoQueryMatcher({ $or }, { or }) + +export function createAbility(permissionRules: PermissionRule[]) { + return createMongoAbility(permissionRules, { conditionsMatcher }) +} + +export function checkPermission( + ability: MongoAbility, + subject: TSubject | typeof AUTH_SUBJECT_ALL, + action: (typeof AuthAction)[TSubject][number] | typeof AUTH_ACTION_ALL, + object?: Partial | null, +) { + if (object != undefined) { + return ability.can(action, assignSubject(subject, object)) + } + + return ability.can(action, subject) +} diff --git a/libs/hcdc/src/entity/base-entity.ts b/libs/hcdc/src/entity/base-entity.ts new file mode 100644 index 00000000..6bd66eaf --- /dev/null +++ b/libs/hcdc/src/entity/base-entity.ts @@ -0,0 +1,9 @@ +export type BaseEntity = { + _id: string + + createdAt: Date + updatedAt: Date + + isDeleted: boolean + deletedAt?: Date +} diff --git a/apps/hcdc-access-service/src/domain/entity/bio-product/entity.ts b/libs/hcdc/src/entity/bio-product/entity.ts similarity index 64% rename from apps/hcdc-access-service/src/domain/entity/bio-product/entity.ts rename to libs/hcdc/src/entity/bio-product/entity.ts index c5ae4015..ece08f43 100644 --- a/apps/hcdc-access-service/src/domain/entity/bio-product/entity.ts +++ b/libs/hcdc/src/entity/bio-product/entity.ts @@ -8,3 +8,10 @@ export type BioProduct = BaseEntity & { branchId: string branch?: Branch | null } + +export enum BioProductAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/bio-product/index.ts b/libs/hcdc/src/entity/bio-product/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/bio-product/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/branch/entity.ts b/libs/hcdc/src/entity/branch/entity.ts similarity index 79% rename from apps/hcdc-access-service/src/domain/entity/branch/entity.ts rename to libs/hcdc/src/entity/branch/entity.ts index e4681dc7..323d41d4 100644 --- a/apps/hcdc-access-service/src/domain/entity/branch/entity.ts +++ b/libs/hcdc/src/entity/branch/entity.ts @@ -18,3 +18,10 @@ export type Branch = BaseEntity & { sampleOriginIds: string[] sampleOrigins?: (Omit | null)[] } + +export enum BranchAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/branch/index.ts b/libs/hcdc/src/entity/branch/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/branch/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/diagnosis/entity.ts b/libs/hcdc/src/entity/diagnosis/entity.ts similarity index 64% rename from apps/hcdc-access-service/src/domain/entity/diagnosis/entity.ts rename to libs/hcdc/src/entity/diagnosis/entity.ts index 5d57b76c..1bb590cd 100644 --- a/apps/hcdc-access-service/src/domain/entity/diagnosis/entity.ts +++ b/libs/hcdc/src/entity/diagnosis/entity.ts @@ -8,3 +8,10 @@ export type Diagnosis = BaseEntity & { branchId: string branch?: Branch | null } + +export enum DiagnosisAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/diagnosis/index.ts b/libs/hcdc/src/entity/diagnosis/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/diagnosis/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/doctor/entity.ts b/libs/hcdc/src/entity/doctor/entity.ts similarity index 64% rename from apps/hcdc-access-service/src/domain/entity/doctor/entity.ts rename to libs/hcdc/src/entity/doctor/entity.ts index 98427741..9ba81b8b 100644 --- a/apps/hcdc-access-service/src/domain/entity/doctor/entity.ts +++ b/libs/hcdc/src/entity/doctor/entity.ts @@ -8,3 +8,10 @@ export type Doctor = BaseEntity & { branchId: string branch?: Branch | null } + +export enum DoctorAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/doctor/index.ts b/libs/hcdc/src/entity/doctor/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/doctor/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/libs/hcdc/src/entity/index.ts b/libs/hcdc/src/entity/index.ts new file mode 100644 index 00000000..e4d9684e --- /dev/null +++ b/libs/hcdc/src/entity/index.ts @@ -0,0 +1,21 @@ +export * from './base-entity' + +export * from './bio-product' +export * from './diagnosis' +export * from './patient-type' +export * from './doctor' +export * from './instrument' +export * from './sample-type' +export * from './test-category' +export * from './role' +export * from './user' +export * from './branch' +export * from './print-form' +export * from './patient' +export * from './test' +export * from './test-element' +export * from './test-combo' +export * from './sample' + +// put 'permission-rule' at bottom to avoid circular dependencies +export * from './permission-rule' diff --git a/apps/hcdc-access-service/src/domain/entity/instrument/entity.ts b/libs/hcdc/src/entity/instrument/entity.ts similarity index 64% rename from apps/hcdc-access-service/src/domain/entity/instrument/entity.ts rename to libs/hcdc/src/entity/instrument/entity.ts index c9aa66d4..e6a32d9d 100644 --- a/apps/hcdc-access-service/src/domain/entity/instrument/entity.ts +++ b/libs/hcdc/src/entity/instrument/entity.ts @@ -8,3 +8,10 @@ export type Instrument = BaseEntity & { branchId: string branch?: Branch | null } + +export enum InstrumentAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/instrument/index.ts b/libs/hcdc/src/entity/instrument/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/instrument/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/patient-type/entity.ts b/libs/hcdc/src/entity/patient-type/entity.ts similarity index 64% rename from apps/hcdc-access-service/src/domain/entity/patient-type/entity.ts rename to libs/hcdc/src/entity/patient-type/entity.ts index 1af775ec..cb1c8f31 100644 --- a/apps/hcdc-access-service/src/domain/entity/patient-type/entity.ts +++ b/libs/hcdc/src/entity/patient-type/entity.ts @@ -8,3 +8,10 @@ export type PatientType = BaseEntity & { branchId: string branch?: Branch | null } + +export enum PatientTypeAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/patient-type/index.ts b/libs/hcdc/src/entity/patient-type/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/patient-type/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/patient/entity.ts b/libs/hcdc/src/entity/patient/entity.ts similarity index 87% rename from apps/hcdc-access-service/src/domain/entity/patient/entity.ts rename to libs/hcdc/src/entity/patient/entity.ts index f82727e1..91e590dc 100644 --- a/apps/hcdc-access-service/src/domain/entity/patient/entity.ts +++ b/libs/hcdc/src/entity/patient/entity.ts @@ -32,3 +32,10 @@ export type Patient = BaseEntity & { branchId: string branch?: Branch | null } + +export enum PatientAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/patient/index.ts b/libs/hcdc/src/entity/patient/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/patient/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/permission-rule/entity.ts b/libs/hcdc/src/entity/permission-rule/entity.ts similarity index 94% rename from apps/hcdc-access-service/src/domain/entity/permission-rule/entity.ts rename to libs/hcdc/src/entity/permission-rule/entity.ts index 5b3b5b41..e5a3f77e 100644 --- a/apps/hcdc-access-service/src/domain/entity/permission-rule/entity.ts +++ b/libs/hcdc/src/entity/permission-rule/entity.ts @@ -6,7 +6,7 @@ import { AuthAction, AuthSubject, SubjectEntityMapping, -} from 'src/domain/auth' +} from '../../auth' export type PermissionRule< TSubject extends keyof typeof AuthSubject = keyof typeof AuthSubject, diff --git a/libs/hcdc/src/entity/permission-rule/index.ts b/libs/hcdc/src/entity/permission-rule/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/permission-rule/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/entity.ts b/libs/hcdc/src/entity/print-form/entity.ts similarity index 80% rename from apps/hcdc-access-service/src/domain/entity/print-form/entity.ts rename to libs/hcdc/src/entity/print-form/entity.ts index cd13cf3a..1b522f0b 100644 --- a/apps/hcdc-access-service/src/domain/entity/print-form/entity.ts +++ b/libs/hcdc/src/entity/print-form/entity.ts @@ -26,3 +26,11 @@ export type PrintForm = BaseEntity & { branchId: string branch?: Branch | null } + +export enum PrintFormAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', + OverrideAuthor = 'OverrideAuthor', +} diff --git a/libs/hcdc/src/entity/print-form/index.ts b/libs/hcdc/src/entity/print-form/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/print-form/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/role/entity.ts b/libs/hcdc/src/entity/role/entity.ts similarity index 62% rename from apps/hcdc-access-service/src/domain/entity/role/entity.ts rename to libs/hcdc/src/entity/role/entity.ts index 5e6e874a..4821e6d9 100644 --- a/apps/hcdc-access-service/src/domain/entity/role/entity.ts +++ b/libs/hcdc/src/entity/role/entity.ts @@ -11,3 +11,12 @@ export type Role = BaseEntity & { branchId: string branch?: Branch | null } + +export enum RoleAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', + AssignToUser = 'AssignToUser', + AssignUserInline = 'AssignUserInline', +} diff --git a/libs/hcdc/src/entity/role/index.ts b/libs/hcdc/src/entity/role/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/role/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/sample-type/entity.ts b/libs/hcdc/src/entity/sample-type/entity.ts similarity index 64% rename from apps/hcdc-access-service/src/domain/entity/sample-type/entity.ts rename to libs/hcdc/src/entity/sample-type/entity.ts index 45270059..c66e1db0 100644 --- a/apps/hcdc-access-service/src/domain/entity/sample-type/entity.ts +++ b/libs/hcdc/src/entity/sample-type/entity.ts @@ -8,3 +8,10 @@ export type SampleType = BaseEntity & { branchId: string branch?: Branch | null } + +export enum SampleTypeAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/sample-type/index.ts b/libs/hcdc/src/entity/sample-type/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/sample-type/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/sample/entity.ts b/libs/hcdc/src/entity/sample/entity.ts similarity index 88% rename from apps/hcdc-access-service/src/domain/entity/sample/entity.ts rename to libs/hcdc/src/entity/sample/entity.ts index de1177a8..84e76ff1 100644 --- a/apps/hcdc-access-service/src/domain/entity/sample/entity.ts +++ b/libs/hcdc/src/entity/sample/entity.ts @@ -90,3 +90,14 @@ export const sampleInfoFieldNames = [ export type SampleInfo = Pick export type SampleResult = Pick + +export enum SampleAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + UpdateInfo = 'UpdateInfo', + UpdateResult = 'UpdateResult', + Delete = 'Delete', + ExportReport = 'ExportReport', + PrintResult = 'PrintResult', +} diff --git a/libs/hcdc/src/entity/sample/index.ts b/libs/hcdc/src/entity/sample/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/sample/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/test-category/entity.ts b/libs/hcdc/src/entity/test-category/entity.ts similarity index 66% rename from apps/hcdc-access-service/src/domain/entity/test-category/entity.ts rename to libs/hcdc/src/entity/test-category/entity.ts index b10f9571..7d40db0f 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-category/entity.ts +++ b/libs/hcdc/src/entity/test-category/entity.ts @@ -9,3 +9,10 @@ export type TestCategory = BaseEntity & { branchId: string branch?: Branch | null } + +export enum TestCategoryAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/test-category/index.ts b/libs/hcdc/src/entity/test-category/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/test-category/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/test-combo/entity.ts b/libs/hcdc/src/entity/test-combo/entity.ts similarity index 71% rename from apps/hcdc-access-service/src/domain/entity/test-combo/entity.ts rename to libs/hcdc/src/entity/test-combo/entity.ts index f40fc7a4..d35c9ade 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-combo/entity.ts +++ b/libs/hcdc/src/entity/test-combo/entity.ts @@ -12,3 +12,10 @@ export type TestCombo = BaseEntity & { branchId: string branch?: Branch | null } + +export enum TestComboAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/test-combo/index.ts b/libs/hcdc/src/entity/test-combo/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/test-combo/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/test-element/entity.ts b/libs/hcdc/src/entity/test-element/entity.ts similarity index 84% rename from apps/hcdc-access-service/src/domain/entity/test-element/entity.ts rename to libs/hcdc/src/entity/test-element/entity.ts index 72ad416b..43be88a0 100644 --- a/apps/hcdc-access-service/src/domain/entity/test-element/entity.ts +++ b/libs/hcdc/src/entity/test-element/entity.ts @@ -31,3 +31,10 @@ export type TestElement = BaseEntity & { branchId: string branch?: Branch | null } + +export enum TestElementAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/test-element/index.ts b/libs/hcdc/src/entity/test-element/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/test-element/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/test/entity.ts b/libs/hcdc/src/entity/test/entity.ts similarity index 87% rename from apps/hcdc-access-service/src/domain/entity/test/entity.ts rename to libs/hcdc/src/entity/test/entity.ts index a4ad716c..6c64cdec 100644 --- a/apps/hcdc-access-service/src/domain/entity/test/entity.ts +++ b/libs/hcdc/src/entity/test/entity.ts @@ -29,3 +29,10 @@ export type Test = BaseEntity & { branchId: string branch?: Branch | null } + +export enum TestAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} diff --git a/libs/hcdc/src/entity/test/index.ts b/libs/hcdc/src/entity/test/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/test/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/apps/hcdc-access-service/src/domain/entity/user/entity.ts b/libs/hcdc/src/entity/user/entity.ts similarity index 74% rename from apps/hcdc-access-service/src/domain/entity/user/entity.ts rename to libs/hcdc/src/entity/user/entity.ts index 06c866ae..38f49782 100644 --- a/apps/hcdc-access-service/src/domain/entity/user/entity.ts +++ b/libs/hcdc/src/entity/user/entity.ts @@ -16,3 +16,11 @@ export type User = BaseEntity & { roleIds: string[] roles?: (Role | null)[] } + +export enum UserAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', + ChangePassword = 'ChangePassword', +} diff --git a/libs/hcdc/src/entity/user/index.ts b/libs/hcdc/src/entity/user/index.ts new file mode 100644 index 00000000..796a3963 --- /dev/null +++ b/libs/hcdc/src/entity/user/index.ts @@ -0,0 +1 @@ +export * from './entity' diff --git a/libs/hcdc/src/index.ts b/libs/hcdc/src/index.ts index 872b8b60..3d03dbba 100644 --- a/libs/hcdc/src/index.ts +++ b/libs/hcdc/src/index.ts @@ -1,2 +1,4 @@ -export * from './resources' +// export * from './resources' export * from './exception' +export * from './entity' +export * from './auth' diff --git a/libs/nestjs-infra/src/mongo/mongo.common.ts b/libs/nestjs-infra/src/mongo/mongo.common.ts index 3e004ea1..4b0ba53e 100644 --- a/libs/nestjs-infra/src/mongo/mongo.common.ts +++ b/libs/nestjs-infra/src/mongo/mongo.common.ts @@ -13,22 +13,7 @@ import { ValidationArguments, ValidationOptions, } from 'class-validator' - -export const exampleMongoObjectId = { - example: '634180269de1f07e47bbf494', -} - -export const exampleMongoObjectIds = { - example: ['634180269de1f07e47bbf494'], - type: () => 'string', - isArray: true, -} - -export const exampleDate = { - format: 'date-time', - // example: '2018-03-20T09:12:28Z', - example: new Date('2018-03-20T09:12:28Z'), -} +import { exampleMongoObjectId } from '@diut/common' // https://github.com/typestack/class-transformer/issues/494 export const ExposeObjectId = () => diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 505ba39d..512cd59c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -142,9 +142,6 @@ importers: '@nestjs/swagger': specifier: ^7.3.0 version: 7.3.0(@nestjs/common@10.3.3)(@nestjs/core@10.3.3)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14) - '@ucast/mongo2js': - specifier: ^1.3.4 - version: 1.3.4 argon2: specifier: ^0.31.2 version: 0.31.2 @@ -371,6 +368,15 @@ importers: libs/hcdc: dependencies: + '@casl/ability': + specifier: ^6.5.0 + version: 6.5.0 + '@diut/common': + specifier: workspace:* + version: link:../common + '@ucast/mongo2js': + specifier: ^1.3.4 + version: 1.3.4 lodash: specifier: ^4.17.21 version: 4.17.21