Some checks failed
ci/woodpecker/push/api Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
ParseUUIDPipe,
|
|
} from "@nestjs/common";
|
|
import { AdminService } from "./admin.service";
|
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
import { AdminGuard } from "../auth/guards/admin.guard";
|
|
import { CurrentUser } from "../auth/decorators/current-user.decorator";
|
|
import type { AuthUser } from "@mosaic/shared";
|
|
import { InviteUserDto } from "./dto/invite-user.dto";
|
|
import { UpdateUserDto } from "./dto/update-user.dto";
|
|
import { CreateWorkspaceDto } from "./dto/create-workspace.dto";
|
|
import { UpdateWorkspaceDto } from "./dto/update-workspace.dto";
|
|
import { QueryUsersDto } from "./dto/query-users.dto";
|
|
|
|
@Controller("admin")
|
|
@UseGuards(AuthGuard, AdminGuard)
|
|
export class AdminController {
|
|
constructor(private readonly adminService: AdminService) {}
|
|
|
|
@Get("users")
|
|
async listUsers(@Query() query: QueryUsersDto) {
|
|
return this.adminService.listUsers(query.page, query.limit);
|
|
}
|
|
|
|
@Post("users/invite")
|
|
async inviteUser(@Body() dto: InviteUserDto, @CurrentUser() user: AuthUser) {
|
|
return this.adminService.inviteUser(dto, user.id);
|
|
}
|
|
|
|
@Patch("users/:id")
|
|
async updateUser(
|
|
@Param("id", new ParseUUIDPipe({ version: "4" })) id: string,
|
|
@Body() dto: UpdateUserDto
|
|
) {
|
|
return this.adminService.updateUser(id, dto);
|
|
}
|
|
|
|
@Delete("users/:id")
|
|
async deactivateUser(@Param("id", new ParseUUIDPipe({ version: "4" })) id: string) {
|
|
return this.adminService.deactivateUser(id);
|
|
}
|
|
|
|
@Post("workspaces")
|
|
async createWorkspace(@Body() dto: CreateWorkspaceDto) {
|
|
return this.adminService.createWorkspace(dto);
|
|
}
|
|
|
|
@Patch("workspaces/:id")
|
|
async updateWorkspace(
|
|
@Param("id", new ParseUUIDPipe({ version: "4" })) id: string,
|
|
@Body() dto: UpdateWorkspaceDto
|
|
) {
|
|
return this.adminService.updateWorkspace(id, dto);
|
|
}
|
|
}
|