Skip to content

Commit

Permalink
print-form + test: todo schema
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Jan 26, 2024
1 parent 8fb0a42 commit 72d7f8b
Show file tree
Hide file tree
Showing 21 changed files with 245 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apps/hcdc-access-service/src/domain/auth/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
DoctorAction,
InstrumentAction,
PatientTypeAction,
PrintFormAction,
RoleAction,
SampleTypeAction,
TestAction,
TestCategoryAction,
UserAction,
} from '../entity'
Expand All @@ -26,6 +28,8 @@ export const AuthAction = {
Doctor: stringEnumValues(DoctorAction),
PatientType: stringEnumValues(PatientTypeAction),
Diagnosis: stringEnumValues(DiagnosisAction),
PrintForm: stringEnumValues(PrintFormAction),
Test: stringEnumValues(TestAction),
} satisfies Record<keyof typeof AuthSubject, string[]>

export const AuthActionValues = [
Expand Down
6 changes: 6 additions & 0 deletions apps/hcdc-access-service/src/domain/auth/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
Doctor,
Instrument,
PatientType,
PrintForm,
Role,
SampleType,
Test,
TestCategory,
User,
} from '../entity'
Expand All @@ -26,6 +28,8 @@ export const AuthSubject = {
Doctor: 'Doctor',
PatientType: 'PatientType',
Diagnosis: 'Diagnosis',
PrintForm: 'PrintForm',
Test: 'Test',
} satisfies Record<keyof RecordTypes, keyof RecordTypes>

export type AuthSubjectUnionType = keyof typeof AuthSubject
Expand All @@ -46,4 +50,6 @@ export type SubjectEntityMapping = {
Doctor: Doctor
PatientType: PatientType
Diagnosis: Diagnosis
PrintForm: PrintForm
Test: Test
}
4 changes: 0 additions & 4 deletions apps/hcdc-access-service/src/domain/entity/branch/entity.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { stringEnumValues } from '@diut/common'

import { BaseEntity } from '../base-entity'

export enum BranchType {
Internal = 'Internal',
External = 'External',
}

export const BranchTypeValues = stringEnumValues(BranchType)

export type Branch = BaseEntity & {
displayIndex: number
name: string
Expand Down
2 changes: 2 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export * from './role'
export * from './user'
export * from './branch'
export * from './permission-rule'
export * from './print-form'
export * from './test'
14 changes: 14 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/print-form/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import '@casl/mongoose'

export enum PrintFormAction {
Create = 'Create',
Read = 'Read',
Update = 'Update',
Delete = 'Delete',
}

declare module '@casl/mongoose' {
interface RecordTypes {
PrintForm: true
}
}
25 changes: 25 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/print-form/entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseEntity } from '../base-entity'
import { Branch } from '../branch'

export enum PrintTemplate {
FormChung = 'FormChung',
FormHIV = 'FormHIV',
FormPap = 'FormPap',
FormSoiNhuom = 'FormSoiNhuom',
FormTD = 'FormTD',
}

export type PrintForm = BaseEntity & {
displayIndex: number
name: string
isA4: boolean
isAuthorLocked: boolean
authorTitle: string
authorName: string
titleMargin: number

template: PrintTemplate

branchId: string
branch?: Branch | null
}
29 changes: 29 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/print-form/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { exampleMongoObjectId } from '@diut/nest-core'

import { EntityDataExample } from '../base-entity'
import { PrintForm, PrintTemplate } from './entity'

export const examplePrintForm = {
displayIndex: {
example: 1,
},
name: {
example: 'CHIV Advia centaur',
},
isA4: {},
isAuthorLocked: {},
authorTitle: {
example: 'Chức vụ',
},
authorName: {
example: 'Nguyễn Văn A',
},
titleMargin: { example: 12 },
template: {
enum: PrintTemplate,
},
branchId: exampleMongoObjectId,
branch: {
required: false,
},
} satisfies EntityDataExample<PrintForm>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './entity'
export * from './example'
export * from './auth'
14 changes: 14 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/test/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import '@casl/mongoose'

export enum TestAction {
Create = 'Create',
Read = 'Read',
Update = 'Update',
Delete = 'Delete',
}

