From ae756b1a494bc439e07bef1978d1fe3f936ec76f Mon Sep 17 00:00:00 2001 From: Ashutosh Kasudhan Date: Wed, 28 Aug 2024 18:33:27 +0530 Subject: [PATCH] Revert "All api within this are tested and validated please merge it" --- backend/api-inventory/src/dto/pay.dto.ts | 2 +- .../src/payment-processing/pay.service.ts | 104 +++++++----------- .../src/product-management/pm.service.ts | 4 +- 3 files changed, 41 insertions(+), 69 deletions(-) diff --git a/backend/api-inventory/src/dto/pay.dto.ts b/backend/api-inventory/src/dto/pay.dto.ts index eab19ca..9232b64 100644 --- a/backend/api-inventory/src/dto/pay.dto.ts +++ b/backend/api-inventory/src/dto/pay.dto.ts @@ -8,7 +8,7 @@ export class CreatePaymentDto { export class RefundPaymentDto { paymentId: string; - refundAmount: number; // Partial refunds may require an amount + amount: number; // Partial refunds may require an amount } export class PaymentIdDto { diff --git a/backend/api-inventory/src/payment-processing/pay.service.ts b/backend/api-inventory/src/payment-processing/pay.service.ts index 00610f8..e00e84b 100644 --- a/backend/api-inventory/src/payment-processing/pay.service.ts +++ b/backend/api-inventory/src/payment-processing/pay.service.ts @@ -1,48 +1,35 @@ -import { Injectable, BadRequestException, BadGatewayException, NotFoundException } from '@nestjs/common'; -import { PrismaService } from '../prisma/prisma.service'; +import { Injectable, BadRequestException, BadGatewayException } from '@nestjs/common'; +import { PrismaService } from '../prisma/prisma.service'; // Assuming you're using Prisma import { CreatePaymentDto, RefundPaymentDto } from 'src/dto/pay.dto'; + @Injectable() export class PaymentService { constructor(private readonly prismaService: PrismaService) {} async createPayment(createPaymentDto: CreatePaymentDto) { - if (!createPaymentDto) { - throw new BadRequestException('Please provide valid payment data.'); - } - - try { - const payment = await this.prismaService.payment.create({ - data: { - ...createPaymentDto, - status: 'completed', - createdAt: new Date(), - }, - }); - - return { - success: true, - message: 'Payment processed successfully', - data: payment, - }; - } catch (error) { - throw new BadGatewayException('Failed to process payment. Please try again later.'); - } + // Logic to process the payment + const payment = await this.prismaService.payment.create({ + data: { + ...createPaymentDto, + status: 'completed', + createdAt: new Date(), + }, + }); + return { + success: true, + message: 'Payment processed successfully', + data: payment, + }; } async getPaymentDetails(paymentId: string) { - if (!paymentId) { - throw new BadRequestException('Please provide a valid payment ID.'); - } - const payment = await this.prismaService.payment.findUnique({ where: { id: paymentId }, }); - if (!payment) { - throw new NotFoundException('Payment not found.'); + throw new BadRequestException('Payment not found'); } - return { success: true, message: 'Payment details retrieved successfully', @@ -51,44 +38,29 @@ export class PaymentService { } async processRefund(refundPaymentDto: RefundPaymentDto) { - if (!refundPaymentDto) { - throw new BadRequestException('Please provide valid refund data.'); + // Logic to process the refund + const obj = await this.prismaService.payment.findUnique({where : {id : refundPaymentDto.paymentId}}) + if(!obj.id){ + throw new BadGatewayException({ + success : false, + message : 'id is not valid' + }) } - - const payment = await this.prismaService.payment.findUnique({ - where: { id: refundPaymentDto.paymentId }, - }); - - if (!payment) { - throw new NotFoundException('Payment not found with the provided ID.'); - } - - if (refundPaymentDto.refundAmount > payment.amount) { - throw new BadRequestException('Refund amount exceeds the original payment amount.'); - } - - try { - const refund = await this.prismaService.refund.create({ - data: { - paymentId: refundPaymentDto.paymentId, - amount: refundPaymentDto.refundAmount, // Use 'amount' instead of 'refundAmount' - status: 'refunded', - createdAt: new Date(), - }, - }); + const actualAmt = obj.amount; + // case bnakr smabhal liyo pls - return { - success: true, - message: 'Refund processed successfully', - data: refund, - }; - } catch (error) { - throw new BadRequestException({ - success: false, - message: 'Error processing refund', - error: error.message, - }); - } + const refund = await this.prismaService.refund.create({ + data: { + ...refundPaymentDto, + status: 'refunded', + createdAt: new Date(), + }, + }); + return { + success: true, + message: 'Refund processed successfully', + data: refund, + }; } } diff --git a/backend/api-inventory/src/product-management/pm.service.ts b/backend/api-inventory/src/product-management/pm.service.ts index 2fe6d77..e3f5538 100644 --- a/backend/api-inventory/src/product-management/pm.service.ts +++ b/backend/api-inventory/src/product-management/pm.service.ts @@ -21,9 +21,9 @@ export class PmService { updatedAt: new Date(), ...product, }; - + console.log("----------------------") const res = await this.prismaService.product.create({ data: newProduct }) - + console.log("----------------------") try { if (res) { return {