From eedc49de14a43ce3e02ac4c3867ec3495ce0fda5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 17 Jan 2023 10:27:45 +0000 Subject: [PATCH] Type s3 responses --- packages/backend-core/src/objectStore/objectStore.ts | 10 +++++----- packages/server/__mocks__/aws-sdk.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/src/objectStore/objectStore.ts b/packages/backend-core/src/objectStore/objectStore.ts index f601d40a37..059e1b228d 100644 --- a/packages/backend-core/src/objectStore/objectStore.ts +++ b/packages/backend-core/src/objectStore/objectStore.ts @@ -361,8 +361,8 @@ export const deleteFolder = async ( Prefix: folder, } - let response: any = await client.listObjects(listParams).promise() - if (response.Contents.length === 0) { + const existingObjectsResponse = await client.listObjects(listParams).promise() + if (existingObjectsResponse.Contents?.length === 0) { return } const deleteParams: any = { @@ -372,13 +372,13 @@ export const deleteFolder = async ( }, } - response.Contents.forEach((content: any) => { + existingObjectsResponse.Contents?.forEach((content: any) => { deleteParams.Delete.Objects.push({ Key: content.Key }) }) - response = await client.deleteObjects(deleteParams).promise() + const deleteResponse = await client.deleteObjects(deleteParams).promise() // can only empty 1000 items at once - if (response.Deleted.length === 1000) { + if (deleteResponse.Deleted?.length === 1000) { return deleteFolder(bucketName, folder) } } diff --git a/packages/server/__mocks__/aws-sdk.ts b/packages/server/__mocks__/aws-sdk.ts index 2efbd303f2..8a66f0e213 100644 --- a/packages/server/__mocks__/aws-sdk.ts +++ b/packages/server/__mocks__/aws-sdk.ts @@ -34,7 +34,7 @@ module AwsMock { // @ts-ignore this.listObjects = jest.fn( response({ - Contents: {}, + Contents: [], }) )