diff --git a/src/file/dto/send-file.dto.ts b/src/file/dto/send-file.dto.ts new file mode 100644 index 0000000..f021070 --- /dev/null +++ b/src/file/dto/send-file.dto.ts @@ -0,0 +1,8 @@ +import { Types } from 'mongoose' + +export class SendFileDto { + id: string | Types.ObjectId + fileName: string + originalName: string + inTheTrash: boolean +} diff --git a/src/file/file.service.ts b/src/file/file.service.ts index b219056..b080ddc 100644 --- a/src/file/file.service.ts +++ b/src/file/file.service.ts @@ -1,6 +1,7 @@ import { BadRequestException, Injectable } from '@nestjs/common' import { InjectModel } from '@nestjs/mongoose' import { Model } from 'mongoose' +import { SendFileDto } from './dto/send-file.dto' import { File } from './entities/file.entity' @Injectable() @@ -32,13 +33,23 @@ export class FileService { } async findByUserId(userId: string) { - return await this.fileModel.find({ userId }) + const res = await this.fileModel.find({ userId }) + return res.map(item => this.formatFileModel(item)) } async findById(id: string) { return await this.fileModel.findById({ _id: id }) } + private formatFileModel(fileModel: any) { + return { + id: fileModel._id, + fileName: fileModel.fileName, + inTheTrash: fileModel.inTheTrash, + originalName: fileModel.originalName, + } as SendFileDto + } + async trashOn(fileId: string) { const foundFile = await this.findById(fileId)