diff --git a/packages/sequence/src/constants/sequence.constant.ts b/packages/sequence/src/constants/sequence.constant.ts index 0cd24d0..fb42f74 100644 --- a/packages/sequence/src/constants/sequence.constant.ts +++ b/packages/sequence/src/constants/sequence.constant.ts @@ -1,5 +1,4 @@ type MasterDataType = { - typeCode: string format: string startMonth?: number registerDate?: Date @@ -8,6 +7,5 @@ type MasterDataType = { export const DEFAULT_MASTER_DATA = Symbol('DEFAULT_MASTER_DATA') export const DEFAULT_VALUE_MASTER_DATA: MasterDataType = { - typeCode: 'sequence', format: '%%no%%', } diff --git a/packages/sequence/src/dto/gen-sequence.dto.ts b/packages/sequence/src/dto/gen-sequence.dto.ts index becc4a7..50508f5 100644 --- a/packages/sequence/src/dto/gen-sequence.dto.ts +++ b/packages/sequence/src/dto/gen-sequence.dto.ts @@ -97,6 +97,9 @@ export class GenerateFormattedSequenceDto { @IsString() tenantCode: string + @IsString() + typeCode: string + /** * Type code for specific sequence classification. */ diff --git a/packages/sequence/src/sequences.service.spec.ts b/packages/sequence/src/sequences.service.spec.ts index 33bf49b..4427e73 100644 --- a/packages/sequence/src/sequences.service.spec.ts +++ b/packages/sequence/src/sequences.service.spec.ts @@ -329,6 +329,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -371,6 +372,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', date: new Date("2024-11-27T13:44:16+07:00"), params: { code1: 'TODO', @@ -413,6 +415,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -456,6 +459,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode : 'sequence', params: { code1: 'TODO', }, @@ -499,6 +503,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode : 'sequence', params: { code1: 'TODO', }, @@ -542,6 +547,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -585,6 +591,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', date : new Date("2024-11-27T13:54:04+07:00"), params: { code1: 'TODO', @@ -628,6 +635,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -671,6 +679,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', date : new Date("2024-11-27T13:56:39+07:00"), params: { code1: 'TODO', @@ -714,6 +723,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -757,6 +767,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -800,6 +811,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -843,6 +855,7 @@ describe('SequencesService', () => { { tenantCode: tenantCode, date : new Date("2024-11-27T13:56:39+07:00"), + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -884,6 +897,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -927,6 +941,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', rotateBy: RotateByEnum.NONE, date: new Date("2024-11-27T13:44:16+07:00"), params: { @@ -973,6 +988,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', date: new Date("2024-11-27T13:44:16+07:00"), rotateBy: RotateByEnum.NONE, params: { @@ -1020,6 +1036,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -1062,6 +1079,7 @@ describe('SequencesService', () => { const result = await service.generateSequenceItem( { tenantCode: tenantCode, + typeCode: 'sequence', params: { code1: 'TODO', }, @@ -1072,6 +1090,50 @@ describe('SequencesService', () => { ); expect(result).toEqual(mockSequenceResponse); }) + it('should call generateSequenceItem with register date, format is %%code1%%-%%fiscal_year%%-%%no%%', async () => { + const mockMasterData = { + typeCode: 'sequence', + format: '%%code1%%-%%fiscal_year%%-%%no%%', + registerDate: new Date("2020-01-01"), + } + const mockUpdate ={ + "code": "sequence#PI#2024", + "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", + "createdIp": "127.0.0.1", + "tenantCode": "MBC", + "type": "sequence", + "createdAt": "2024-11-27T17:45:45+07:00", + "updatedIp": "127.0.0.1", + "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", + "requestId": "9fc8d555-f200-4f5d-b3e0-07d2fa9dcd16", + "name": "fiscal_yearly", + "sk": "sequence#PI#2024", + "pk": "SEQ#MBC", + "seq": 2, + "updatedAt": "2024-11-27T17:46:36+07:00" + } + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + const mockSequenceResponse = new SequenceEntity({ + id: "SEQ#MBC#sequence#PI#2024", + no: 2, + formattedNo:"PI-5-2", + issuedAt: new Date("2024-11-27T17:46:36+07:00"), + }) + const result = await service.generateSequenceItem( + { + tenantCode: tenantCode, + typeCode: 'sequence', + params: { + code1: 'PI', + }, + date: new Date("2024-11-27T17:46:36+07:00"), + rotateBy: RotateByEnum.FISCAL_YEARLY, + }, + optionsMock + ); + expect(result).toEqual(mockSequenceResponse); + }) }); }); diff --git a/packages/sequence/src/sequences.service.ts b/packages/sequence/src/sequences.service.ts index a646e75..da001a4 100644 --- a/packages/sequence/src/sequences.service.ts +++ b/packages/sequence/src/sequences.service.ts @@ -117,10 +117,10 @@ export class SequencesService implements ISequenceService { dto: GenerateFormattedSequenceDto, options: { invokeContext: IInvoke }, ): Promise { - const { date, rotateBy, tenantCode, params } = dto + const { date, rotateBy, tenantCode, params, typeCode } = dto const generalMasterPk = masterPk(tenantCode) - const generalMasterSk = `SEQ${KEY_SEPARATOR}${params?.code1}` + const generalMasterSk = `SEQ${KEY_SEPARATOR}${typeCode}` this.logger.log('general master pk: ', generalMasterPk) this.logger.log('general master sk: ', generalMasterSk) const masterData = await this.masterDataProvider.getData({ @@ -128,7 +128,7 @@ export class SequencesService implements ISequenceService { sk: generalMasterSk, }) // Get master data for the tenant - const { format, typeCode, registerDate, startMonth } = masterData + const { format, registerDate, startMonth } = masterData const pk = seqPk(tenantCode) // Construct the sort key for the sequence let sk = [