تغییرات کلی در backend و frontend
This commit is contained in:
1 parent
a74f4bda48
commit
3dedc89ee1
41 files changed
+2373
-1957
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Patch, Post, Delete, Body, Param, UseGuards, Req, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Get, Patch, Post, Delete, Body, Param, UseGuards, Req, HttpStatus, BadRequestException } from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiBadRequestResponse } from '@nestjs/swagger';
|
||||
@@ -169,4 +169,30 @@ export class UsersController {
|
||||
setDefaultAddress(@Req() req: any, @Param('addressId') addressId: string) {
|
||||
return this.usersService.setDefaultAddress(req.user.id, addressId);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('wallet/top-up')
|
||||
@ApiOperation({ summary: 'شارژ کیف پول کاربر' })
|
||||
@ApiCreatedResponse({
|
||||
description: 'کیف پول با موفقیت شارژ شد',
|
||||
schema: {
|
||||
example: {
|
||||
id: 'txn-uuid',
|
||||
userId: 'user-uuid',
|
||||
amount: '500000.00',
|
||||
type: 'deposit',
|
||||
status: 'completed',
|
||||
description: 'شارژ کیف پول',
|
||||
createdAt: '2026-07-11T08:00:00.000Z'
|
||||
}
|
||||
}
|
||||
})
|
||||
@ApiBadRequestResponse({ description: 'مبلغ نامعتبر است' })
|
||||
async topUpWallet(@Req() req: any, @Body() body: { amount: number }) {
|
||||
const amount = Number(body.amount);
|
||||
if (!amount || amount <= 0) {
|
||||
throw new BadRequestException('مبلغ شارژ باید بزرگتر از صفر باشد');
|
||||
}
|
||||
return this.usersService.topUpWallet(req.user.id, amount);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,19 @@ export class UsersService {
|
||||
return this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
pets: true,
|
||||
pets: {
|
||||
include: {
|
||||
medicalConditions: true,
|
||||
reminders: {
|
||||
include: {
|
||||
completions: true
|
||||
}
|
||||
},
|
||||
healthLogs: true,
|
||||
}
|
||||
},
|
||||
orders: {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
orderItems: {
|
||||
include: { product: true }
|
||||
@@ -18,7 +29,10 @@ export class UsersService {
|
||||
}
|
||||
},
|
||||
addresses: true,
|
||||
walletTransactions: true
|
||||
walletTransactions: {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 50
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -103,6 +117,30 @@ export class UsersService {
|
||||
});
|
||||
}
|
||||
|
||||
async topUpWallet(userId: string, amount: number) {
|
||||
if (amount <= 0) {
|
||||
throw new Error('مبلغ شارژ باید بزرگتر از صفر باشد');
|
||||
}
|
||||
|
||||
const [transaction] = await this.prisma.$transaction([
|
||||
this.prisma.walletTransaction.create({
|
||||
data: {
|
||||
userId,
|
||||
amount,
|
||||
type: 'deposit',
|
||||
status: 'completed',
|
||||
description: 'شارژ کیف پول',
|
||||
},
|
||||
}),
|
||||
this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: { walletBalance: { increment: amount } },
|
||||
}),
|
||||
]);
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
async findByPhone(phoneNumber: string) {
|
||||
return this.prisma.user.findUnique({
|
||||
where: { mobile: phoneNumber },
|
||||
|
||||
Reference in new issue
Block a user