add user address
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-06-23 10:22:00 +03:30
parent 7ce2ddfe5d
commit 556c35d1df
2 changed files with 22 additions and 2 deletions
@@ -1,5 +1,5 @@
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 { AuthGuard } from 'src/modules/auth/guards/auth.guard';
import { UserService } from '../providers/user.service';
@@ -184,6 +184,22 @@ export class UsersController {
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)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_USERS)
+5 -1
View File
@@ -75,10 +75,14 @@ export class UserService {
async findByPhone(phone: string): Promise<User | null> {
const normalizedPhone = normalizePhone(phone);
const user = await this.userRepository.findOne({ phone: normalizedPhone });
const user = await this.userRepository.findOne(
{ phone: normalizedPhone },
{ populate: ['addresses'] },
);
if (!user) {
throw new NotFoundException(`User with phone ${phone} not found.`);
}
await user.addresses.loadItems();
return user;
}