본문 바로가기
Node js/Nest js 강의 내용

5-2. repository 완성 ( with Prisma )

by Bill Lab 2024. 12. 6.
728x90

1. 개발해야할 repository 리스트!

    1) 카트 추가하기

    2) 카트 조회하기

    3) 주문하기

    4) 주문내역확인하기

    5) 상품 조회하기

    6) 상품 재고 차감하기

 

2. Prisma의 transaction

   

 const result: boolean = await this.prisma.$transaction(async (tx) => {
     const products = await this.productRepository.getProductByIds(productIds, tx);
     await this.orderDetailRepository.createOrderDetail(detailWithOrderNo, tx)
 }
 
 async createOrderDetail(createOrdertDetailDto: CreateOrderDetailDto, tx: Prisma.TransactionClient = this.prisma): Promise<boolean> {
      const orderDetailData = CreateOrderDetailDto.to(createOrdertDetailDto);
      await tx.ordersdetail.create({
        data: orderDetailData,
      });
      return true;   
  }

 

 

3. Prisma entity와 DTO사이 어떻게 변환하는가? 

    1) Prisma entity를 DTO로

    2) DTO를 Entity 로

728x90