Add password login, set-password, business images migration, and user serialization.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-23 12:10:30 +03:30
co-authored by Cursor
parent 715ca585a8
commit 97a9ee022f
11 changed files with 290 additions and 36 deletions
+5 -4
View File
@@ -6,7 +6,8 @@ import {
Patch,
UseGuards,
} from '@nestjs/common';
import { UserEntity, UserRole } from '../../entities/user.entity';
import { PublicUser } from '../../common/utils/user-serialize.util';
import { UserRole } from '../../entities/user.entity';
import { Roles } from '../auth/decorators/roles.decorator';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
@@ -20,12 +21,12 @@ export class UsersController {
constructor(private readonly service: UsersService) {}
@Get()
findAll(): Promise<UserEntity[]> {
findAll(): Promise<PublicUser[]> {
return this.service.findAll();
}
@Get(':id')
findOne(@Param('id') id: string): Promise<UserEntity> {
findOne(@Param('id') id: string): Promise<PublicUser> {
return this.service.findOne(id);
}
@@ -33,7 +34,7 @@ export class UsersController {
update(
@Param('id') id: string,
@Body() payload: UpdateUserDto,
): Promise<UserEntity> {
): Promise<PublicUser> {
return this.service.update(id, payload);
}
}
+26 -8
View File
@@ -1,6 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { PublicUser, serializeUser } from '../../common/utils/user-serialize.util';
import { UserEntity } from '../../entities/user.entity';
import { UpdateUserDto } from './dto/update-user.dto';
@@ -11,20 +12,36 @@ export class UsersService {
private readonly repo: Repository<UserEntity>,
) {}
findAll(): Promise<UserEntity[]> {
return this.repo.find({ order: { createdAt: 'DESC' } });
async findAll(): Promise<PublicUser[]> {
const users = await this.repo
.createQueryBuilder('user')
.addSelect('user.passwordHash')
.orderBy('user.createdAt', 'DESC')
.getMany();
return users.map(serializeUser);
}
async findOne(id: string): Promise<UserEntity> {
const user = await this.repo.findOne({ where: { id } });
async findOne(id: string): Promise<PublicUser> {
const user = await this.repo
.createQueryBuilder('user')
.addSelect('user.passwordHash')
.where('user.id = :id', { id })
.getOne();
if (!user) {
throw new NotFoundException('User not found');
}
return user;
return serializeUser(user);
}
async update(id: string, dto: UpdateUserDto): Promise<UserEntity> {
const user = await this.findOne(id);
async update(id: string, dto: UpdateUserDto): Promise<PublicUser> {
const user = await this.repo
.createQueryBuilder('user')
.addSelect('user.passwordHash')
.where('user.id = :id', { id })
.getOne();
if (!user) {
throw new NotFoundException('User not found');
}
if (dto.fullName !== undefined) {
user.fullName = dto.fullName;
@@ -36,6 +53,7 @@ export class UsersService {
user.isActive = dto.isActive;
}
return this.repo.save(user);
const saved = await this.repo.save(user);
return serializeUser(saved);
}
}