mirror of
https://github.com/docmost/docmost.git
synced 2026-05-08 23:33:09 +08:00
c18c9ae02b
* replace TypeORM with Kysely query builder * refactor migrations * other changes and fixes
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { SpaceService } from './services/space.service';
|
|
import { AuthUser } from '../../decorators/auth-user.decorator';
|
|
import { AuthWorkspace } from '../../decorators/auth-workspace.decorator';
|
|
import { JwtAuthGuard } from '../../guards/jwt-auth.guard';
|
|
import { SpaceIdDto } from './dto/space-id.dto';
|
|
import { PaginationOptions } from '../../helpers/pagination/pagination-options';
|
|
import { SpaceMemberService } from './services/space-member.service';
|
|
import { User, Workspace } from '@docmost/db/types/entity.types';
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('spaces')
|
|
export class SpaceController {
|
|
constructor(
|
|
private readonly spaceService: SpaceService,
|
|
private readonly spaceMemberService: SpaceMemberService,
|
|
) {}
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('/')
|
|
async getWorkspaceSpaces(
|
|
@Body()
|
|
pagination: PaginationOptions,
|
|
@AuthUser() user: User,
|
|
@AuthWorkspace() workspace: Workspace,
|
|
) {
|
|
// TODO: only show spaces user can see. e.g open and private with user being a member
|
|
return this.spaceService.getWorkspaceSpaces(workspace.id, pagination);
|
|
}
|
|
|
|
// get all spaces user is a member of
|
|
/*
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('user')
|
|
async getUserSpaces(
|
|
@Body()
|
|
pagination: PaginationOptions,
|
|
@AuthUser() user: User,
|
|
@AuthWorkspace() workspace: Workspace,
|
|
) {
|
|
return this.spaceMemberService.getUserSpaces(
|
|
user.id,
|
|
workspace.id,
|
|
pagination,
|
|
);
|
|
}*/
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('info')
|
|
async getSpaceInfo(
|
|
@Body() spaceIdDto: SpaceIdDto,
|
|
@AuthUser() user: User,
|
|
@AuthWorkspace() workspace: Workspace,
|
|
) {
|
|
return this.spaceService.getSpaceInfo(spaceIdDto.spaceId, workspace.id);
|
|
}
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('members')
|
|
async getSpaceMembers(
|
|
// todo: accept type? users | groups
|
|
@Body() spaceIdDto: SpaceIdDto,
|
|
@Body()
|
|
pagination: PaginationOptions,
|
|
@AuthUser() user: User,
|
|
@AuthWorkspace() workspace: Workspace,
|
|
) {
|
|
return this.spaceMemberService.getSpaceMembers(
|
|
spaceIdDto.spaceId,
|
|
workspace.id,
|
|
pagination,
|
|
);
|
|
}
|
|
}
|