본문 바로가기

프로젝트 개발

23.12.25(전체적으로 수정, 파일 모델 추가)

 

 

ERROR [AuthGuard] In order to use "defaultStrategy", please, ensure to import PassportModule in each place where AuthGuard() is being used. Otherwise, passport won't work correctly.

 

AuthGuard() 쓰는 곳에 passportModule 삽입 

import { PassportModule } from '@nestjs/passport';

 

@Module({
  imports: [
    TypeOrmModule.forFeature([Review]),
    AuthModule,
    RecipeModule,
    PassportModule,
  ],
  controllers: [ReviewController],
  providers: [ReviewService, ReviewRepository],
})
export class ReviewModule {}

 

해도 같은 에러가 떠서 유저부분 맡은 분께 일단 바톤터치함

 

 

deleteDto도 따로 만들어서 하는 게 더 효율적이라는 코치님의 조언듣고 고쳐봄

<delete-recipe.dto.ts>

import { User } from 'src/auth/user.entity';

export class DeleteRecipeDto {
  user: User;
  recipeId: number;

  constructor(deleteRecipeDto: { recipeId: number; user: User }) {
    const { user, recipeId } = deleteRecipeDto;
    this.user = user;
    this.recipeId = recipeId;
  }
}

 

dto에 따라 서비스도 수정

async updateRecipe(
    recipeId: number,
    updateRecipeDto: UpdateRecipeDto,
  ): Promise<Recipe> {
    const recipe = await this.recipeRepository.findOne({
      where: {
        recipeId,
      },
    });
    if (recipe.affected === 0) {
      throw new NotFoundException(`Can't find Recipe with id ${recipeId}`);
    }
  }

 

 

<delelte-review.dto.ts>

import { User } from 'src/auth/user.entity';

export class DeleteReviewDto {
  user: User;
  reviewId: number;

  constructor(deleteReviewDto: { reviewId: number; user: User }) {
    const { user, reviewId } = deleteReviewDto;
    this.user = user;
    this.reviewId = reviewId;
  }
}

 

<review.service.ts>

 async deleteReview(deleteReviewDto: DeleteReviewDto): Promise<void> {
    const { reviewId, user } = deleteReviewDto;
    const review = await this.reviewRepositoty.delete({
      reviewId,
      user: { id: user.id },
    });

    if (review.affected === 0) {
      throw new NotFoundException(`Can't find Review with id ${reviewId}`);
    }
  }

 

 

 

 

파일모델 추가

<upload.service.ts>

import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class UploadService {
  private readonly s3Client = new S3Client({
    region: this.configService.getOrThrow('AWS_S3_REGION'),
  });
  constructor(private readonly configService: ConfigService) {}

  async upload(fileName: string, file: Buffer) {
    await this.s3Client.send(
      new PutObjectCommand({
        Bucket: 'nestjs-uploader',
        Key: fileName,
        Body: file,
      }),
    );
  }
}

 

<upload.controller.ts>

import {
  Controller,
  //   FileTypeValidator,
  //   MaxFileSizeValidator,
  ParseFilePipe,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';
import { UploadService } from './upload.service';

@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}

  @Post()
  @UseInterceptors(FileInterceptor('file'))
  async UploadedFile(
    @UploadedFile(
      new ParseFilePipe({
        validators: [
          //   new MaxFileSizeValidator({ maxSize: 1000 }),
          //   new FileTypeValidator({ fileType: 'image/jpeg' }),
        ],
      }),
    )
    file: Express.Multer.File,
  ) {
    await this.uploadService.upload(file.originalname, file.buffer);
  }
}

 

<upload.module.ts>

import { Module } from '@nestjs/common';
import { UploadController } from './upload.controller';
import { UploadService } from './upload.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RecipeModule } from 'src/recipe/recipe.module';

@Module({
  imports: [TypeOrmModule.forFeature(), RecipeModule],
  controllers: [UploadController],
  providers: [UploadService],
})
export class UploadModule {}

 

레시피랑 연결해서 이미지 넣는 방법 찾아서 해보기  + aws서버에 잘 등록되는지 테스트 하기

 

현재 작업하고 있는 API: recipe, review, category

현재 API가 작업이 된 단계: 데이터 모델링 / 테스트 > 유저쪽 먼저 수정되고 잘 돌아가야 테스트 수월할 거 같습니다 (done)현재 작업이 된 기능: 찜 제외 모든 모델 기본적인 crud + 레시피, 리뷰는 한 유저것만 조회 수정 삭제 가능 (onprogress)현재 작업하고 있는 작업 및 소요기간: 레시피에 카테고리 연결해서 데이터 가져오기

(todo)진행 중이신 작업 : 레시피에 리뷰 연결해서 각 레시피당 리뷰 전체 불러오기+이미지 aws 등록테스트

현실적으로 구현 가능한 기능: 생각하시게에 현실적으로

포기하고 갈 기능: 찜관련

작업들이 언제 끝날지(대략적으로도): 모델 연결 작업은 방법만 알면 금방할 거 같은데 코치님이 join함수로 연결해서 생성하라고 하시는데 어려워서 헤매는 중 > 둘 다 해서 하루에서 이틀정도

현실적으로 생각했을때 프론트가 도와줄 수 있는 도움이 필요한 부분 : 이미지 데이터 확보, 구글링?

 

 

#엘리스트랙 #엘리스트랙후기 #리액트네이티브강좌 #온라인코딩부트캠프 #온라인코딩학원 #프론트엔드학원 #개발자국비지원 #개발자부트캠프 #국비지원부트캠프 #프론트엔드국비지원 #React #Styledcomponent #React Router Dom #Redux #Typescript #Javascript