67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import type { UserRole } from '@mento/shared';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
import { Roles } from '../auth/roles.decorator';
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
import { InviteUserDto, UpdateUserCommissionDto, UpdateUserRoleDto } from './dto';
|
|
import { UsersService } from './users.service';
|
|
|
|
@Controller('users')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
export class UsersController {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@Get()
|
|
list(@CurrentUser() user: { organizationId: string }) {
|
|
return this.usersService.list(user.organizationId);
|
|
}
|
|
|
|
@Post()
|
|
@Roles('owner', 'admin')
|
|
invite(
|
|
@CurrentUser() user: { organizationId: string; role: UserRole },
|
|
@Body() dto: InviteUserDto,
|
|
) {
|
|
return this.usersService.invite(user.organizationId, user.role, dto);
|
|
}
|
|
|
|
@Patch(':id/commission')
|
|
@Roles('owner', 'admin')
|
|
updateCommission(
|
|
@CurrentUser() user: { organizationId: string; role: UserRole },
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateUserCommissionDto,
|
|
) {
|
|
return this.usersService.updateCommission(
|
|
user.organizationId,
|
|
user.role,
|
|
id,
|
|
dto.commissionPercent,
|
|
);
|
|
}
|
|
|
|
@Patch(':id/role')
|
|
@Roles('owner', 'admin')
|
|
updateRole(
|
|
@CurrentUser() user: { organizationId: string; userId: string; role: UserRole },
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateUserRoleDto,
|
|
) {
|
|
return this.usersService.updateRole(
|
|
user.organizationId,
|
|
{ userId: user.userId, role: user.role },
|
|
id,
|
|
dto.role,
|
|
);
|
|
}
|
|
}
|