diff --git a/src/app.service.ts b/src/app.service.ts index 927d7cc..80f2304 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common'; @Injectable() export class AppService { getHello(): string { - return 'Hello World!'; + return 'E-commerce API'; } } diff --git a/src/payment/payment.controller.ts b/src/payment/payment.controller.ts index 314eb51..2b7c7d0 100644 --- a/src/payment/payment.controller.ts +++ b/src/payment/payment.controller.ts @@ -7,6 +7,7 @@ import { InjectModel } from "@nestjs/sequelize"; import { Payment } from "./entities/payment.entity"; import { JwtAuthGuard } from "src/guard/auth.guard"; import { Transaction } from "src/wallet/entities/transaction.entity"; +import { RoleGuard } from "src/guard/role.guard"; @Controller("payment") export class PaymentController { @@ -20,11 +21,14 @@ export class PaymentController { ) {} @UseGuards(JwtAuthGuard) - @Post("request/:userId") - async requestPayment(@Request() req): Promise<{ url: string }> { + @Post("request") + async requestPayment(@Request() req) { const userId = req.user.id; const invoice = await this.invoiceService.getInvoicePendingByUser(userId); const totalAmount = invoice.totalPaymentAmount; + if(totalAmount<1000){ + return{message:'please enter amount above 1000'} + } const callbackUrl = `http://localhost:3000/payment/verify?userId=${userId}&amount=${totalAmount}`; const paymentUrl = await this.paymentService.requestPayment(totalAmount, "Purchase products", callbackUrl); @@ -69,4 +73,5 @@ export class PaymentController { throw new Error(`Error during payment verification: ${error.message}`); } } + } diff --git a/src/payment/payment.service.ts b/src/payment/payment.service.ts index bc5373a..74fd4a9 100644 --- a/src/payment/payment.service.ts +++ b/src/payment/payment.service.ts @@ -9,7 +9,6 @@ export class PaymentService { private zarinpal; constructor( - ) { this.zarinpal = this.initializeZarinpal(); } @@ -54,4 +53,6 @@ export class PaymentService { throw new InternalServerErrorException(`Error in payment verification: ${error.message}`); } } + + } diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 76d08ad..6cb0fb5 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -46,20 +46,20 @@ export class UsersController { const userId = req.user.id; return this.usersService.editProfile(userId, updateUserDto); } - /////////////////////////////////////admin endpoints///////////////////////////////////////////////////////// + /////////////////////////////////////admin access endpoints///////////////////////////////////////////////////////// //get users list (admin) @UseGuards(RoleGuard) @Get("users") async findAll(): Promise { return this.usersService.findAll(); } - // get a specific user info by admin + // get a specific user info (admin) @UseGuards(RoleGuard) @Get("users/:id") async findSpecificUserInfoByUser(@Param("id") id): Promise { return this.usersService.findSpecificUserInfoByUser(id); } - //delete a specific user by admin + // delete a specific user (admin) @UseGuards(RoleGuard) @Delete(":id?") async deleteUser(@Param("id") id) { diff --git a/src/wallet/wallet.controller.ts b/src/wallet/wallet.controller.ts index 3dcb708..2406378 100644 --- a/src/wallet/wallet.controller.ts +++ b/src/wallet/wallet.controller.ts @@ -2,6 +2,7 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request, import { WalletService } from "./wallet.service"; import { JwtAuthGuard } from "src/guard/auth.guard"; import { PaymentService } from "src/payment/payment.service"; +import { RoleGuard } from "src/guard/role.guard"; @Controller("wallet") export class WalletController { @@ -30,8 +31,14 @@ export class WalletController { @UseGuards(JwtAuthGuard) @Get("transaction") - async getTransactionById(@Request() req){ - const userId = req.user.id - return this.walletService.getTransactionById(userId) + async getTransactionById(@Request() req) { + const userId = req.user.id; + return this.walletService.getTransactionById(userId); + } + + @UseGuards(RoleGuard) + @Get("transaction/:id") + async getTransactionByIdForAdmin(@Param("id") id: number) { + return this.walletService.getTransactionByIdForAdmin(id); } } diff --git a/src/wallet/wallet.service.ts b/src/wallet/wallet.service.ts index 9135ae1..783c5d8 100644 --- a/src/wallet/wallet.service.ts +++ b/src/wallet/wallet.service.ts @@ -53,7 +53,7 @@ export class WalletService { const wallet = await this.walletModel.findOne({ where: { userId } }); if (!wallet) { - throw new HttpException("Wallet not found", HttpStatus.NOT_FOUND); + throw new HttpException("Please Charge your wallet", HttpStatus.NOT_FOUND); } if (wallet.balance < amount) { @@ -86,4 +86,14 @@ export class WalletService { where: { walletId: wallet.walletId }, }); } + //getting transaction a user (admin) + async getTransactionByIdForAdmin(userId: number) { + const wallet = await this.getWalletInfo(userId); + if (!wallet) { + throw new HttpException("Wallet not found for the user.", HttpStatus.NOT_FOUND); + } + return await this.transactionModel.findAll({ + where: { walletId: wallet.walletId }, + }); + } }