Skip to content

Commit

Permalink
fix: batchDelete returns incorrect sync result
Browse files Browse the repository at this point in the history
  • Loading branch information
TBonnin committed Mar 26, 2024
1 parent 05319e5 commit 612211f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/shared/lib/services/sync/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ export async function upsert(
try {
const encryptedRecords = encryptionManager.encryptDataRecords(recordsWithoutDuplicates);

await schema().from(RECORDS_TABLE).insert(encryptedRecords).onConflict(['nango_connection_id', 'external_id', 'model']).merge();
const externalIds = await schema()
.from<DataRecord>(RECORDS_TABLE)
.insert(encryptedRecords)
.onConflict(['nango_connection_id', 'external_id', 'model'])
.merge()
.returning('external_id');

if (softDelete) {
return {
success: true,
summary: {
deletedKeys: [...addedKeys, ...updatedKeys],
deletedKeys: externalIds.map(({ external_id }) => external_id),
addedKeys: [],
updatedKeys: []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Running sync', () => {
{ id: '1', name: 'a' },
{ id: '2', name: 'b' }
];
const expectedResult = { added: 0, updated: 0, deleted: 0 };
const expectedResult = { added: 0, updated: 0, deleted: 2 };
const { records } = await verifySyncRun(rawRecords, rawRecords, false, expectedResult, softDelete);
expect(records).lengthOf(2);
records.forEach((record) => {
Expand Down

0 comments on commit 612211f

Please sign in to comment.