Skip to content

Commit c23c29f

Browse files
committed
feat(File|Readme): update File to return filename in the body response and update README
1 parent a5a9722 commit c23c29f

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ POST localhost:5001/v1/api/uploadFile/
3636
Retorno de sucesso:
3737
```json
3838
{
39-
"message": "File upload with success!"
39+
"message": "File upload with success!",
40+
"file": "bd40728a-e82b-4dce-91e0-c6d4701ab7ef.csv"
4041
}
4142
```
4243
----

src/api/modules/v1/controllers/files/FileController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ class Files implements IFileController {
1313
if (!body.files) {
1414
throw new Error("Doesn't have a file with csv format to upload");
1515
}
16-
await FileService.handlerFilesPerson(body.files);
16+
const file = await FileService.handlerFilesPerson(body.files);
1717

1818
ctx.response.status = Status.Created;
1919
return ctx.response.body = {
2020
message: "File upload with success!",
21+
file
2122
};
2223
// deno-lint-ignore no-explicit-any
2324
} catch (er: Error | any | unknown) {

src/api/modules/v1/services/file/FileService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export class FileService implements IFileService {
1818
this.fileRepository = FileRespository;
1919
}
2020

21-
public async handlerFilesPerson(files: Array<FormDataFile>): Promise<void> {
21+
public async handlerFilesPerson(files: Array<FormDataFile>): Promise<string> {
2222
return this.processFilesPerson(files);
2323
}
2424

25-
private async processFilesPerson(files: Array<FormDataFile>): Promise<void> {
25+
private async processFilesPerson(files: Array<FormDataFile>): Promise<string> {
2626
if (!files) {
2727
throw new Error('The file is required');
2828
}
29+
let name = '';
2930

3031
for (const file of files) {
3132
const isTypeCsvOrXml = file.contentType === "text/csv" ||
@@ -45,8 +46,11 @@ export class FileService implements IFileService {
4546
await this.s3.handlerBucket(whithoutHeader, filename);
4647

4748
await this.fileRepository.handleCreate(filename);
49+
50+
name = filename;
4851
}
4952
}
53+
return name;
5054
}
5155

5256
public async listFiles(): Promise<Array<IFileDTO>> {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RouterContext } from '$deps';
22

3-
export type CSVType = { message: string } | undefined;
3+
export type CSVType = { message: string, file: string } | undefined;
44
export interface IFileController {
55
uploadCsv(ctx: RouterContext<string>): Promise<CSVType>;
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { FormDataFile, PutObjectOutput } from '$deps';
22
export interface IFileService {
3-
handlerFilesPerson(files: Array<FormDataFile>): Promise<void>
3+
handlerFilesPerson(files: Array<FormDataFile>): Promise<string>
44
}

0 commit comments

Comments
 (0)