Skip to content

Commit

Permalink
'.'
Browse files Browse the repository at this point in the history
  • Loading branch information
ManucherKM committed Sep 24, 2023
1 parent e0f6be3 commit f60c997
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/file/dto/send-file.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Types } from 'mongoose'

export class SendFileDto {
id: string | Types.ObjectId
fileName: string
originalName: string
inTheTrash: boolean
}
13 changes: 12 additions & 1 deletion src/file/file.service.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f60c997

Please sign in to comment.