feat: updade workspace
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { Controller, Get, Inject, UseGuards } from '@nestjs/common';
|
||||
import { ok } from '../common/api-response.js';
|
||||
import { JwtAuthGuard } from '../common/jwt-auth.guard.js';
|
||||
import { Roles } from '../common/roles.decorator.js';
|
||||
import { RolesGuard } from '../common/roles.guard.js';
|
||||
import { UsersService } from './users.service.js';
|
||||
|
||||
@Controller('users')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
export class UsersController {
|
||||
constructor(@Inject(UsersService) private readonly usersService: UsersService) {}
|
||||
|
||||
@Get()
|
||||
@Roles('ADMIN', 'MANAGER')
|
||||
async list() {
|
||||
return ok(await this.usersService.listUsers());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrismaModule } from '../prisma/prisma.module.js';
|
||||
import { UsersController } from './users.controller.js';
|
||||
import { UsersService } from './users.service.js';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service.js';
|
||||
|
||||
export interface PublicUser {
|
||||
id: number;
|
||||
name: string;
|
||||
username: string;
|
||||
email: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(@Inject(PrismaService) private readonly prisma: PrismaService) {}
|
||||
|
||||
async listUsers(): Promise<PublicUser[]> {
|
||||
return this.prisma.user.findMany({
|
||||
orderBy: { id: 'asc' },
|
||||
select: { id: true, name: true, username: true, email: true, role: true },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user