Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
fix: delete old save img in folder api
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicGendre committed Jan 20, 2022
1 parent 1093807 commit b16061c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
44 changes: 0 additions & 44 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ import {
Put,
Query,
UploadedFile,
UseGuards,
Request,
UseInterceptors,
Req,
Res,
ParseIntPipe,
StreamableFile,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { User } from '@prisma/client';
import { Response } from 'express';
import { diskStorage } from 'multer';
import path = require('path');
import { v4 as uuidv4 } from 'uuid';
import { CreateUserDto, FilterDto } from 'src/dtos';
import { AuthGuard } from 'src/guards/auth.guard';

import { UserService } from './user.service';

Expand All @@ -47,17 +41,6 @@ export class UserController {
});
}

// Ludo: Pas nécessaire (duplication), nous avons déjà l'ensemble des users en relation dans /cities/:id

// @Get('/city/:id')
// async listCity(@Param('id') id: string): Promise<User[]> {
// return await this.userService.getCity({
// cityWhereUniqueInput: {
// id,
// },
// });
// }

// @UseGuards(AuthGuard)
@Get('/proximity')
async getUsersInRadius(
Expand All @@ -76,33 +59,6 @@ export class UserController {
return await this.userService.get({ id: id });
}

// @Post('upload')
// @UseInterceptors(
// FileInterceptor('file', {
// storage: diskStorage({
// destination: './uploads',
// filename: (req, file, cb) => {
// const filename: string =
// path.parse(file.originalname).name.replace(/\s/g, '') + uuidv4();
// const extension: string = path.parse(file.originalname).ext;

// cb(null, `${filename}${extension}`);
// },
// }),
// }),
// )
// async uploadFile(
// @UploadedFile() file: Express.Multer.File,
// @LoggedUser() user: any,
// ): Promise<User> {
// const auth = await this.userService.get(user);

// return await this.userService.update({
// where: { id: auth.id },
// data: { avatar: file.filename },
// });
// }

@Post('/avatar')
@UseInterceptors(FileInterceptor('file'))
async addAvatar(
Expand Down
3 changes: 2 additions & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class UserService {
return usersInProximity;
}

// save avatar in db
async addAvatar(userId: string, imageBuffer: Buffer, filename: string) {
const avatar = await this.prisma.file.create({
data: {
Expand All @@ -94,7 +95,7 @@ export class UserService {
});
return avatar;
}

// get avatar from db
async getFileById(fileId: string): Promise<File | null> {
return await this.prisma.file.findUnique({
where: { id: fileId },
Expand Down

0 comments on commit b16061c

Please sign in to comment.