-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
960 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/hcdc-access-service/src/domain/entity/auth/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { exampleMongoObjectId } from '@diut/nest-core' | ||
|
||
import { EntityDataExample } from '../base-entity' | ||
import { AuthActionValues } from './action' | ||
import { PermissionRule } from './entity' | ||
import { AuthSubjectValues } from './subject' | ||
|
||
export const examplePermissionRule = { | ||
subject: { | ||
example: AuthSubjectValues[0], | ||
enum: AuthSubjectValues, | ||
}, | ||
action: { | ||
example: AuthActionValues[0], | ||
enum: AuthActionValues, | ||
}, | ||
inverted: { | ||
example: false, | ||
default: false, | ||
required: false, | ||
}, | ||
conditions: { | ||
example: { _id: { $eq: exampleMongoObjectId.example } }, | ||
}, | ||
} satisfies EntityDataExample<PermissionRule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,78 @@ | ||
import { exampleMongoObjectId } from '@diut/nest-core' | ||
import { ApiPropertyOptions } from '@nestjs/swagger' | ||
import { omit } from 'lodash' | ||
|
||
export type BaseEntity = { | ||
_id: string | ||
|
||
createdAt: Date | ||
updatedAt: Date | ||
} | ||
|
||
export type EntityData<TEntity extends BaseEntity> = Omit< | ||
TEntity, | ||
export const exampleBaseEntity = { | ||
_id: exampleMongoObjectId, | ||
createdAt: { | ||
format: 'date-time', | ||
example: '2022-08-20T16:00:00.000Z', | ||
}, | ||
updatedAt: { | ||
format: 'date-time', | ||
example: '2022-08-20T16:00:00.000Z', | ||
}, | ||
} satisfies EntityExample<BaseEntity> | ||
|
||
export const baseEntityKeys: (keyof BaseEntity)[] = [ | ||
'_id', | ||
'createdAt', | ||
'updatedAt', | ||
] | ||
|
||
export type EntityData<TEntity> = Omit<TEntity, keyof BaseEntity> | ||
|
||
export type EntityExample<TEntity> = { | ||
[key in keyof Required<EntityData<TEntity>>]: Omit< | ||
ApiPropertyOptions, | ||
'example' | 'examples' | ||
> & { | ||
example?: EntityData<TEntity>[key] | ||
examples?: EntityData<TEntity>[key][] | ||
} | ||
} | ||
|
||
export type EntityDataExample<TEntity> = Omit< | ||
EntityExample<TEntity>, | ||
keyof BaseEntity | ||
> | ||
|
||
export type EntityExample<TEntity extends BaseEntity> = { | ||
[key in keyof EntityData<TEntity>]: { | ||
example: EntityData<TEntity>[key] | ||
description: string | ||
export function omitBaseEntityKeys<TEntity>( | ||
example: EntityExample<TEntity>, | ||
): EntityDataExample<TEntity> { | ||
return omit(example, ...baseEntityKeys) | ||
} | ||
|
||
export function populateEntityDataExample<TEntity>( | ||
exampleData: EntityDataExample<TEntity>, | ||
): EntityExample<TEntity> { | ||
return { | ||
...exampleBaseEntity, | ||
...exampleData, | ||
} as EntityExample<TEntity> | ||
} | ||
|
||
export function extractExampleEntity<TEntity>( | ||
exampleData: EntityDataExample<TEntity>, | ||
includeBaseEntityKeys = true, | ||
) { | ||
let example: object = populateEntityDataExample(exampleData) | ||
if (!includeBaseEntityKeys) { | ||
example = omitBaseEntityKeys(example) | ||
} | ||
|
||
const rv: object = {} | ||
|
||
Object.keys(example).forEach((key) => { | ||
rv[key] = example[key].example | ||
}) | ||
|
||
return rv as TEntity | ||
} |
8 changes: 3 additions & 5 deletions
8
apps/hcdc-access-service/src/domain/entity/bio-product/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import { EntityExample } from '../base-entity' | ||
import { EntityDataExample } from '../base-entity' | ||
import { BioProduct } from './entity' | ||
|
||
export const exampleBioProduct: EntityExample<BioProduct> = { | ||
export const exampleBioProduct = { | ||
index: { | ||
example: 1, | ||
description: 'index', | ||
}, | ||
name: { | ||
example: 'CHIV Advia centaur', | ||
description: 'name', | ||
}, | ||
} | ||
} satisfies EntityDataExample<BioProduct> |
11 changes: 11 additions & 0 deletions
11
apps/hcdc-access-service/src/domain/entity/branch/entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
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 & { | ||
index: number | ||
name: string | ||
|
||
address: string | ||
|
||
type: BranchType | ||
} |
17 changes: 8 additions & 9 deletions
17
apps/hcdc-access-service/src/domain/entity/branch/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { exampleMongoObjectIds } from '@diut/nest-core' | ||
import { EntityExample } from '../base-entity' | ||
import { Branch } from './entity' | ||
import { EntityDataExample } from '../base-entity' | ||
import { Branch, BranchType } from './entity' | ||
|
||
export const exampleBranch: EntityExample<Branch> = { | ||
export const exampleBranch = { | ||
index: { | ||
example: 1, | ||
description: 'index', | ||
}, | ||
name: { | ||
example: 'HCDC Ba tháng hai', | ||
description: 'tên chi nhánh', | ||
}, | ||
address: { | ||
example: 'Ba tháng hai', | ||
description: 'địa chỉ chi nhánh', | ||
example: 'đường 3/2', | ||
}, | ||
} | ||
type: { | ||
enum: BranchType, | ||
}, | ||
} satisfies EntityDataExample<Branch> |
18 changes: 8 additions & 10 deletions
18
apps/hcdc-access-service/src/domain/entity/role/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import { exampleMongoObjectIds } from '@diut/nest-core' | ||
|
||
import { EntityExample } from '../base-entity' | ||
import { EntityDataExample, extractExampleEntity } from '../base-entity' | ||
import { Role } from './entity' | ||
import { examplePermissionRule } from '../auth' | ||
import { exampleBranch } from '../branch' | ||
|
||
export const exampleRole: EntityExample<Role> = { | ||
export const exampleRole = { | ||
index: { | ||
example: 1, | ||
description: 'index', | ||
}, | ||
name: { | ||
example: 'Admin', | ||
description: 'tên phân quyền', | ||
}, | ||
description: { | ||
example: 'phân quyền cao nhất', | ||
description: 'mô tả', | ||
}, | ||
policy: { | ||
example: [], | ||
description: 'policy', | ||
example: [extractExampleEntity(examplePermissionRule, false)], | ||
}, | ||
branchIds: exampleMongoObjectIds, | ||
branches: { | ||
example: [], | ||
description: 'các chi nhánh khả dụng cho phân quyền này', | ||
example: [extractExampleEntity(exampleBranch)], | ||
required: false, | ||
}, | ||
} | ||
} satisfies EntityDataExample<Role> |
9 changes: 3 additions & 6 deletions
9
apps/hcdc-access-service/src/domain/entity/test-category/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import { EntityExample } from '../base-entity' | ||
import { EntityDataExample } from '../base-entity' | ||
import { TestCategory } from './entity' | ||
|
||
export const exampleTestCategory: EntityExample<TestCategory> = { | ||
export const exampleTestCategory = { | ||
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', | ||
}, | ||
} | ||
} satisfies EntityDataExample<TestCategory> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { exampleMongoObjectIds } from '@diut/nest-core' | ||
|
||
import { EntityExample } from '../base-entity' | ||
import { EntityDataExample, extractExampleEntity } from '../base-entity' | ||
import { User } from './entity' | ||
import { exampleBranch } from '../branch' | ||
|
||
export const exampleUser: EntityExample<User> = { | ||
export const exampleUser = { | ||
username: { | ||
example: 'levana', | ||
description: 'username', | ||
}, | ||
name: { | ||
example: 'Lê Văn A', | ||
description: 'name', | ||
}, | ||
phoneNumber: { | ||
example: '1234567890', | ||
description: 'phoneNumber', | ||
}, | ||
passwordHash: { | ||
example: 'hashed_password', | ||
description: 'passwordHash', | ||
}, | ||
branchIds: exampleMongoObjectIds, | ||
} | ||
branches: { | ||
example: [extractExampleEntity(exampleBranch)], | ||
isArray: true, | ||
}, | ||
} satisfies EntityDataExample<User> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.