Skip to content

Commit

Permalink
feat: Update GetProductDTO with userTokenBalance property and update …
Browse files Browse the repository at this point in the history
…user token balance
  • Loading branch information
suk-6 committed Sep 26, 2024
1 parent 4ead66a commit d3dd66f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/modules/product/dto/get.product.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export class GetProductDTO extends ProductDTO {
type: Boolean,
})
saleIsDisabled: boolean;

@ApiProperty({
description: '유저 토큰 보유량',
})
userTokenBalance: number;
}

export class GetProductsDTO extends PickType(ProductDTO, ['id', 'name', 'image', 'currentAmount']) {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/product/product.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { PrismaModule } from 'src/common';
import { S3Module } from 'src/common/modules/s3/s3.module';

import { BlockchainModule } from '../blockchain';
import { UserModule } from '../user';
import { ProductController } from './product.controller';
import { ProductService } from './product.service';

@Module({
imports: [PrismaModule, BlockchainModule, S3Module],
imports: [PrismaModule, BlockchainModule, S3Module, UserModule],
controllers: [ProductController],
providers: [ProductService],
})
Expand Down
9 changes: 9 additions & 0 deletions src/modules/product/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PrismaService } from 'src/common/modules/prisma/prisma.service';
import { S3Service } from 'src/common/modules/s3/s3.service';

import { BlockchainService } from '../blockchain/blockchain.service';
import { UserService } from '../user/user.service';
import { CreateProductDTO } from './dto/create.product.dto';
import { CreateProductQnADTO } from './dto/create.qna.dto';
import { GetProductDTO, GetProductsDTO } from './dto/get.product.dto';
Expand All @@ -24,6 +25,7 @@ export class ProductService {
private readonly prisma: PrismaService,
private readonly blockchain: BlockchainService,
private readonly s3Service: S3Service,
private readonly userService: UserService,
private readonly configService: ConfigService<{
S3_PUBLIC_URL: string;
}>,
Expand Down Expand Up @@ -204,6 +206,7 @@ export class ProductService {
}

async getProduct(userId: string, productId: string): Promise<GetProductDTO> {
this.userService.updateTokenBalancees(userId);
return this.prisma.product
.findFirstOrThrow({
where: {
Expand Down Expand Up @@ -315,6 +318,12 @@ export class ProductService {
product.type === ProductType.FUNDING,
};
})
.then((product) => ({
...product,
userTokenBalance: product.userTokenBalancesOnProduct.length
? product.userTokenBalancesOnProduct[0].token
: 0,
}))
.then((product) => {
const copy: { [key: string]: any } = { ...product };
delete copy['fundingLog'];
Expand Down

0 comments on commit d3dd66f

Please sign in to comment.