2022-02-20 11:51:55 +00:00
|
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
HttpStatus,
|
|
|
|
|
HttpCode,
|
|
|
|
|
Post,
|
|
|
|
|
Param,
|
|
|
|
|
Query,
|
|
|
|
|
Body,
|
|
|
|
|
Request,
|
|
|
|
|
UseGuards,
|
|
|
|
|
UseInterceptors,
|
|
|
|
|
ClassSerializerInterceptor,
|
|
|
|
|
Patch,
|
|
|
|
|
Delete,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { JwtGuard } from '@guard/jwt.guard';
|
2022-04-04 13:42:52 +00:00
|
|
|
|
import { IPagination, WikiUserRole, WikiStatus } from '@think/domains';
|
|
|
|
|
import { WikiUserRoleGuard, CheckWikiUserRole } from '@guard/wiki-user.guard';
|
|
|
|
|
import { WikiStatusGuard, CheckWikiStatus } from '@guard/wiki-status.guard';
|
2022-02-20 11:51:55 +00:00
|
|
|
|
import { WikiService } from '@services/wiki.service';
|
|
|
|
|
import { WikiUserDto } from '@dtos/wiki-user.dto';
|
|
|
|
|
import { CreateWikiDto } from '@dtos/create-wiki.dto';
|
|
|
|
|
import { UpdateWikiDto } from '@dtos/update-wiki.dto';
|
|
|
|
|
import { ShareWikiDto } from '@dtos/share-wiki.dto';
|
|
|
|
|
|
|
|
|
|
@Controller('wiki')
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@UseGuards(WikiUserRoleGuard)
|
|
|
|
|
@UseGuards(WikiStatusGuard)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
export class WikiController {
|
|
|
|
|
constructor(private readonly wikiService: WikiService) {}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 新建知识库
|
|
|
|
|
* @param req
|
|
|
|
|
* @param dto
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Post('create')
|
|
|
|
|
@HttpCode(HttpStatus.CREATED)
|
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
|
async register(@Request() req, @Body() dto: CreateWikiDto) {
|
|
|
|
|
return await this.wikiService.createWiki(req.user, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取用户所有知识库(创建的、参与的)
|
|
|
|
|
* @param req
|
|
|
|
|
* @param pagination
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('list/all')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-11 05:57:55 +00:00
|
|
|
|
async getAllWikis(@Request() req, @Query() pagination: IPagination) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.getAllWikis(req.user, pagination);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取用户拥有的知识库(一般是创建的,尚未实现知识库转移)
|
|
|
|
|
* @param req
|
|
|
|
|
* @param pagination
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('list/own')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-11 05:57:55 +00:00
|
|
|
|
async getOwnWikis(@Request() req, @Query() pagination: IPagination) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.getOwnWikis(req.user, pagination);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取用户参与的知识库
|
|
|
|
|
* @param req
|
|
|
|
|
* @param pagination
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('list/join')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-11 05:57:55 +00:00
|
|
|
|
async getJoinWikis(@Request() req, @Query() pagination: IPagination) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.getJoinWikis(req.user, pagination);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取知识库详情
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('detail/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole()
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
|
async getWikiDetail(@Request() req, @Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getWikiDetail(req.user, wikiId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取知识库首页文档(首页文档为自动创建)
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('homedoc/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole()
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
|
async getWikiHomeDocument(@Request() req, @Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getWikiHomeDocument(req.user, wikiId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 修改知识库
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @param dto
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Patch('update/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-12 03:27:56 +00:00
|
|
|
|
async updateWiki(@Request() req, @Param('id') wikiId, @Body() dto: UpdateWikiDto) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.updateWiki(req.user, wikiId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 删除知识库
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Delete('delete/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
|
async deleteWiki(@Request() req, @Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.deleteWiki(req.user, wikiId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 查看知识库成员
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('user/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
async getWikiUsers(@Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getWikiUsers(wikiId);
|
2022-02-20 11:51:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 添加知识库成员
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @param dto
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Post('user/:id/add')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-12 03:27:56 +00:00
|
|
|
|
async addWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.addWikiUser(req.user, wikiId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 更新知识库成员(一般为角色操作)
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @param dto
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Post('user/:id/update')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-12 03:27:56 +00:00
|
|
|
|
async updateWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.updateWikiUser(req.user, wikiId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 删除知识库成员
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @param dto
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Post('user/:id/delete')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-12 03:27:56 +00:00
|
|
|
|
async deleteWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.deleteWikiUser(req.user, wikiId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 分享(或关闭分享)知识库
|
|
|
|
|
* 只有管理员可操作
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @param dto
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Post('share/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole(WikiUserRole.admin)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-03-12 03:27:56 +00:00
|
|
|
|
async toggleWorkspaceStatus(@Request() req, @Param('id') wikiId, @Body() dto: ShareWikiDto) {
|
2022-02-20 11:51:55 +00:00
|
|
|
|
return await this.wikiService.shareWiki(req.user, wikiId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取知识库目录
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('tocs/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole()
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
|
async getWikiTocs(@Request() req, @Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getWikiTocs(req.user, wikiId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 更新知识库目录(排序、父子关系)
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @param relations
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Post('tocs/:id/update')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole()
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
async orderWikiTocs(@Body() relations) {
|
|
|
|
|
return await this.wikiService.orderWikiTocs(relations);
|
2022-02-20 11:51:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取知识库所有文档
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('docs/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiUserRole()
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
|
async getWikiDocs(@Request() req, @Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getWikiDocs(req.user, wikiId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取公开知识库首页文档
|
|
|
|
|
* @param req
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('public/homedoc/:id')
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@CheckWikiStatus(WikiStatus.public)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
async getWikiPublicHomeDocument(@Request() req, @Param('id') wikiId) {
|
2022-04-04 13:42:52 +00:00
|
|
|
|
return await this.wikiService.getPublicWikiHomeDocument(wikiId, req.headers['user-agent']);
|
2022-02-20 11:51:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取公开知识库详情
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@Post('public/detail/:id')
|
|
|
|
|
@CheckWikiStatus(WikiStatus.public)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
async getPublicWorkspaceDetail(@Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getPublicWikiDetail(wikiId);
|
2022-02-20 11:51:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取公开知识库目录
|
|
|
|
|
* @param wikiId
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
@Post('public/tocs/:id')
|
|
|
|
|
@CheckWikiStatus(WikiStatus.public)
|
2022-02-20 11:51:55 +00:00
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2022-04-04 13:42:52 +00:00
|
|
|
|
async getPublicWikiTocs(@Param('id') wikiId) {
|
|
|
|
|
return await this.wikiService.getPublicWikiTocs(wikiId);
|
2022-02-20 11:51:55 +00:00
|
|
|
|
}
|
2022-03-18 09:09:00 +00:00
|
|
|
|
|
2022-04-04 13:42:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取所有公开知识库
|
|
|
|
|
* @param pagination
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-03-18 09:09:00 +00:00
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
|
@Get('public/wikis')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
async getAllPublicWikis(@Query() pagination: IPagination) {
|
|
|
|
|
return await this.wikiService.getAllPublicWikis(pagination);
|
|
|
|
|
}
|
2022-02-20 11:51:55 +00:00
|
|
|
|
}
|