feat(devops,docs,verify): implement Phase 4 CI pipeline, OpenAPI synchronization, and E2E verification matrix
Deploy Canina / deploy (push) Failing after 28s
Deploy Canina / deploy (push) Failing after 28s
This commit is contained in:
1 parent
27abaa3e05
commit
ad3f149789
25 files changed
+3582
-212
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AdminController } from './admin.controller';
|
||||
import { AdminService } from './admin.service';
|
||||
|
||||
describe('AdminController', () => {
|
||||
let controller: AdminController;
|
||||
@@ -7,6 +8,7 @@ describe('AdminController', () => {
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AdminController],
|
||||
providers: [{ provide: AdminService, useValue: {} }],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AdminController>(AdminController);
|
||||
|
||||
@@ -85,7 +85,12 @@ export class AdminController {
|
||||
@Body('type') type: 'deposit' | 'withdrawal' | 'refund',
|
||||
@Body('description') description?: string,
|
||||
) {
|
||||
const result = await this.adminService.adjustUserWallet(id, Number(amount), type, description);
|
||||
const result = await this.adminService.adjustUserWallet(
|
||||
id,
|
||||
Number(amount),
|
||||
type,
|
||||
description,
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
message: 'موجود کیف پول با موفقیت بروزرسانی شد',
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AdminService } from './admin.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { RedisService } from '../redis/redis.service';
|
||||
|
||||
describe('AdminService', () => {
|
||||
let service: AdminService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AdminService],
|
||||
providers: [
|
||||
AdminService,
|
||||
{ provide: PrismaService, useValue: {} },
|
||||
{ provide: RedisService, useValue: {} },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AdminService>(AdminService);
|
||||
|
||||
@@ -102,17 +102,26 @@ export class AdminService {
|
||||
};
|
||||
}
|
||||
|
||||
async adjustUserWallet(userId: string, amount: number, type: 'deposit' | 'withdrawal' | 'refund', description?: string) {
|
||||
async adjustUserWallet(
|
||||
userId: string,
|
||||
amount: number,
|
||||
type: 'deposit' | 'withdrawal' | 'refund',
|
||||
description?: string,
|
||||
) {
|
||||
const user = await this.prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new NotFoundException('کاربر مورد نظر یافت نشد');
|
||||
}
|
||||
|
||||
const adjustAmount = type === 'withdrawal' ? -Math.abs(amount) : Math.abs(amount);
|
||||
const adjustAmount =
|
||||
type === 'withdrawal' ? -Math.abs(amount) : Math.abs(amount);
|
||||
const currentBalance = Number(user.walletBalance || 0);
|
||||
|
||||
if (adjustAmount < 0 && currentBalance + adjustAmount < 0) {
|
||||
throw new HttpException('موجودی کیف پول کاربر برای کسر این مبلغ کافی نیست', 400);
|
||||
throw new HttpException(
|
||||
'موجودی کیف پول کاربر برای کسر این مبلغ کافی نیست',
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
return this.prisma.$transaction([
|
||||
@@ -122,7 +131,13 @@ export class AdminService {
|
||||
amount: Math.abs(amount),
|
||||
type: type === 'withdrawal' ? 'withdrawal' : 'deposit',
|
||||
status: 'completed',
|
||||
description: description || (type === 'refund' ? 'بازگشت وجه توسط ادمین' : type === 'deposit' ? 'شارژ توسط ادمین' : 'کسر توسط ادمین'),
|
||||
description:
|
||||
description ||
|
||||
(type === 'refund'
|
||||
? 'بازگشت وجه توسط ادمین'
|
||||
: type === 'deposit'
|
||||
? 'شارژ توسط ادمین'
|
||||
: 'کسر توسط ادمین'),
|
||||
},
|
||||
}),
|
||||
this.prisma.user.update({
|
||||
@@ -485,7 +500,9 @@ export class AdminService {
|
||||
where.OR = [
|
||||
{ name: { contains: query.search, mode: 'insensitive' } },
|
||||
{ breed: { contains: query.search, mode: 'insensitive' } },
|
||||
{ user: { firstName: { contains: query.search, mode: 'insensitive' } } },
|
||||
{
|
||||
user: { firstName: { contains: query.search, mode: 'insensitive' } },
|
||||
},
|
||||
{ user: { lastName: { contains: query.search, mode: 'insensitive' } } },
|
||||
];
|
||||
}
|
||||
@@ -498,7 +515,13 @@ export class AdminService {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
user: {
|
||||
select: { id: true, firstName: true, lastName: true, mobile: true, email: true },
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
mobile: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
medicalConditions: true,
|
||||
reminders: true,
|
||||
|
||||
Reference in new issue
Block a user