auth services implmented
This commit is contained in:
3
ServicesApi/src/users/cluster/utils.ts
Normal file
3
ServicesApi/src/users/cluster/utils.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function processUsers(): void {
|
||||
console.log('Processing users New...');
|
||||
}
|
||||
@@ -6,39 +6,17 @@ import {
|
||||
Delete,
|
||||
Param,
|
||||
Body,
|
||||
HttpCode,
|
||||
} from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { User } from '@prisma/client';
|
||||
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor(private usersService: UsersService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<User[]> {
|
||||
return this.usersService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string): Promise<User | null> {
|
||||
return this.usersService.findOne(Number(id));
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: { name: string; email: string }): Promise<User> {
|
||||
return this.usersService.create(data);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() data: Partial<{ name: string; email: string }>,
|
||||
): Promise<User> {
|
||||
return this.usersService.update(Number(id), data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async remove(@Param('id') id: string): Promise<User> {
|
||||
return this.usersService.remove(Number(id));
|
||||
@Post('filter')
|
||||
@HttpCode(200)
|
||||
async filterUsers(@Body() query: any) {
|
||||
return this.usersService.findWithPagination(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ import { Module } from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { UsersController } from './users.controller';
|
||||
import { PrismaModule } from '@/prisma/prisma.module';
|
||||
import { CacheService } from '../cache.service';
|
||||
import { UtilsModule } from '../utils/utils.module';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
providers: [UsersService],
|
||||
imports: [PrismaModule, UtilsModule],
|
||||
providers: [UsersService, CacheService],
|
||||
controllers: [UsersController],
|
||||
exports: [UsersService],
|
||||
})
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '@/prisma.service';
|
||||
import { User } from '@prisma/client';
|
||||
import { PrismaService } from '@/src/prisma.service';
|
||||
import { users } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll(): Promise<User[]> {
|
||||
return this.prisma.user.findMany();
|
||||
async findAll(): Promise<users[]> {
|
||||
return this.prisma.users.findMany();
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<User | null> {
|
||||
return this.prisma.user.findUnique({ where: { id } });
|
||||
async findOne(id: number): Promise<users | null> {
|
||||
return this.prisma.users.findUnique({ where: { id } });
|
||||
}
|
||||
|
||||
async create(data: { name: string; email: string }): Promise<User> {
|
||||
return this.prisma.user.create({ data });
|
||||
async create(data: any): Promise<users> {
|
||||
return this.prisma.users.create({ data });
|
||||
}
|
||||
|
||||
async update(
|
||||
id: number,
|
||||
data: Partial<{ name: string; email: string }>,
|
||||
): Promise<User> {
|
||||
return this.prisma.user.update({ where: { id }, data });
|
||||
async update(id: number, data: any): Promise<users> {
|
||||
return this.prisma.users.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<User> {
|
||||
return this.prisma.user.delete({ where: { id } });
|
||||
async remove(id: number): Promise<users> {
|
||||
return this.prisma.users.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '@/prisma.service';
|
||||
import { User } from '@prisma/client';
|
||||
import { PrismaService } from '@/src/prisma.service';
|
||||
import { Prisma, users } from '@prisma/client';
|
||||
import { CacheService } from '../cache.service';
|
||||
import { PaginationHelper, PaginationInfo } from '../utils/pagination-helper';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
constructor(
|
||||
private prisma: PrismaService,
|
||||
private cacheService: CacheService,
|
||||
private paginationHelper: PaginationHelper,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<User[]> {
|
||||
return this.prisma.user.findMany();
|
||||
async findAll(filter: any): Promise<Partial<users>[]> {
|
||||
return this.prisma.users.findMany({
|
||||
where: { ...filter },
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<User | null> {
|
||||
return this.prisma.user.findUnique({ where: { id } });
|
||||
async findDynamic(
|
||||
query: Prisma.usersFindManyArgs,
|
||||
): Promise<{ totalCount: number; result: Partial<users>[] }> {
|
||||
const totalCount = await this.prisma.users.count({
|
||||
where: query.where,
|
||||
});
|
||||
const result = await this.prisma.users.findMany(query);
|
||||
return { totalCount, result };
|
||||
}
|
||||
|
||||
async create(data: { name: string; email: string }): Promise<User> {
|
||||
return this.prisma.user.create({ data });
|
||||
async findWithPagination(
|
||||
query: any & { page?: number; pageSize?: number },
|
||||
): Promise<{ data: any[]; pagination: PaginationInfo }> {
|
||||
return this.paginationHelper.paginate(this.prisma.users, query);
|
||||
}
|
||||
|
||||
async update(
|
||||
id: number,
|
||||
data: Partial<{ name: string; email: string }>,
|
||||
): Promise<User> {
|
||||
return this.prisma.user.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<User> {
|
||||
return this.prisma.user.delete({ where: { id } });
|
||||
async findOne(uuid: string): Promise<Partial<users> | null> {
|
||||
return this.prisma.users.findUnique({
|
||||
where: { uu_id: uuid },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user