Skip to content

Commit 3888955

Browse files
author
Nino van Galen
committed
Fix: Fixed some problems
1 parent 90a1502 commit 3888955

5 files changed

Lines changed: 15 additions & 53 deletions

File tree

lib/domain/entities/Attachment.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

lib/server/controllers/attachments.controller.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,17 @@ const readAttachment = async (request, response, next) => {
5656
return;
5757
}
5858

59-
const { attachment, errors } = await new GetAttachmentUseCase()
59+
const { attachment } = await new GetAttachmentUseCase()
6060
.execute(value);
61-
if (errors) {
62-
response.status(400).json(errors);
61+
if (!attachment) {
62+
response.status(400).json({
63+
errors: [
64+
{
65+
status: '404',
66+
title: `Attachment with this id (${request.params.attachmentId}) could not be found`,
67+
},
68+
],
69+
});
6370
return;
6471
}
6572
response.status(200).sendFile(attachment.path);

lib/server/controllers/logs.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ const getAttachment = async (request, response, next) => {
144144
return;
145145
}
146146

147-
const { file, error } = await new GetLogAttachmentUseCase()
147+
const { result, error } = await new GetLogAttachmentUseCase()
148148
.execute(dto);
149149

150150
if (error) {
151151
response.status(Number(error.status)).json({ errors: [error] });
152152
return;
153153
}
154154

155-
response.status(200).sendFile(file.path);
155+
response.status(200).sendFile(result.path);
156156
};
157157

158158
/**

lib/usecases/attachment/GetAttachmentUseCase.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,13 @@ class GetAttachment {
3333
*/
3434
async execute(dto) {
3535
const queryBuilder = new QueryBuilder();
36-
const { params, query = {} } = dto;
36+
const { params } = dto;
3737
const { id } = params;
38-
const { mimetype } = query;
3938

4039
queryBuilder.where('id').is(id);
4140

42-
if (query) {
43-
if (mimetype) {
44-
if (mimetype.includes('/')) {
45-
queryBuilder.where('mime_type').is(mimetype);
46-
} else {
47-
queryBuilder.where('mime_type').startsWith(mimetype);
48-
}
49-
}
50-
}
51-
52-
return TransactionHelper.provide(() => AttachmentRepository.findOne(queryBuilder));
41+
return TransactionHelper
42+
.provide(async () => ({ attachment: await AttachmentRepository.findOne(queryBuilder) }));
5343
}
5444
}
5545

lib/usecases/log/GetLogAttachmentUseCase.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class GetLogAttachmentUseCase {
5050
}
5151

5252
const result = await TransactionHelper.provide(() => AttachmentRepository.findOne(queryBuilder));
53-
5453
if (!result) {
5554
return {
5655
error: {

0 commit comments

Comments
 (0)