Skip to content

Commit 441b765

Browse files
committed
CCM-12327: increment lock number on sftp updates
1 parent 01efc4a commit 441b765

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lambdas/sftp-letters/src/__tests__/infra/template-lock-repository.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ describe('TemplateLockRepository', () => {
4444
'#sftpSendLockTime': 'sftpSendLockTime',
4545
'#supplier': 'supplier',
4646
'#supplierReferences': 'supplierReferences',
47+
'#lockNumber': 'lockNumber',
4748
},
4849
ExpressionAttributeValues: {
4950
':condition_2_sftpSendLockTime': mockDate.getTime() + sendLockTtlMs,
5051
':sftpSendLockTime': mockDate.getTime(),
5152
':supplier': 'supplier-reference',
53+
':lockNumber': 1,
5254
},
5355
ConditionExpression:
5456
'attribute_not_exists (#sftpSendLockTime) OR #sftpSendLockTime > :condition_2_sftpSendLockTime',
@@ -58,7 +60,7 @@ describe('TemplateLockRepository', () => {
5860
},
5961
TableName: templatesTableName,
6062
UpdateExpression:
61-
'SET #sftpSendLockTime = :sftpSendLockTime, #supplierReferences.#supplier = :supplier',
63+
'SET #sftpSendLockTime = :sftpSendLockTime, #supplierReferences.#supplier = :supplier ADD #lockNumber :lockNumber',
6264
});
6365
});
6466

@@ -109,16 +111,19 @@ describe('TemplateLockRepository', () => {
109111
expect(mocks.client).toHaveReceivedCommandWith(UpdateCommand, {
110112
ExpressionAttributeNames: {
111113
'#sftpSendLockTime': 'sftpSendLockTime',
114+
'#lockNumber': 'lockNumber',
112115
},
113116
ExpressionAttributeValues: {
114117
':sftpSendLockTime': mockDate.getTime() + 2_592_000_000,
118+
':lockNumber': 1,
115119
},
116120
Key: {
117121
id: templateId,
118122
owner: `CLIENT#${clientId}`,
119123
},
120124
TableName: templatesTableName,
121-
UpdateExpression: 'SET #sftpSendLockTime = :sftpSendLockTime',
125+
UpdateExpression:
126+
'SET #sftpSendLockTime = :sftpSendLockTime ADD #lockNumber :lockNumber',
122127
});
123128
});
124129
});

lambdas/sftp-letters/src/infra/template-lock-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class TemplateLockRepository {
1212
private readonly lockTtl: number
1313
) {}
1414

15-
// TODO: CCM-12327
1615
async acquireLockAndSetSupplierReference(
1716
clientId: string,
1817
id: string,
@@ -28,6 +27,7 @@ export class TemplateLockRepository {
2827
)
2928
.setLockTime('sftpSendLockTime', time, time + this.lockTtl)
3029
.setSupplierReference(supplier, supplierReference)
30+
.incrementLockNumber()
3131
.build();
3232

3333
try {
@@ -42,7 +42,6 @@ export class TemplateLockRepository {
4242
return true;
4343
}
4444

45-
// TODO: CCM-12327
4645
async finaliseLock(clientId: string, id: string) {
4746
const time = this.getDate().getTime();
4847

@@ -52,6 +51,7 @@ export class TemplateLockRepository {
5251
id
5352
)
5453
.setLockTimeUnconditional('sftpSendLockTime', time + THIRTY_DAYS_MS)
54+
.incrementLockNumber()
5555
.build();
5656

5757
return await this.client.send(new UpdateCommand(update));

0 commit comments

Comments
 (0)