style: apply standard ESLint & Prettier formatting across backend
Deploy Canina / deploy (push) Successful in 4m58s

This commit is contained in:
parsa aghaei committed 2026-07-29 15:41:53 +03:30
1 parent ae636c8b03
commit 62bd8811fa
66 files changed
+1398 -607

No files matched your search

+16 -7
View File
@@ -8,9 +8,13 @@ describe('UsersController', () => {
const mockUsersService = {
findById: jest.fn().mockResolvedValue({ id: 'user-id', firstName: 'Test' }),
update: jest.fn().mockResolvedValue({ id: 'user-id', firstName: 'Updated' }),
update: jest
.fn()
.mockResolvedValue({ id: 'user-id', firstName: 'Updated' }),
addAddress: jest.fn().mockResolvedValue({ id: 'addr-id', title: 'Home' }),
updateAddress: jest.fn().mockResolvedValue({ id: 'addr-id', title: 'Work' }),
updateAddress: jest
.fn()
.mockResolvedValue({ id: 'addr-id', title: 'Work' }),
deleteAddress: jest.fn().mockResolvedValue({ success: true }),
setDefaultAddress: jest.fn().mockResolvedValue({ success: true }),
};
@@ -18,9 +22,7 @@ describe('UsersController', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
providers: [
{ provide: UsersService, useValue: mockUsersService },
],
providers: [{ provide: UsersService, useValue: mockUsersService }],
}).compile();
controller = module.get<UsersController>(UsersController);
@@ -78,7 +80,11 @@ describe('UsersController', () => {
zipCode: '123',
};
const result = await controller.updateAddress(req, 'addr-id', dto);
expect(service.updateAddress).toHaveBeenCalledWith('user-id', 'addr-id', dto);
expect(service.updateAddress).toHaveBeenCalledWith(
'user-id',
'addr-id',
dto,
);
expect(result.title).toBe('Work');
});
@@ -92,7 +98,10 @@ describe('UsersController', () => {
it('should setDefaultAddress', async () => {
const req = { user: { id: 'user-id' } };
const result = await controller.setDefaultAddress(req, 'addr-id');
expect(service.setDefaultAddress).toHaveBeenCalledWith('user-id', 'addr-id');
expect(service.setDefaultAddress).toHaveBeenCalledWith(
'user-id',
'addr-id',
);
expect(result).toBeDefined();
});
});
+50 -30
View File
@@ -1,7 +1,27 @@
import { Controller, Get, Patch, Post, Delete, Body, Param, UseGuards, Req, HttpStatus, BadRequestException } 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';
import {
ApiTags,
ApiBearerAuth,
ApiOperation,
ApiResponse,
ApiOkResponse,
ApiCreatedResponse,
ApiBadRequestResponse,
} from '@nestjs/swagger';
import { UpdateProfileDto } from './dto/update-profile.dto';
import { AddressDto } from './dto/address.dto';
@@ -16,9 +36,9 @@ import { AddressDto } from './dto/address.dto';
success: false,
message: 'Unauthorized',
code: 'UNAUTHORIZED',
details: {}
}
}
details: {},
},
},
})
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@@ -41,9 +61,9 @@ export class UsersController {
addresses: [],
pets: [],
createdAt: '2026-05-26T15:20:00.000Z',
updatedAt: '2026-05-26T15:20:00.000Z'
}
}
updatedAt: '2026-05-26T15:20:00.000Z',
},
},
})
getProfile(@Req() req: any) {
return this.usersService.findById(req.user.id);
@@ -63,9 +83,9 @@ export class UsersController {
mobile: '09123456789',
role: 'User_PetOwner',
walletBalance: '1500000.00',
charityDonationTotal: '25000.00'
}
}
charityDonationTotal: '25000.00',
},
},
})
@ApiBadRequestResponse({
description: 'خطا در صحت‌سنجی فیلدهای ورودی',
@@ -75,10 +95,10 @@ export class UsersController {
message: 'ایمیل نامعتبر است',
code: 'BAD_REQUEST',
details: {
message: ['ایمیل نامعتبر است']
}
}
}
message: ['ایمیل نامعتبر است'],
},
},
},
})
updateProfile(@Req() req: any, @Body() updateProfileDto: UpdateProfileDto) {
return this.usersService.update(req.user.id, updateProfileDto);
@@ -101,9 +121,9 @@ export class UsersController {
detail: 'خیابان آزادی، کوچه مریم، پلاک ۱۰',
zipCode: '1456789012',
isDefault: false,
createdAt: '2026-05-26T18:00:00.000Z'
}
}
createdAt: '2026-05-26T18:00:00.000Z',
},
},
})
addAddress(@Req() req: any, @Body() addressDto: AddressDto) {
return this.usersService.addAddress(req.user.id, addressDto);
@@ -126,9 +146,9 @@ export class UsersController {
detail: 'خیابان ولیعصر، برج سپهر، طبقه ۴',
zipCode: '1456789012',
isDefault: false,
createdAt: '2026-05-26T18:00:00.000Z'
}
}
createdAt: '2026-05-26T18:00:00.000Z',
},
},
})
updateAddress(
@Req() req: any,
@@ -146,9 +166,9 @@ export class UsersController {
schema: {
example: {
success: true,
message: 'آدرس با موفقیت حذف شد'
}
}
message: 'آدرس با موفقیت حذف شد',
},
},
})
deleteAddress(@Req() req: any, @Param('addressId') addressId: string) {
return this.usersService.deleteAddress(req.user.id, addressId);
@@ -162,9 +182,9 @@ export class UsersController {
schema: {
example: {
success: true,
message: 'آدرس پیش‌فرض با موفقیت تغییر کرد'
}
}
message: 'آدرس پیش‌فرض با موفقیت تغییر کرد',
},
},
})
setDefaultAddress(@Req() req: any, @Param('addressId') addressId: string) {
return this.usersService.setDefaultAddress(req.user.id, addressId);
@@ -183,9 +203,9 @@ export class UsersController {
type: 'deposit',
status: 'completed',
description: 'شارژ کیف پول',
createdAt: '2026-07-11T08:00:00.000Z'
}
}
createdAt: '2026-07-11T08:00:00.000Z',
},
},
})
@ApiBadRequestResponse({ description: 'مبلغ نامعتبر است' })
async topUpWallet(@Req() req: any, @Body() body: { amount: number }) {
+18 -5
View File
@@ -57,8 +57,11 @@ describe('UsersService', () => {
it('should addAddress', async () => {
const addressData = { title: 'Home', isDefault: true };
mockPrisma.userAddress.create.mockResolvedValue({ id: 'addr-id', ...addressData });
mockPrisma.userAddress.create.mockResolvedValue({
id: 'addr-id',
...addressData,
});
const result = await service.addAddress('user-id', addressData);
expect(prisma.userAddress.updateMany).toHaveBeenCalledWith({
where: { userId: 'user-id' },
@@ -70,9 +73,16 @@ describe('UsersService', () => {
it('should updateAddress', async () => {
const addressData = { title: 'Work', isDefault: true };
mockPrisma.userAddress.update.mockResolvedValue({ id: 'addr-id', ...addressData });
mockPrisma.userAddress.update.mockResolvedValue({
id: 'addr-id',
...addressData,
});
const result = await service.updateAddress('user-id', 'addr-id', addressData);
const result = await service.updateAddress(
'user-id',
'addr-id',
addressData,
);
expect(prisma.userAddress.updateMany).toHaveBeenCalled();
expect(prisma.userAddress.update).toHaveBeenCalled();
expect(result.title).toBe('Work');
@@ -86,7 +96,10 @@ describe('UsersService', () => {
});
it('should setDefaultAddress', async () => {
mockPrisma.userAddress.update.mockResolvedValue({ id: 'addr-id', isDefault: true });
mockPrisma.userAddress.update.mockResolvedValue({
id: 'addr-id',
isDefault: true,
});
const result = await service.setDefaultAddress('user-id', 'addr-id');
expect(prisma.userAddress.updateMany).toHaveBeenCalledWith({
where: { userId: 'user-id' },
+16 -16
View File
@@ -8,32 +8,32 @@ export class UsersService {
async findById(id: string) {
return this.prisma.user.findUnique({
where: { id },
include: {
include: {
pets: {
include: {
medicalConditions: true,
reminders: {
include: {
completions: true
}
completions: true,
},
},
healthLogs: true,
}
},
},
},
orders: {
orderBy: { createdAt: 'desc' },
include: {
orderItems: {
include: { product: true }
}
}
include: { product: true },
},
},
},
addresses: true,
walletTransactions: {
orderBy: { createdAt: 'desc' },
take: 50
}
}
take: 50,
},
},
});
}
@@ -46,13 +46,13 @@ export class UsersService {
orders: {
include: {
orderItems: {
include: { product: true }
}
}
include: { product: true },
},
},
},
addresses: true,
walletTransactions: true
}
walletTransactions: true,
},
});
}