declare module '@casl/mongoose' {
interface RecordTypes {
Test: true
}
}
12 changes: 12 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/test/entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BaseEntity } from '../base-entity'
import { Branch } from '../branch'

export type Test = BaseEntity & {
displayIndex: number
name: string
shouldNotPrint: boolean
shouldDisplayWithChildren: boolean

branchId: string
branch?: Branch | null
}
19 changes: 19 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/test/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { exampleMongoObjectId } from '@diut/nest-core'

import { EntityDataExample } from '../base-entity'
import { Test } from './entity'

export const exampleTest = {
displayIndex: {
example: 1,
},
name: {
example: 'CHIV Advia centaur',
},
shouldNotPrint: {},
shouldDisplayWithChildren: {},
branchId: exampleMongoObjectId,
branch: {
required: false,
},
} satisfies EntityDataExample<Test>
3 changes: 3 additions & 0 deletions apps/hcdc-access-service/src/domain/entity/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './entity'
export * from './example'
export * from './auth'
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export * from './branch'
export * from './role'
export * from './instrument'
export * from './sample-type'
export * from './print-form'
export * from './test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PrintForm } from 'src/domain/entity'
import { IRepository } from './interface'

export const PrintFormRepositoryToken = Symbol('PrintFormRepository')

export interface IPrintFormRepository extends IRepository<PrintForm> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Test } from 'src/domain/entity'
import { IRepository } from './interface'

export const TestRepositoryToken = Symbol('TestRepository')

export interface ITestRepository extends IRepository<Test> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './repository'
export * from './schema'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { InjectModel } from '@nestjs/mongoose'
import { MongoRepository } from '@diut/nest-core'
import { Model } from 'mongoose'

import { IPrintFormRepository } from 'src/domain'
import { PrintFormSchema } from './schema'

export class PrintFormRepository
extends MongoRepository<PrintFormSchema>
implements IPrintFormRepository
{
constructor(
@InjectModel(PrintFormSchema.name) model: Model<PrintFormSchema>,
) {
super(model)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Prop, Schema } from '@nestjs/mongoose'
import { BaseSchema, baseSchemaOptions } from '@diut/nest-core'
import { Types } from 'mongoose'

import { COLLECTION } from '../collections'
import { BranchSchema } from '../branch'

@Schema({
...baseSchemaOptions,
collection: COLLECTION.BIO_PRODUCT,
virtuals: {
branch: {
options: {
ref: BranchSchema.name,
localField: 'branchId',
foreignField: '_id',
justOne: true,
},
},
},
})
export class PrintFormSchema extends BaseSchema {
@Prop({ required: true })
displayIndex: number

@Prop({ required: true })
name: string

@Prop({ required: true, type: Types.ObjectId })
branchId: string
branch?: BranchSchema | null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './repository'
export * from './schema'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { InjectModel } from '@nestjs/mongoose'
import { MongoRepository } from '@diut/nest-core'
import { Model } from 'mongoose'

import { ITestRepository } from 'src/domain'
import { TestSchema } from './schema'

export class TestRepository
extends MongoRepository<TestSchema>
implements ITestRepository
{
constructor(@InjectModel(TestSchema.name) model: Model<TestSchema>) {
super(model)
}
}
32 changes: 32 additions & 0 deletions apps/hcdc-access-service/src/infrastructure/mongo/test/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Prop, Schema } from '@nestjs/mongoose'
import { BaseSchema, baseSchemaOptions } from '@diut/nest-core'
import { Types } from 'mongoose'

import { COLLECTION } from '../collections'
import { BranchSchema } from '../branch'

@Schema({
...baseSchemaOptions,
collection: COLLECTION.BIO_PRODUCT,
virtuals: {
branch: {
options: {
ref: BranchSchema.name,
localField: 'branchId',
foreignField: '_id',
justOne: true,
},
},
},
})
export class TestSchema extends BaseSchema {
@Prop({ required: true })
displayIndex: number

@Prop({ required: true })
name: string

@Prop({ required: true, type: Types.ObjectId })
branchId: string
branch?: BranchSchema | null
}

0 comments on commit 72d7f8b

Please sign in to comment.