Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Dec 13, 2023
1 parent a50b5a4 commit b841110
Show file tree
Hide file tree
Showing 47 changed files with 570 additions and 81 deletions.
3 changes: 2 additions & 1 deletion apps/levansy-access-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@casl/ability": "^6.5.0",
"@casl/mongoose": "^7.2.1",
"@diut/common": "workspace:*",
"@diut/levansy-common": "workspace:*",
"@diut/nest-core": "workspace:*",
Expand All @@ -33,9 +34,9 @@
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
"lodash": "^4.17.21",
"minio": "^7.1.3",
"mongodb": "^6.3.0",
"mongoose": "^8.0.2",
"minio": "^7.1.3",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseEntity, EntityExample } from './base-entity'

export type BioProduct = BaseEntity & {
name: string
index: number
name: string
}

export const exampleBioProduct: EntityExample<BioProduct> = {
Expand Down
1 change: 1 addition & 0 deletions apps/levansy-access-service/src/domain/entity/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './base-entity'

export * from './bio-product'
export * from './test-category'
22 changes: 22 additions & 0 deletions apps/levansy-access-service/src/domain/entity/test-category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BaseEntity, EntityExample } from './base-entity'

export type TestCategory = BaseEntity & {
index: number
name: string
reportIndex: number
}

export const exampleTestCategory: EntityExample<TestCategory> = {
index: {
example: 1,
description: 'thứ tự in trong kết quả',
},
name: {
example: 'XN Huyết học - Đông máu',
description: 'name',
},
reportIndex: {
example: 1,
description: 'thứ tự in trong báo cáo',
},
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './interface'

export * from './bio-product'
export * from './test-category'
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type SearchOptions<TEntity> = {
offset?: number
limit?: number
filter?: FilterQuery<TEntity>
sort?: { [key in keyof TEntity]?: SortOrder | { $meta: 'textScore' } }
sort?: { [key in keyof TEntity]: SortOrder | { $meta: 'textScore' } }
projection?:
| keyof TEntity
| (keyof TEntity)[]
Expand All @@ -31,15 +31,15 @@ export type SearchResult<TEntity extends BaseEntity> = {
}

export interface IRepository<TEntity extends BaseEntity> {
findById(id: string): Promise<TEntity>
findById(id: string): Promise<TEntity | null>

findOne(options?: {
filter?: FilterQuery<TEntity>
projection?:
| keyof TEntity
| (keyof TEntity)[]
| Record<keyof TEntity, number | boolean | object>
}): Promise<TEntity>
}): Promise<TEntity | null>

exists(filter: FilterQuery<TEntity>): Promise<boolean>

Expand All @@ -53,13 +53,13 @@ export interface IRepository<TEntity extends BaseEntity> {
id: string,
data: UpdateQuery<TEntity>,
options?: QueryOptions<TEntity>,
): Promise<TEntity>
): Promise<TEntity | null>

update(
filter: FilterQuery<TEntity>,
data: UpdateQuery<TEntity>,
options?: QueryOptions<TEntity>,
): Promise<TEntity>
): Promise<TEntity | null>

updateMany(
filter: FilterQuery<TEntity>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TestCategory } from 'src/domain/entity'
import { IRepository } from './interface'

export const TestCategoryRepositoryToken = Symbol('TestCategoryRepository')

export interface ITestCategoryRepository extends IRepository<TestCategory> {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IUseCase } from '../interface'
export type BioProductFindByIdUseCaseInput = {
id: string
}
export type BioProductFindByIdUseCaseOutput = BioProduct
export type BioProductFindByIdUseCaseOutput = BioProduct | null

@Injectable()
export class BioProductFindByIdUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IUseCase } from '../interface'
export type BioProductUpdateUseCaseInput = Partial<EntityData<BioProduct>> & {
id: string
}
export type BioProductUpdateUseCaseOutput = BioProduct
export type BioProductUpdateUseCaseOutput = BioProduct | null

@Injectable()
export class BioProductUpdateUseCase
Expand Down
6 changes: 6 additions & 0 deletions apps/levansy-access-service/src/domain/use-case/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ export * from './bio-product/find-by-id'
export * from './bio-product/update'
export * from './bio-product/delete'
export * from './bio-product/search'

