upd
This commit is contained in:
@@ -14,9 +14,9 @@ export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@Get('me')
|
||||
@ApiOperation({ summary: 'Get current user profile' })
|
||||
@ApiOperation({ summary: 'Get current user with profile list' })
|
||||
getMe(@CurrentUser('id') userId: string) {
|
||||
return this.usersService.getMyProfile(userId);
|
||||
return this.usersService.getMe(userId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@@ -28,7 +28,7 @@ export class UsersController {
|
||||
@Patch(':id/ban')
|
||||
@Roles('admin', 'moderator')
|
||||
@UseGuards(RolesGuard)
|
||||
@ApiOperation({ summary: 'Ban user (admin/moderator only)' })
|
||||
@ApiOperation({ summary: 'Ban user' })
|
||||
ban(@Param('id') id: string) {
|
||||
return this.usersService.banUser(id);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export class UsersController {
|
||||
@Patch(':id/activate')
|
||||
@Roles('admin', 'moderator')
|
||||
@UseGuards(RolesGuard)
|
||||
@ApiOperation({ summary: 'Activate user (admin/moderator only)' })
|
||||
@ApiOperation({ summary: 'Activate user' })
|
||||
activate(@Param('id') id: string) {
|
||||
return this.usersService.activateUser(id);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { DrizzleService } from '../../database/drizzle.service';
|
||||
import { user, profile, media, role } from '../../database/schema';
|
||||
import { user, profile, role } from '../../database/schema';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -19,38 +19,23 @@ export class UsersService {
|
||||
return rest;
|
||||
}
|
||||
|
||||
async findByIdWithProfile(id: string) {
|
||||
async getMe(userId: string) {
|
||||
const [found] = await this.drizzleService.db
|
||||
.select()
|
||||
.from(user)
|
||||
.leftJoin(profile, eq(profile.userId, user.id))
|
||||
.where(eq(user.id, id))
|
||||
.limit(1);
|
||||
|
||||
if (!found) throw new NotFoundException('User not found');
|
||||
return found;
|
||||
}
|
||||
|
||||
async getMyProfile(userId: string) {
|
||||
const result = await this.drizzleService.db
|
||||
.select()
|
||||
.from(user)
|
||||
.leftJoin(profile, eq(profile.userId, user.id))
|
||||
.leftJoin(role, eq(role.id, user.roleId))
|
||||
.where(eq(user.id, userId))
|
||||
.limit(1);
|
||||
|
||||
if (!result.length) throw new NotFoundException('User not found');
|
||||
const row = result[0];
|
||||
const { password, ...userFields } = row.user;
|
||||
return { ...userFields, profile: row.profile, role: row.role };
|
||||
}
|
||||
if (!found) throw new NotFoundException('User not found');
|
||||
const { password, ...userFields } = found.user;
|
||||
|
||||
async getMediaByUserId(userId: string) {
|
||||
return this.drizzleService.db
|
||||
.select()
|
||||
.from(media)
|
||||
.where(eq(media.userId, userId));
|
||||
const profiles = await this.drizzleService.db
|
||||
.select({ id: profile.id, name: profile.name, gender: profile.gender })
|
||||
.from(profile)
|
||||
.where(eq(profile.userId, userId));
|
||||
|
||||
return { ...userFields, role: found.role, profiles };
|
||||
}
|
||||
|
||||
async banUser(userId: string) {
|
||||
|
||||
Reference in New Issue
Block a user