Init
This commit is contained in:
@@ -0,0 +1 @@
|
||||
// placeholder app.module.ts
|
||||
@@ -0,0 +1 @@
|
||||
// placeholder config.module.ts
|
||||
@@ -0,0 +1 @@
|
||||
// placeholder config.service.ts
|
||||
@@ -0,0 +1 @@
|
||||
// placeholder main.ts
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
||||
import { UserService } from '../services/user.service';
|
||||
|
||||
@ApiTags('users')
|
||||
@Controller('api/v1/users')
|
||||
export class UsersController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get user by id' })
|
||||
async findById(@Param('id') id: string) {
|
||||
const data = await this.userService.findById(id);
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
meta: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// REMOVED: file content deleted per user request
|
||||
@@ -0,0 +1 @@
|
||||
// REMOVED: file content deleted per user request
|
||||
@@ -0,0 +1,9 @@
|
||||
export class UserEntity {
|
||||
id: string;
|
||||
email: string;
|
||||
displayName: string;
|
||||
metadata?: Record<string, any>;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
deletedAt?: Date | null;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// REMOVED: file content deleted per user request
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface IUserService {
|
||||
findById(id: string): Promise<any | null>;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../../../shared/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class UserRepository {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findById(id: string) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!user) return null;
|
||||
|
||||
// map DB fields (snake_case) to camelCase entity
|
||||
return {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
displayName: (user as any).display_name ?? (user as any).displayName ?? null,
|
||||
metadata: (user as any).metadata ?? {},
|
||||
createdAt: (user as any).created_at ?? (user as any).createdAt,
|
||||
updatedAt: (user as any).updated_at ?? (user as any).updatedAt,
|
||||
deletedAt: (user as any).deleted_at ?? (user as any).deletedAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { UserRepository } from '../repositories/user.repository';
|
||||
import { IUserService } from '../interfaces/iuser.service';
|
||||
|
||||
@Injectable()
|
||||
export class UserService implements IUserService {
|
||||
constructor(private readonly userRepository: UserRepository) {}
|
||||
|
||||
async findById(id: string) {
|
||||
const user = await this.userRepository.findById(id);
|
||||
if (!user) {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||
async onModuleInit() {
|
||||
await this.$connect();
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.$disconnect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user