50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
/**
|
|
* ════════════════════════════════════════════════════════════
|
|
* مُصادَق (Musadaq) — Users Controller
|
|
* ════════════════════════════════════════════════════════════
|
|
*/
|
|
|
|
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Param,
|
|
Delete,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { UsersService } from './user.service';
|
|
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
|
import { RolesGuard } from '../../common/guards/roles.guard';
|
|
import { Roles } from '../../common/decorators/roles.decorator';
|
|
import { UserRole } from './enums/role.enum';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
|
|
@Controller('users')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
export class UsersController {
|
|
constructor(private usersService: UsersService) {}
|
|
|
|
@Post()
|
|
@Roles(UserRole.ADMIN)
|
|
async create(@CurrentUser() user: any, @Body() dto: any) {
|
|
return this.usersService.create(user.tenantId, dto);
|
|
}
|
|
|
|
@Get()
|
|
async findAll(@CurrentUser() user: any) {
|
|
return this.usersService.findAll(user.tenantId);
|
|
}
|
|
|
|
@Get(':id')
|
|
async findOne(@CurrentUser() user: any, @Param('id') id: string) {
|
|
return this.usersService.findOne(user.tenantId, id);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@Roles(UserRole.ADMIN)
|
|
async remove(@CurrentUser() user: any, @Param('id') id: string) {
|
|
return this.usersService.remove(user.tenantId, id);
|
|
}
|
|
}
|