-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from mbc-net/develop
update sequence with master data
- Loading branch information
Showing
13 changed files
with
1,286 additions
and
289 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const HEADER_TENANT_CODE = 'x-tenant-code' | ||
export const TENANT_COMMON = 'common' | ||
export const DEFAULT_TENANT_CODE = 'single' |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DetailKey } from './detail-key.interface' | ||
|
||
export interface IMasterDataProvider { | ||
/** | ||
* Get the data for a specific key. | ||
* @param key - The key to identify the data. | ||
* @returns A promise that resolves to the data. | ||
*/ | ||
getData(key: DetailKey): Promise<any> | ||
} |
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,13 @@ | ||
type MasterDataType = { | ||
typeCode: string | ||
format: string | ||
startMonth?: number | ||
registerDate?: Date | ||
} | ||
|
||
export const DEFAULT_MASTER_DATA = Symbol('DEFAULT_MASTER_DATA') | ||
|
||
export const DEFAULT_VALUE_MASTER_DATA: MasterDataType = { | ||
typeCode: 'sequence', | ||
format: '%%no%%', | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export class SequenceEntity { | ||
id: string | ||
no: number | ||
formattedNo: string | ||
issuedAt: Date | ||
|
||
constructor(partial: Partial<SequenceEntity>) { | ||
Object.assign(this, partial) | ||
} | ||
} |
32 changes: 30 additions & 2 deletions
32
packages/sequence/src/interfaces/sequence-service.interface.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,14 +1,42 @@ | ||
import { DataEntity, DetailKey, IInvoke } from '@mbc-cqrs-serverless/core' | ||
|
||
import { GenSequenceDto } from '../dto/gen-sequence.dto' | ||
import { | ||
GenerateFormattedSequenceDto, | ||
GenSequenceDto, | ||
} from '../dto/gen-sequence.dto' | ||
import { SequenceEntity } from '../entities/sequence.entity' | ||
|
||
export interface ISequenceService { | ||
/** | ||
* Get the current sequence by a specific key. | ||
* @param key - The key to identify the sequence details. | ||
* @returns A promise that resolves to the current sequence's data entity. | ||
*/ | ||
getCurrentSequence(key: DetailKey): Promise<DataEntity> | ||
|
||
/** | ||
* Generate a new sequence based on the provided parameters. | ||
* @param dto - The data transfer object containing generation parameters. | ||
* @param opts - Additional options including invocation context. | ||
* @returns A promise that resolves to the newly generated sequence's data entity. | ||
*/ | ||
genNewSequence( | ||
dto: GenSequenceDto, | ||
opts: { | ||
options: { | ||
invokeContext: IInvoke | ||
}, | ||
): Promise<DataEntity> | ||
|
||
/** | ||
* Generate a new sequence with a specified format. | ||
* @param dto - The data transfer object containing parameters for formatted sequence generation. | ||
* @param opts - Additional options including invocation context. | ||
* @returns A promise that resolves to the newly generated formatted sequence's data entity. | ||
*/ | ||
generateSequenceItem( | ||
dto: GenerateFormattedSequenceDto, | ||
options: { | ||
invokeContext: IInvoke | ||
}, | ||
): Promise<SequenceEntity> | ||
} |
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,32 @@ | ||
import { | ||
DetailKey, | ||
DynamoDbService, | ||
IMasterDataProvider, | ||
} from '@mbc-cqrs-serverless/core' | ||
import { Inject, Injectable, Optional } from '@nestjs/common' | ||
|
||
import { DEFAULT_MASTER_DATA } from './constants/sequence.constant' | ||
|
||
Injectable() | ||
export class SequenceMasterDataProvider implements IMasterDataProvider { | ||
private tableName | ||
constructor( | ||
private readonly dynamoDbService: DynamoDbService, | ||
@Inject(DEFAULT_MASTER_DATA) | ||
@Optional() | ||
private readonly defaultValue: Record<string, any>, | ||
) { | ||
this.tableName = dynamoDbService.getTableName('master', 'data') | ||
} | ||
async getData(key: DetailKey): Promise<any> { | ||
try { | ||
const item = await this.dynamoDbService.getItem(this.tableName, key) | ||
if (!item) { | ||
return this.defaultValue | ||
} | ||
return item | ||
} catch (error) { | ||
return this.defaultValue | ||
} | ||
} | ||
} |
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.