export * from './test-category/create'
export * from './test-category/find-by-id'
export * from './test-category/update'
export * from './test-category/delete'
export * from './test-category/search'
11 changes: 11 additions & 0 deletions apps/levansy-access-service/src/domain/use-case/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { BioProductUpdateUseCase } from './bio-product/update'
import { BioProductFindByIdUseCase } from './bio-product/find-by-id'
import { BioProductDeleteUseCase } from './bio-product/delete'
import { BioProductSearchUseCase } from './bio-product/search'
import { TestCategoryCreateUseCase } from './test-category/create'
import { TestCategoryUpdateUseCase } from './test-category/update'
import { TestCategoryFindByIdUseCase } from './test-category/find-by-id'
import { TestCategoryDeleteUseCase } from './test-category/delete'
import { TestCategorySearchUseCase } from './test-category/search'

export const useCaseMetadata: ModuleMetadata = {
providers: [
Expand All @@ -13,5 +18,11 @@ export const useCaseMetadata: ModuleMetadata = {
BioProductUpdateUseCase,
BioProductDeleteUseCase,
BioProductSearchUseCase,

TestCategoryCreateUseCase,
TestCategoryFindByIdUseCase,
TestCategoryUpdateUseCase,
TestCategoryDeleteUseCase,
TestCategorySearchUseCase,
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Inject, Injectable } from '@nestjs/common'

import {
TestCategoryRepositoryToken,
ITestCategoryRepository,
} from 'src/domain/interface'
import { TestCategory, EntityData } from 'src/domain/entity'
import { IUseCase } from '../interface'

export type TestCategoryCreateUseCaseInput = EntityData<TestCategory>
export type TestCategoryCreateUseCaseOutput = TestCategory

@Injectable()
export class TestCategoryCreateUseCase
implements
IUseCase<TestCategoryCreateUseCaseInput, TestCategoryCreateUseCaseOutput>
{
constructor(
@Inject(TestCategoryRepositoryToken)
private readonly testCategoryRepository: ITestCategoryRepository,
) {}

async handle(input: TestCategoryCreateUseCaseInput) {
return this.testCategoryRepository.create(input)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Inject, Injectable } from '@nestjs/common'

import {
TestCategoryRepositoryToken,
ITestCategoryRepository,
} from 'src/domain/interface'
import { TestCategory } from 'src/domain/entity'
import { IUseCase } from '../interface'

export type TestCategoryDeleteUseCaseInput = {
id: string
}
export type TestCategoryDeleteUseCaseOutput = TestCategory

@Injectable()
export class TestCategoryDeleteUseCase
implements
IUseCase<TestCategoryDeleteUseCaseInput, TestCategoryDeleteUseCaseOutput>
{
constructor(
@Inject(TestCategoryRepositoryToken)
private readonly testCategoryRepository: ITestCategoryRepository,
) {}

handle(input: TestCategoryDeleteUseCaseInput) {
return this.testCategoryRepository.deleteById(input.id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Inject, Injectable } from '@nestjs/common'

import {
TestCategoryRepositoryToken,
ITestCategoryRepository,
} from 'src/domain/interface'
import { TestCategory } from 'src/domain/entity'
import { IUseCase } from '../interface'

export type TestCategoryFindByIdUseCaseInput = {
id: string
}
export type TestCategoryFindByIdUseCaseOutput = TestCategory | null

@Injectable()
export class TestCategoryFindByIdUseCase
implements
IUseCase<
TestCategoryFindByIdUseCaseInput,
TestCategoryFindByIdUseCaseOutput
>
{
constructor(
@Inject(TestCategoryRepositoryToken)
private readonly testCategoryRepository: ITestCategoryRepository,
) {}

handle(input: TestCategoryFindByIdUseCaseInput) {
return this.testCategoryRepository.findById(input.id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Inject, Injectable } from '@nestjs/common'

import {
TestCategoryRepositoryToken,
ITestCategoryRepository,
SearchOptions,
SearchResult,
} from 'src/domain/interface'
import { TestCategory } from 'src/domain/entity'
import { IUseCase } from '../interface'

export type TestCategorySearchUseCaseInput = SearchOptions<TestCategory>
export type TestCategorySearchUseCaseOutput = SearchResult<TestCategory>

@Injectable()
export class TestCategorySearchUseCase
implements
IUseCase<TestCategorySearchUseCaseInput, TestCategorySearchUseCaseOutput>
{
constructor(
@Inject(TestCategoryRepositoryToken)
private readonly testCategoryRepository: ITestCategoryRepository,
) {}

handle(input: TestCategorySearchUseCaseInput) {
return this.testCategoryRepository.search(input)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Inject, Injectable } from '@nestjs/common'

import {
TestCategoryRepositoryToken,
ITestCategoryRepository,
} from 'src/domain/interface'
import { TestCategory, EntityData } from 'src/domain/entity'
import { IUseCase } from '../interface'

export type TestCategoryUpdateUseCaseInput = Partial<
EntityData<TestCategory>
> & {
id: string
}
export type TestCategoryUpdateUseCaseOutput = TestCategory | null

@Injectable()
export class TestCategoryUpdateUseCase
implements
IUseCase<TestCategoryUpdateUseCaseInput, TestCategoryUpdateUseCaseOutput>
{
constructor(
@Inject(TestCategoryRepositoryToken)
private readonly testCategoryRepository: ITestCategoryRepository,
) {}

handle(input: TestCategoryUpdateUseCaseInput) {
const { id, ...data } = input
return this.testCategoryRepository.updateById(id, data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { COLLECTION } from '../collections'
})
export class BioProductSchema extends BaseSchema {
@Prop({ required: true })
name: string
index: number

@Prop({ required: true })
index: number
name: string
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BaseSchema } from '@diut/nest-core'

import { COLLECTION } from './collections'
import { BioProductSchema } from './bio-product/schema'
import { BioProductSchema } from './bio-product'
import { TestCategorySchema } from './test-category'

export const COLLECTION_CLASS: Record<COLLECTION, typeof BaseSchema> = {
[COLLECTION.BIO_PRODUCT]: BioProductSchema,
Expand All @@ -12,7 +13,7 @@ export const COLLECTION_CLASS: Record<COLLECTION, typeof BaseSchema> = {
// [COLLECTION.SAMPLE]: Sample,
// [COLLECTION.SAMPLE_TYPE]: SampleType,
// [COLLECTION.TEST]: Test,
// [COLLECTION.TEST_CATEGORY]: TestCategory,
[COLLECTION.TEST_CATEGORY]: TestCategorySchema,
// [COLLECTION.TEST_COMBO]: TestCombo,
// [COLLECTION.TEST_ELEMENT]: TestElement,
// [COLLECTION.USER]: User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export enum COLLECTION {
// USER = 'users',
// PATIENT = 'patients',
// DOCTOR = 'doctors',
// TEST_CATEGORY = 'test_categories',
TEST_CATEGORY = 'test_categories',
// TEST = 'tests',
// TEST_ELEMENT = 'test_elements',
// PATIENT_TYPE = 'patient_types',
Expand Down
11 changes: 10 additions & 1 deletion apps/levansy-access-service/src/infrastructure/mongo/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { ModuleMetadata } from '@nestjs/common'
import { ConfigModule, MongoModule } from '@diut/nest-core'

import { MongoConfig, loadMongoConfig } from '../config'
import { BioProductRepositoryToken } from 'src/domain'
import {
BioProductRepositoryToken,
TestCategoryRepositoryToken,
} from 'src/domain'
import { BioProductSchema, BioProductRepository } from './bio-product'
import { TestCategoryRepository, TestCategorySchema } from './test-category'

export const mongoMetadata: ModuleMetadata = {
imports: [
Expand All @@ -15,11 +19,16 @@ export const mongoMetadata: ModuleMetadata = {
}),
}),
MongoModule.forFeature(BioProductSchema),
MongoModule.forFeature(TestCategorySchema),
],
providers: [
{
provide: BioProductRepositoryToken,
useClass: BioProductRepository,
},
{
provide: TestCategoryRepositoryToken,
useClass: TestCategoryRepository,
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './repository'
export * from './schema'
Loading

0 comments on commit b841110

Please sign in to comment.