This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe, Post, Query, Delete, Param, UploadedFile, UseInterceptors } from '@nestjs/common';
|
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe, Post, Query, Delete, Param, UploadedFile, UseInterceptors } from '@nestjs/common';
|
||||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiOkResponse, ApiHeader, ApiConsumes } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiOkResponse, ApiHeader, ApiConsumes, ApiParam } from '@nestjs/swagger';
|
||||||
import { FileInterceptor, type File } from '@nest-lab/fastify-multer';
|
import { FileInterceptor, type File } from '@nest-lab/fastify-multer';
|
||||||
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
||||||
import { UserService } from '../providers/user.service';
|
import { UserService } from '../providers/user.service';
|
||||||
@@ -184,6 +184,22 @@ export class UsersController {
|
|||||||
return this.userService.findPaginated(restId, query);
|
return this.userService.findPaginated(restId, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Permissions(Permission.MANAGE_USERS)
|
||||||
|
@ApiHeader(API_HEADER_SLUG)
|
||||||
|
@ApiOperation({ summary: 'Create a new address for a user (admin)' })
|
||||||
|
@ApiParam({ name: 'userId', description: 'User ID' })
|
||||||
|
@ApiBody({ type: CreateUserAddressDto })
|
||||||
|
@ApiOkResponse({ description: 'Created user address' })
|
||||||
|
@Post('admin/users/:userId/addresses')
|
||||||
|
async adminCreateUserAddress(
|
||||||
|
@Param('userId') userId: string,
|
||||||
|
@Body(new ValidationPipe({ transform: true, whitelist: true })) dto: CreateUserAddressDto,
|
||||||
|
) {
|
||||||
|
return this.userService.createUserAddress(userId, dto);
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Permissions(Permission.MANAGE_USERS)
|
@Permissions(Permission.MANAGE_USERS)
|
||||||
|
|||||||
@@ -75,10 +75,14 @@ export class UserService {
|
|||||||
|
|
||||||
async findByPhone(phone: string): Promise<User | null> {
|
async findByPhone(phone: string): Promise<User | null> {
|
||||||
const normalizedPhone = normalizePhone(phone);
|
const normalizedPhone = normalizePhone(phone);
|
||||||
const user = await this.userRepository.findOne({ phone: normalizedPhone });
|
const user = await this.userRepository.findOne(
|
||||||
|
{ phone: normalizedPhone },
|
||||||
|
{ populate: ['addresses'] },
|
||||||
|
);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new NotFoundException(`User with phone ${phone} not found.`);
|
throw new NotFoundException(`User with phone ${phone} not found.`);
|
||||||
}
|
}
|
||||||
|
await user.addresses.loadItems();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user