feat: complete testing, security, dynamic content, and devops overhaul
This commit is contained in:
1 parent
467532713c
commit
40ff169dc2
52 files changed
+3918
-104
No files matched your search
@@ -1,19 +1,50 @@
|
||||
import { Controller, Get, Patch, Post, Delete, Body, Param, UseGuards, Req } from '@nestjs/common';
|
||||
import { Controller, Get, Patch, Post, Delete, Body, Param, UseGuards, Req, HttpStatus } from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiResponse } 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';
|
||||
|
||||
@ApiTags('Users')
|
||||
@ApiTags('Users - مدیریت کاربران و آدرسها')
|
||||
@ApiBearerAuth()
|
||||
@Controller('users')
|
||||
@ApiResponse({
|
||||
status: HttpStatus.UNAUTHORIZED,
|
||||
description: 'عدم احراز هویت - توکن معتبر نیست یا ارسال نشده است',
|
||||
schema: {
|
||||
example: {
|
||||
success: false,
|
||||
message: 'Unauthorized',
|
||||
code: 'UNAUTHORIZED',
|
||||
details: {}
|
||||
}
|
||||
}
|
||||
})
|
||||
export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('profile')
|
||||
@ApiOperation({ summary: 'دریافت پروفایل کاربر فعلی' })
|
||||
@ApiOkResponse({
|
||||
description: 'مشخصات کامل کاربر به همراه آدرسها و اطلاعات حیوانات خانگی',
|
||||
schema: {
|
||||
example: {
|
||||
id: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
firstName: 'کاربر',
|
||||
lastName: 'جدید',
|
||||
email: '09123456789@temp.local',
|
||||
mobile: '09123456789',
|
||||
role: 'User_PetOwner',
|
||||
walletBalance: '1500000.00',
|
||||
charityDonationTotal: '25000.00',
|
||||
addresses: [],
|
||||
pets: [],
|
||||
createdAt: '2026-05-26T15:20:00.000Z',
|
||||
updatedAt: '2026-05-26T15:20:00.000Z'
|
||||
}
|
||||
}
|
||||
})
|
||||
getProfile(@Req() req: any) {
|
||||
return this.usersService.findById(req.user.id);
|
||||
}
|
||||
@@ -21,7 +52,34 @@ export class UsersController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch('profile')
|
||||
@ApiOperation({ summary: 'ویرایش پروفایل کاربر فعلی' })
|
||||
@ApiResponse({ status: 200, description: 'پروفایل با موفقیت ویرایش شد' })
|
||||
@ApiOkResponse({
|
||||
description: 'پروفایل با موفقیت ویرایش شد',
|
||||
schema: {
|
||||
example: {
|
||||
id: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
firstName: 'علی',
|
||||
lastName: 'احمدی',
|
||||
email: 'ali@example.com',
|
||||
mobile: '09123456789',
|
||||
role: 'User_PetOwner',
|
||||
walletBalance: '1500000.00',
|
||||
charityDonationTotal: '25000.00'
|
||||
}
|
||||
}
|
||||
})
|
||||
@ApiBadRequestResponse({
|
||||
description: 'خطا در صحتسنجی فیلدهای ورودی',
|
||||
schema: {
|
||||
example: {
|
||||
success: false,
|
||||
message: 'ایمیل نامعتبر است',
|
||||
code: 'BAD_REQUEST',
|
||||
details: {
|
||||
message: ['ایمیل نامعتبر است']
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
updateProfile(@Req() req: any, @Body() updateProfileDto: UpdateProfileDto) {
|
||||
return this.usersService.update(req.user.id, updateProfileDto);
|
||||
}
|
||||
@@ -29,7 +87,24 @@ export class UsersController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('addresses')
|
||||
@ApiOperation({ summary: 'ایجاد آدرس جدید برای کاربر' })
|
||||
@ApiResponse({ status: 201, description: 'آدرس جدید با موفقیت ایجاد شد' })
|
||||
@ApiCreatedResponse({
|
||||
description: 'آدرس جدید با موفقیت ایجاد شد',
|
||||
schema: {
|
||||
example: {
|
||||
id: 'b5a6c7d8-1234-5678-abcd-ef1234567890',
|
||||
userId: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
title: 'خانه',
|
||||
receptorName: 'علی احمدی',
|
||||
phone: '09123456789',
|
||||
province: 'تهران',
|
||||
city: 'تهران',
|
||||
detail: 'خیابان آزادی، کوچه مریم، پلاک ۱۰',
|
||||
zipCode: '1456789012',
|
||||
isDefault: false,
|
||||
createdAt: '2026-05-26T18:00:00.000Z'
|
||||
}
|
||||
}
|
||||
})
|
||||
addAddress(@Req() req: any, @Body() addressDto: AddressDto) {
|
||||
return this.usersService.addAddress(req.user.id, addressDto);
|
||||
}
|
||||
@@ -37,7 +112,24 @@ export class UsersController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch('addresses/:addressId')
|
||||
@ApiOperation({ summary: 'ویرایش آدرس کاربر' })
|
||||
@ApiResponse({ status: 200, description: 'آدرس با موفقیت ویرایش شد' })
|
||||
@ApiOkResponse({
|
||||
description: 'آدرس با موفقیت ویرایش شد',
|
||||
schema: {
|
||||
example: {
|
||||
id: 'b5a6c7d8-1234-5678-abcd-ef1234567890',
|
||||
userId: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
title: 'دفتر کار',
|
||||
receptorName: 'علی احمدی',
|
||||
phone: '09123456789',
|
||||
province: 'تهران',
|
||||
city: 'تهران',
|
||||
detail: 'خیابان ولیعصر، برج سپهر، طبقه ۴',
|
||||
zipCode: '1456789012',
|
||||
isDefault: false,
|
||||
createdAt: '2026-05-26T18:00:00.000Z'
|
||||
}
|
||||
}
|
||||
})
|
||||
updateAddress(
|
||||
@Req() req: any,
|
||||
@Param('addressId') addressId: string,
|
||||
@@ -49,7 +141,15 @@ export class UsersController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('addresses/:addressId')
|
||||
@ApiOperation({ summary: 'حذف آدرس کاربر' })
|
||||
@ApiResponse({ status: 200, description: 'آدرس با موفقیت حذف شد' })
|
||||
@ApiOkResponse({
|
||||
description: 'آدرس با موفقیت حذف شد',
|
||||
schema: {
|
||||
example: {
|
||||
success: true,
|
||||
message: 'آدرس با موفقیت حذف شد'
|
||||
}
|
||||
}
|
||||
})
|
||||
deleteAddress(@Req() req: any, @Param('addressId') addressId: string) {
|
||||
return this.usersService.deleteAddress(req.user.id, addressId);
|
||||
}
|
||||
@@ -57,7 +157,15 @@ export class UsersController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch('addresses/:addressId/default')
|
||||
@ApiOperation({ summary: 'انتخاب آدرس به عنوان پیشفرض' })
|
||||
@ApiResponse({ status: 200, description: 'آدرس به عنوان پیشفرض ثبت شد' })
|
||||
@ApiOkResponse({
|
||||
description: 'آدرس به عنوان پیشفرض ثبت شد',
|
||||
schema: {
|
||||
example: {
|
||||
success: true,
|
||||
message: 'آدرس پیشفرض با موفقیت تغییر کرد'
|
||||
}
|
||||
}
|
||||
})
|
||||
setDefaultAddress(@Req() req: any, @Param('addressId') addressId: string) {
|
||||
return this.usersService.setDefaultAddress(req.user.id, addressId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user