Skip to content

Commit

Permalink
Fix handleImageDtoAndGetKey function
Browse files Browse the repository at this point in the history
Fixes: #60
  • Loading branch information
MrBartusek committed Mar 6, 2024
1 parent 673a05d commit 3c1d564
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/api/src/images/images.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ describe('ImagesService', () => {

expect(result).toBe(null);
});

it('should keep already uploaded image', async () => {
const document = { imageKey: 'test-key' } as DocumentWithImage;
const dto: ImageDto = { hasImage: true };

const result = await service.handleImageDtoAndGetKey(document, dto);

expect(result).toBe('test-key');
});
});

describe('Directly remove image', () => {
Expand Down
7 changes: 7 additions & 0 deletions apps/api/src/images/images.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ export class ImagesService {
if (shouldDeleteImage) {
await this.s3Service.deleteObject(document.imageKey);
}

if (shouldUploadImage) {
return this.uploadBase64(dto.data);
}

const imageWasDeleted = shouldDeleteImage;
if (imageWasDeleted) {
return null;
} else if (documentHasImage) {
return document.imageKey;
}
return null;
}

Expand Down

0 comments on commit 3c1d564

Please sign in to comment.