This commit is contained in:
Oscar
2026-06-02 16:22:53 +03:00
parent dc44cdd639
commit bc3e48bcad
37 changed files with 973 additions and 1894 deletions

View File

@@ -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) {