Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sequence] Configuration Changes #78

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/sequence/src/constants/sequence.constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
type MasterDataType = {
typeCode: string
format: string
startMonth?: number
registerDate?: Date
Expand All @@ -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%%',
}
3 changes: 3 additions & 0 deletions packages/sequence/src/dto/gen-sequence.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export class GenerateFormattedSequenceDto {
@IsString()
tenantCode: string

@IsString()
typeCode: string

/**
* Type code for specific sequence classification.
*/
Expand Down
62 changes: 62 additions & 0 deletions packages/sequence/src/sequences.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -413,6 +415,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -456,6 +459,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode : 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -499,6 +503,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode : 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -542,6 +547,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -628,6 +635,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -714,6 +723,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -757,6 +767,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -800,6 +811,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -843,6 +855,7 @@ describe('SequencesService', () => {
{
tenantCode: tenantCode,
date : new Date("2024-11-27T13:56:39+07:00"),
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -884,6 +897,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -1020,6 +1036,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand Down Expand Up @@ -1062,6 +1079,7 @@ describe('SequencesService', () => {
const result = await service.generateSequenceItem(
{
tenantCode: tenantCode,
typeCode: 'sequence',
params: {
code1: 'TODO',
},
Expand All @@ -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);
})
});

});
6 changes: 3 additions & 3 deletions packages/sequence/src/sequences.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ export class SequencesService implements ISequenceService {
dto: GenerateFormattedSequenceDto,
options: { invokeContext: IInvoke },
): Promise<SequenceEntity> {
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({
pk: generalMasterPk,
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 = [
Expand Down