refactor: add api definition in domain

This commit is contained in:
fantasticit 2022-05-23 13:05:59 +08:00
parent a3cce12243
commit 55f227fae0
39 changed files with 1956 additions and 233 deletions

49
packages/domains/lib/api/collector.d.ts vendored Normal file
View File

@ -0,0 +1,49 @@
import { IDocument, IWiki, CollectType } from '../models';
export declare type CollectorApiTypeDefinition = {
toggle: {
request: {
targetId: IDocument['id'] | IWiki['id'];
type: CollectType;
};
};
check: {
request: {
targetId: IDocument['id'] | IWiki['id'];
type: CollectType;
};
};
};
export declare const CollectorApiDefinition: {
/**
*
*/
toggle: {
method: "Post";
server: "toggle";
client: () => string;
};
/**
*
*/
check: {
method: "Post";
server: "check";
client: () => string;
};
/**
*
*/
wikis: {
method: "Post";
server: "wikis";
client: () => string;
};
/**
*
*/
documents: {
method: "Post";
server: "documents";
client: () => string;
};
};

View File

@ -0,0 +1,37 @@
"use strict";
exports.__esModule = true;
exports.CollectorApiDefinition = void 0;
exports.CollectorApiDefinition = {
/**
* 收藏或取消收藏
*/
toggle: {
method: 'Post',
server: 'toggle',
client: function () { return '/collector/toggle'; }
},
/**
* 检测是否收藏
*/
check: {
method: 'Post',
server: 'check',
client: function () { return '/collector/check'; }
},
/**
* 获取收藏的知识库
*/
wikis: {
method: 'Post',
server: 'wikis',
client: function () { return '/collector/wikis'; }
},
/**
* 获取收藏的文档
*/
documents: {
method: 'Post',
server: 'documents',
client: function () { return '/collector/documents'; }
}
};

35
packages/domains/lib/api/comment.d.ts vendored Normal file
View File

@ -0,0 +1,35 @@
import { IComment, IDocument } from '../models';
export declare const CommentApiDefinition: {
/**
*
*/
add: {
method: "Post";
server: "add";
client: () => string;
};
/**
*
*/
update: {
method: "Patch";
server: "update";
client: () => string;
};
/**
*
*/
delete: {
method: "Delete";
server: "delete/:id";
client: (id: IComment['id']) => string;
};
/**
*
*/
documents: {
method: "Get";
server: "document/:documentId";
client: (documentId: IDocument['id']) => string;
};
};

View File

@ -0,0 +1,37 @@
"use strict";
exports.__esModule = true;
exports.CommentApiDefinition = void 0;
exports.CommentApiDefinition = {
/**
* 新建评论
*/
add: {
method: 'Post',
server: 'add',
client: function () { return '/comment/add'; }
},
/**
* 更新评论
*/
update: {
method: 'Patch',
server: 'update',
client: function () { return '/comment/update'; }
},
/**
* 删除评论
*/
"delete": {
method: 'Delete',
server: 'delete/:id',
client: function (id) { return "/comment/delete/".concat(id); }
},
/**
* 获取指定文档评论
*/
documents: {
method: 'Get',
server: 'document/:documentId',
client: function (documentId) { return "/comment/document/".concat(documentId); }
}
};

123
packages/domains/lib/api/document.d.ts vendored Normal file
View File

@ -0,0 +1,123 @@
import { IDocument } from '../models';
export declare const DocumentApiDefinition: {
/**
*
*/
search: {
method: "Get";
server: "search";
client: () => string;
};
/**
* 访
*/
recent: {
method: "Get";
server: "recent";
client: () => string;
};
/**
*
*/
create: {
method: "Post";
server: "create";
client: () => string;
};
/**
*
*/
getDetailById: {
method: "Get";
server: "detail/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
updateById: {
method: "Patch";
server: "update/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
getVersionById: {
method: "Get";
server: "version/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
getMemberById: {
method: "Get";
server: "member/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
addMemberById: {
method: "Post";
server: "member/:id/add";
client: (id: IDocument['id']) => string;
};
/**
*
*/
updateMemberById: {
method: "Patch";
server: "member/:id/update";
client: (id: IDocument['id']) => string;
};
/**
*
*/
deleteMemberById: {
method: "Post";
server: "member/:id/delete";
client: (id: IDocument['id']) => string;
};
/**
*
*/
getChildren: {
method: "Get";
server: "children";
client: () => string;
};
/**
*
*/
deleteById: {
method: "Delete";
server: "delete/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
shareById: {
method: "Post";
server: "share/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
getPublicDetailById: {
method: "Get";
server: "public/detail/:id";
client: (id: IDocument['id']) => string;
};
/**
*
*/
getPublicChildren: {
method: "Get";
server: "public/children";
client: () => string;
};
};

View File

@ -0,0 +1,125 @@
"use strict";
exports.__esModule = true;
exports.DocumentApiDefinition = void 0;
exports.DocumentApiDefinition = {
/**
* 搜索文档
*/
search: {
method: 'Get',
server: 'search',
client: function () { return '/document/search'; }
},
/**
* 获取用户最近访问的文档
*/
recent: {
method: 'Get',
server: 'recent',
client: function () { return '/document/recent'; }
},
/**
* 新建文档
*/
create: {
method: 'Post',
server: 'create',
client: function () { return '/document/create'; }
},
/**
* 获取文档详情
*/
getDetailById: {
method: 'Get',
server: 'detail/:id',
client: function (id) { return "/document/detail/".concat(id); }
},
/**
* 更新文档
*/
updateById: {
method: 'Patch',
server: 'update/:id',
client: function (id) { return "/document/update/".concat(id); }
},
/**
* 获取文档版本记录
*/
getVersionById: {
method: 'Get',
server: 'version/:id',
client: function (id) { return "/document/version/".concat(id); }
},
/**
* 获取文档成员
*/
getMemberById: {
method: 'Get',
server: 'member/:id',
client: function (id) { return "/document/member/".concat(id); }
},
/**
* 添加文档成员
*/
addMemberById: {
method: 'Post',
server: 'member/:id/add',
client: function (id) { return "/document/member/".concat(id, "/add"); }
},
/**
* 更新文档成员
*/
updateMemberById: {
method: 'Patch',
server: 'member/:id/update',
client: function (id) { return "/document/member/".concat(id, "/update"); }
},
/**
* 删除文档成员
*/
deleteMemberById: {
method: 'Post',
server: 'member/:id/delete',
client: function (id) { return "/document/member/".concat(id, "/delete"); }
},
/**
* 获取子文档
*/
getChildren: {
method: 'Get',
server: 'children',
client: function () { return "/document/children"; }
},
/**
* 删除文档
*/
deleteById: {
method: 'Delete',
server: 'delete/:id',
client: function (id) { return "/document/delete/".concat(id); }
},
/**
* 分享文档
*/
shareById: {
method: 'Post',
server: 'share/:id',
client: function (id) { return "/document/share/".concat(id); }
},
/**
* 获取公开文档详情
*/
getPublicDetailById: {
method: 'Get',
server: 'public/detail/:id',
client: function (id) { return "/document/public/detail/".concat(id); }
},
/**
* 获取公开文档的子文档
*/
getPublicChildren: {
method: 'Get',
server: 'public/children',
client: function () { return "/document/public/children"; }
}
};

10
packages/domains/lib/api/file.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
export declare const FileApiDefinition: {
/**
*
*/
upload: {
method: "Post";
server: "upload";
client: () => string;
};
};

View File

@ -0,0 +1,13 @@
"use strict";
exports.__esModule = true;
exports.FileApiDefinition = void 0;
exports.FileApiDefinition = {
/**
* 上传文件
*/
upload: {
method: 'Post',
server: 'upload',
client: function () { return '/file/upload'; }
}
};

8
packages/domains/lib/api/index.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
export * from './user';
export * from './wiki';
export * from './document';
export * from './file';
export * from './message';
export * from './template';
export * from './comment';
export * from './collector';

View File

@ -0,0 +1,20 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
exports.__esModule = true;
__exportStar(require("./user"), exports);
__exportStar(require("./wiki"), exports);
__exportStar(require("./document"), exports);
__exportStar(require("./file"), exports);
__exportStar(require("./message"), exports);
__exportStar(require("./template"), exports);
__exportStar(require("./comment"), exports);
__exportStar(require("./collector"), exports);

35
packages/domains/lib/api/message.d.ts vendored Normal file
View File

@ -0,0 +1,35 @@
import { IMessage } from '../models';
export declare const MessageApiDefinition: {
/**
*
*/
getUnread: {
method: "Get";
server: "unread";
client: () => string;
};
/**
*
*/
getRead: {
method: "Get";
server: "read";
client: () => string;
};
/**
*
*/
getAll: {
method: "Get";
server: "all";
client: () => string;
};
/**
*
*/
readMessage: {
method: "Post";
server: "read/:id";
client: (id: IMessage['id']) => string;
};
};

View File

@ -0,0 +1,37 @@
"use strict";
exports.__esModule = true;
exports.MessageApiDefinition = void 0;
exports.MessageApiDefinition = {
/**
* 获取未读消息
*/
getUnread: {
method: 'Get',
server: 'unread',
client: function () { return '/message/unread'; }
},
/**
* 获取已读消息
*/
getRead: {
method: 'Get',
server: 'read',
client: function () { return '/message/read'; }
},
/**
* 获取所有消息
*/
getAll: {
method: 'Get',
server: 'all',
client: function () { return '/message/all'; }
},
/**
* 将消息标记为已读
*/
readMessage: {
method: 'Post',
server: 'read/:id',
client: function (id) { return "/message/read/".concat(id); }
}
};

51
packages/domains/lib/api/template.d.ts vendored Normal file
View File

@ -0,0 +1,51 @@
import { ITemplate } from '../models';
export declare const TemplateApiDefinition: {
/**
*
*/
public: {
method: "Get";
server: "public";
client: () => string;
};
/**
*
*/
own: {
method: "Get";
server: "own";
client: () => string;
};
/**
*
*/
add: {
method: "Post";
server: "add";
client: () => string;
};
/**
*
*/
updateById: {
method: "Patch";
server: "update/:id";
client: (id: ITemplate['id']) => string;
};
/**
*
*/
getDetailById: {
method: "Get";
server: "detail/:id";
client: (id: ITemplate['id']) => string;
};
/**
*
*/
deleteById: {
method: "Delete";
server: "delete/:id";
client: (id: ITemplate['id']) => string;
};
};

View File

@ -0,0 +1,53 @@
"use strict";
exports.__esModule = true;
exports.TemplateApiDefinition = void 0;
exports.TemplateApiDefinition = {
/**
* 获取公开模板
*/
public: {
method: 'Get',
server: 'public',
client: function () { return '/template/public'; }
},
/**
* 获取个人创建模板
*/
own: {
method: 'Get',
server: 'own',
client: function () { return '/template/own'; }
},
/**
* 新建模板
*/
add: {
method: 'Post',
server: 'add',
client: function () { return '/template/add'; }
},
/**
* 更新模板
*/
updateById: {
method: 'Patch',
server: 'update/:id',
client: function (id) { return "/template/update/".concat(id); }
},
/**
* 获取模板详情
*/
getDetailById: {
method: 'Get',
server: 'detail/:id',
client: function (id) { return "/template/detail/".concat(id); }
},
/**
* 删除模板
*/
deleteById: {
method: 'Delete',
server: 'delete/:id',
client: function (id) { return "/template/delete/".concat(id); }
}
};

42
packages/domains/lib/api/user.d.ts vendored Normal file
View File

@ -0,0 +1,42 @@
export declare const UserApiDefinition: {
/**
*
*/
getAllUsers: {
method: "Get";
server: "/";
client: () => string;
};
/**
*
*/
register: {
method: "Post";
server: "register";
client: () => string;
};
/**
*
*/
login: {
method: "Post";
server: "login";
client: () => string;
};
/**
*
*/
logout: {
method: "Post";
server: "logout";
client: () => string;
};
/**
*
*/
update: {
method: "Patch";
server: "update";
client: () => string;
};
};

View File

@ -0,0 +1,45 @@
"use strict";
exports.__esModule = true;
exports.UserApiDefinition = void 0;
exports.UserApiDefinition = {
/**
* 获取用户
*/
getAllUsers: {
method: 'Get',
server: '/',
client: function () { return '/user'; }
},
/**
* 注册
*/
register: {
method: 'Post',
server: 'register',
client: function () { return '/user/register'; }
},
/**
* 登录
*/
login: {
method: 'Post',
server: 'login',
client: function () { return '/user/login'; }
},
/**
* 登出
*/
logout: {
method: 'Post',
server: 'logout',
client: function () { return '/user/logout'; }
},
/**
* 更新
*/
update: {
method: 'Patch',
server: 'update',
client: function () { return "/user/update"; }
}
};

163
packages/domains/lib/api/wiki.d.ts vendored Normal file
View File

@ -0,0 +1,163 @@
import { IWiki } from '../models';
export declare const WikiApiDefinition: {
/**
*
*/
getAllWikis: {
method: "Get";
server: "list/all";
client: () => string;
};
/**
*
*/
getOwnWikis: {
method: "Get";
server: "list/own";
client: () => string;
};
/**
*
*/
getJoinWikis: {
method: "Get";
server: "list/join";
client: () => string;
};
/**
*
*/
add: {
method: "Post";
server: "add";
client: () => string;
};
/**
*
*/
getHomeDocumentById: {
method: "Get";
server: "homedoc/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getTocsById: {
method: "Get";
server: "tocs/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
updateTocsById: {
method: "Patch";
server: "tocs/:id/update";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getDocumentsById: {
method: "Get";
server: "documents/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getDetailById: {
method: "Get";
server: "detail/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
updateById: {
method: "Patch";
server: "update/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
deleteById: {
method: "Delete";
server: "delet/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getMemberById: {
method: "Get";
server: "member/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
addMemberById: {
method: "Post";
server: "member/:id/add";
client: (id: IWiki['id']) => string;
};
/**
*
*/
updateMemberById: {
method: "Patch";
server: "member/:id/update";
client: (id: IWiki['id']) => string;
};
/**
*
*/
deleteMemberById: {
method: "Delete";
server: "member/:id/delete";
client: (id: IWiki['id']) => string;
};
/**
*
*/
shareById: {
method: "Post";
server: "share/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getPublicHomeDocumentById: {
method: "Get";
server: "/public/homedoc/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getPublicTocsById: {
method: "Get";
server: "/public/tocs/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getPublicDetailById: {
method: "Get";
server: "/public/detail/:id";
client: (id: IWiki['id']) => string;
};
/**
*
*/
getPublicWikis: {
method: "Get";
server: "/public/wikis";
client: (id: IWiki['id']) => string;
};
};

View File

@ -0,0 +1,165 @@
"use strict";
exports.__esModule = true;
exports.WikiApiDefinition = void 0;
exports.WikiApiDefinition = {
/**
* 获取用户所有知识库创建的参与的
*/
getAllWikis: {
method: 'Get',
server: 'list/all',
client: function () { return '/wiki/list/all'; }
},
/**
* 获取用户创建的知识库
*/
getOwnWikis: {
method: 'Get',
server: 'list/own',
client: function () { return '/wiki/list/own'; }
},
/**
* 获取用户参与的知识库
*/
getJoinWikis: {
method: 'Get',
server: 'list/join',
client: function () { return '/wiki/list/join'; }
},
/**
* 新建知识库
*/
add: {
method: 'Post',
server: 'add',
client: function () { return '/wiki/add'; }
},
/**
* 获取知识库首页文档
*/
getHomeDocumentById: {
method: 'Get',
server: 'homedoc/:id',
client: function (id) { return "/wiki/homedoc/".concat(id); }
},
/**
* 获取知识库目录
*/
getTocsById: {
method: 'Get',
server: 'tocs/:id',
client: function (id) { return "/wiki/tocs/".concat(id); }
},
/**
* 更新知识库目录
*/
updateTocsById: {
method: 'Patch',
server: 'tocs/:id/update',
client: function (id) { return "/wiki/tocs/".concat(id, "/update"); }
},
/**
* 获取知识库所有文档
*/
getDocumentsById: {
method: 'Get',
server: 'documents/:id',
client: function (id) { return "/wiki/documents/".concat(id); }
},
/**
* 获取知识库详情
*/
getDetailById: {
method: 'Get',
server: 'detail/:id',
client: function (id) { return "/wiki/detail/".concat(id); }
},
/**
* 更新知识库
*/
updateById: {
method: 'Patch',
server: 'update/:id',
client: function (id) { return "/wiki/update/".concat(id); }
},
/**
* 删除知识库
*/
deleteById: {
method: 'Delete',
server: 'delet/:id',
client: function (id) { return "/wiki/delet/".concat(id); }
},
/**
* 获取知识库成员
*/
getMemberById: {
method: 'Get',
server: 'member/:id',
client: function (id) { return "/wiki/member/".concat(id); }
},
/**
* 添加知识库成员
*/
addMemberById: {
method: 'Post',
server: 'member/:id/add',
client: function (id) { return "/wiki/member/".concat(id, "/add"); }
},
/**
* 更新知识库成员
*/
updateMemberById: {
method: 'Patch',
server: 'member/:id/update',
client: function (id) { return "/wiki/member/".concat(id, "/update"); }
},
/**
* 删除知识库成员
*/
deleteMemberById: {
method: 'Delete',
server: 'member/:id/delete',
client: function (id) { return "/wiki/member/".concat(id, "/delete"); }
},
/**
* 分享知识库
*/
shareById: {
method: 'Post',
server: 'share/:id',
client: function (id) { return "/wiki/share/".concat(id); }
},
/**
* 获取公开知识库首页文档
*/
getPublicHomeDocumentById: {
method: 'Get',
server: '/public/homedoc/:id',
client: function (id) { return "/wiki/public/homedoc/".concat(id); }
},
/**
* 获取公开知识库目录
*/
getPublicTocsById: {
method: 'Get',
server: '/public/tocs/:id',
client: function (id) { return "/wiki/public/tocs/".concat(id); }
},
/**
* 获取知识库详情
*/
getPublicDetailById: {
method: 'Get',
server: '/public/detail/:id',
client: function (id) { return "/wiki/public/detail/".concat(id); }
},
/**
* 获取所有公开知识库
*/
getPublicWikis: {
method: 'Get',
server: '/public/wikis',
client: function (id) { return "/wiki/public/wikis"; }
}
};

View File

@ -1,2 +1,3 @@
export * from './models';
export * from './util';
export * from './api';

View File

@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
exports.__esModule = true;
__exportStar(require("./models"), exports);
__exportStar(require("./util"), exports);
__exportStar(require("./api"), exports);

View File

@ -0,0 +1,54 @@
import { IDocument, IWiki, CollectType } from '../models';
export type CollectorApiTypeDefinition = {
toggle: {
request: {
targetId: IDocument['id'] | IWiki['id'];
type: CollectType;
};
};
check: {
request: {
targetId: IDocument['id'] | IWiki['id'];
type: CollectType;
};
};
};
export const CollectorApiDefinition = {
/**
*
*/
toggle: {
method: 'Post' as const,
server: 'toggle' as const,
client: () => '/collector/toggle',
},
/**
*
*/
check: {
method: 'Post' as const,
server: 'check' as const,
client: () => '/collector/check',
},
/**
*
*/
wikis: {
method: 'Post' as const,
server: 'wikis' as const,
client: () => '/collector/wikis',
},
/**
*
*/
documents: {
method: 'Post' as const,
server: 'documents' as const,
client: () => '/collector/documents',
},
};

View File

@ -0,0 +1,39 @@
import { IComment, IDocument } from '../models';
export const CommentApiDefinition = {
/**
*
*/
add: {
method: 'Post' as const,
server: 'add' as const,
client: () => '/comment/add',
},
/**
*
*/
update: {
method: 'Patch' as const,
server: 'update' as const,
client: () => '/comment/update',
},
/**
*
*/
delete: {
method: 'Delete' as const,
server: 'delete/:id' as const,
client: (id: IComment['id']) => `/comment/delete/${id}`,
},
/**
*
*/
documents: {
method: 'Get' as const,
server: 'document/:documentId' as const,
client: (documentId: IDocument['id']) => `/comment/document/${documentId}`,
},
};

View File

@ -0,0 +1,138 @@
import { IDocument } from '../models';
export const DocumentApiDefinition = {
/**
*
*/
search: {
method: 'Get' as const,
server: 'search' as const,
client: () => '/document/search',
},
/**
* 访
*/
recent: {
method: 'Get' as const,
server: 'recent' as const,
client: () => '/document/recent',
},
/**
*
*/
create: {
method: 'Post' as const,
server: 'create' as const,
client: () => '/document/create',
},
/**
*
*/
getDetailById: {
method: 'Get' as const,
server: 'detail/:id' as const,
client: (id: IDocument['id']) => `/document/detail/${id}`,
},
/**
*
*/
updateById: {
method: 'Patch' as const,
server: 'update/:id' as const,
client: (id: IDocument['id']) => `/document/update/${id}`,
},
/**
*
*/
getVersionById: {
method: 'Get' as const,
server: 'version/:id' as const,
client: (id: IDocument['id']) => `/document/version/${id}`,
},
/**
*
*/
getMemberById: {
method: 'Get' as const,
server: 'member/:id' as const,
client: (id: IDocument['id']) => `/document/member/${id}`,
},
/**
*
*/
addMemberById: {
method: 'Post' as const,
server: 'member/:id/add' as const,
client: (id: IDocument['id']) => `/document/member/${id}/add`,
},
/**
*
*/
updateMemberById: {
method: 'Patch' as const,
server: 'member/:id/update' as const,
client: (id: IDocument['id']) => `/document/member/${id}/update`,
},
/**
*
*/
deleteMemberById: {
method: 'Post' as const,
server: 'member/:id/delete' as const,
client: (id: IDocument['id']) => `/document/member/${id}/delete`,
},
/**
*
*/
getChildren: {
method: 'Get' as const,
server: 'children' as const,
client: () => `/document/children`,
},
/**
*
*/
deleteById: {
method: 'Delete' as const,
server: 'delete/:id' as const,
client: (id: IDocument['id']) => `/document/delete/${id}`,
},
/**
*
*/
shareById: {
method: 'Post' as const,
server: 'share/:id' as const,
client: (id: IDocument['id']) => `/document/share/${id}`,
},
/**
*
*/
getPublicDetailById: {
method: 'Get' as const,
server: 'public/detail/:id' as const,
client: (id: IDocument['id']) => `/document/public/detail/${id}`,
},
/**
*
*/
getPublicChildren: {
method: 'Get' as const,
server: 'public/children' as const,
client: () => `/document/public/children`,
},
};

View File

@ -0,0 +1,10 @@
export const FileApiDefinition = {
/**
*
*/
upload: {
method: 'Post' as const,
server: 'upload' as const,
client: () => '/file/upload',
},
};

View File

@ -0,0 +1,8 @@
export * from './user';
export * from './wiki';
export * from './document';
export * from './file';
export * from './message';
export * from './template';
export * from './comment';
export * from './collector';

View File

@ -0,0 +1,39 @@
import { IMessage } from '../models';
export const MessageApiDefinition = {
/**
*
*/
getUnread: {
method: 'Get' as const,
server: 'unread' as const,
client: () => '/message/unread',
},
/**
*
*/
getRead: {
method: 'Get' as const,
server: 'read' as const,
client: () => '/message/read',
},
/**
*
*/
getAll: {
method: 'Get' as const,
server: 'all' as const,
client: () => '/message/all',
},
/**
*
*/
readMessage: {
method: 'Post' as const,
server: 'read/:id' as const,
client: (id: IMessage['id']) => `/message/read/${id}`,
},
};

View File

@ -0,0 +1,57 @@
import { ITemplate } from '../models';
export const TemplateApiDefinition = {
/**
*
*/
public: {
method: 'Get' as const,
server: 'public' as const,
client: () => '/template/public',
},
/**
*
*/
own: {
method: 'Get' as const,
server: 'own' as const,
client: () => '/template/own',
},
/**
*
*/
add: {
method: 'Post' as const,
server: 'add' as const,
client: () => '/template/add',
},
/**
*
*/
updateById: {
method: 'Patch' as const,
server: 'update/:id' as const,
client: (id: ITemplate['id']) => `/template/update/${id}`,
},
/**
*
*/
getDetailById: {
method: 'Get' as const,
server: 'detail/:id' as const,
client: (id: ITemplate['id']) => `/template/detail/${id}`,
},
/**
*
*/
deleteById: {
method: 'Delete' as const,
server: 'delete/:id' as const,
client: (id: ITemplate['id']) => `/template/delete/${id}`,
},
};

View File

@ -0,0 +1,48 @@
import { IUser } from '../models';
export const UserApiDefinition = {
/**
*
*/
getAllUsers: {
method: 'Get' as const,
server: '/' as const,
client: () => '/user',
},
/**
*
*/
register: {
method: 'Post' as const,
server: 'register' as const,
client: () => '/user/register',
},
/**
*
*/
login: {
method: 'Post' as const,
server: 'login' as const,
client: () => '/user/login',
},
/**
*
*/
logout: {
method: 'Post' as const,
server: 'logout' as const,
client: () => '/user/logout',
},
/**
*
*/
update: {
method: 'Patch' as const,
server: 'update' as const,
client: () => `/user/update`,
},
};

View File

@ -0,0 +1,183 @@
import { IWiki } from '../models';
export const WikiApiDefinition = {
/**
*
*/
getAllWikis: {
method: 'Get' as const,
server: 'list/all' as const,
client: () => '/wiki/list/all',
},
/**
*
*/
getOwnWikis: {
method: 'Get' as const,
server: 'list/own' as const,
client: () => '/wiki/list/own',
},
/**
*
*/
getJoinWikis: {
method: 'Get' as const,
server: 'list/join' as const,
client: () => '/wiki/list/join',
},
/**
*
*/
add: {
method: 'Post' as const,
server: 'add' as const,
client: () => '/wiki/add',
},
/**
*
*/
getHomeDocumentById: {
method: 'Get' as const,
server: 'homedoc/:id' as const,
client: (id: IWiki['id']) => `/wiki/homedoc/${id}`,
},
/**
*
*/
getTocsById: {
method: 'Get' as const,
server: 'tocs/:id' as const,
client: (id: IWiki['id']) => `/wiki/tocs/${id}`,
},
/**
*
*/
updateTocsById: {
method: 'Patch' as const,
server: 'tocs/:id/update' as const,
client: (id: IWiki['id']) => `/wiki/tocs/${id}/update`,
},
/**
*
*/
getDocumentsById: {
method: 'Get' as const,
server: 'documents/:id' as const,
client: (id: IWiki['id']) => `/wiki/documents/${id}`,
},
/**
*
*/
getDetailById: {
method: 'Get' as const,
server: 'detail/:id' as const,
client: (id: IWiki['id']) => `/wiki/detail/${id}`,
},
/**
*
*/
updateById: {
method: 'Patch' as const,
server: 'update/:id' as const,
client: (id: IWiki['id']) => `/wiki/update/${id}`,
},
/**
*
*/
deleteById: {
method: 'Delete' as const,
server: 'delet/:id' as const,
client: (id: IWiki['id']) => `/wiki/delet/${id}`,
},
/**
*
*/
getMemberById: {
method: 'Get' as const,
server: 'member/:id' as const,
client: (id: IWiki['id']) => `/wiki/member/${id}`,
},
/**
*
*/
addMemberById: {
method: 'Post' as const,
server: 'member/:id/add' as const,
client: (id: IWiki['id']) => `/wiki/member/${id}/add`,
},
/**
*
*/
updateMemberById: {
method: 'Patch' as const,
server: 'member/:id/update' as const,
client: (id: IWiki['id']) => `/wiki/member/${id}/update`,
},
/**
*
*/
deleteMemberById: {
method: 'Delete' as const,
server: 'member/:id/delete' as const,
client: (id: IWiki['id']) => `/wiki/member/${id}/delete`,
},
/**
*
*/
shareById: {
method: 'Post' as const,
server: 'share/:id' as const,
client: (id: IWiki['id']) => `/wiki/share/${id}`,
},
/**
*
*/
getPublicHomeDocumentById: {
method: 'Get' as const,
server: '/public/homedoc/:id' as const,
client: (id: IWiki['id']) => `/wiki/public/homedoc/${id}`,
},
/**
*
*/
getPublicTocsById: {
method: 'Get' as const,
server: '/public/tocs/:id' as const,
client: (id: IWiki['id']) => `/wiki/public/tocs/${id}`,
},
/**
*
*/
getPublicDetailById: {
method: 'Get' as const,
server: '/public/detail/:id' as const,
client: (id: IWiki['id']) => `/wiki/public/detail/${id}`,
},
/**
*
*/
getPublicWikis: {
method: 'Get' as const,
server: '/public/wikis' as const,
client: (id: IWiki['id']) => `/wiki/public/wikis`,
},
};

View File

@ -1,2 +1,3 @@
export * from './models';
export * from './util';
export * from './api';

View File

@ -4,6 +4,7 @@ import {
Body,
ClassSerializerInterceptor,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
@ -12,40 +13,53 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { CollectorService } from '@services/collector.service';
import { CollectorApiDefinition } from '@think/domains';
@Controller('collector')
export class CollectorController {
constructor(private readonly collectorService: CollectorService) {}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('toggle')
@Post(CollectorApiDefinition.toggle.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async toggleStar(@Request() req, @Body() dto: CollectDto) {
return await this.collectorService.toggleStar(req.user, dto);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('check')
@Post(CollectorApiDefinition.toggle.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async checkStar(@Request() req, @Body() dto: CollectDto) {
return await this.collectorService.isStared(req.user, dto);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('documents')
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getDocuments(@Request() req) {
return await this.collectorService.getDocuments(req.user);
}
@UseInterceptors(ClassSerializerInterceptor)
@Post('wikis')
@Get(CollectorApiDefinition.wikis.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getWikis(@Request() req) {
return await this.collectorService.getWikis(req.user);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get(CollectorApiDefinition.documents.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getDocuments(@Request() req) {
return await this.collectorService.getDocuments(req.user);
}
}

View File

@ -4,10 +4,12 @@ import {
Body,
ClassSerializerInterceptor,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Patch,
Post,
Query,
Request,
@ -15,13 +17,17 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { CommentService } from '@services/comment.service';
import { CommentApiDefinition } from '@think/domains';
@Controller('comment')
export class CommentController {
constructor(private readonly commentService: CommentService) {}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('add')
@Post(CommentApiDefinition.add.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async create(@Request() req, @Body() dto: CommentDto) {
@ -29,24 +35,33 @@ export class CommentController {
return await this.commentService.create(req.user, userAgent, dto);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('update')
@Patch(CommentApiDefinition.update.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async updateComment(@Request() req, @Body() dto: UpdateCommentDto) {
return await this.commentService.updateComment(req.user, dto);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('delete/:id')
@Delete(CommentApiDefinition.delete.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async deleteComment(@Request() req, @Param('id') documentId) {
return await this.commentService.deleteComment(req.user, documentId);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('document/:id')
@Get(CommentApiDefinition.documents.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getArticleComments(@Param('id') documentId, @Query() qurey) {

View File

@ -14,6 +14,7 @@ import {
HttpCode,
HttpStatus,
Param,
Patch,
Post,
Query,
Request,
@ -21,7 +22,7 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { DocumentService } from '@services/document.service';
import { DocumentStatus } from '@think/domains';
import { DocumentApiDefinition, DocumentStatus } from '@think/domains';
@Controller('document')
@UseGuards(DocumentAuthorityGuard)
@ -29,8 +30,38 @@ import { DocumentStatus } from '@think/domains';
export class DocumentController {
constructor(private readonly documentService: DocumentService) {}
/**
*
* @param req
* @param keyword
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('create')
@Get(DocumentApiDefinition.search.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async search(@Request() req, @Query('keyword') keyword) {
return await this.documentService.search(req.user, keyword);
}
/**
* 访
* @param req
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get(DocumentApiDefinition.recent.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getWorkspaceDocuments(@Request() req) {
return await this.documentService.getRecentDocuments(req.user);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post(DocumentApiDefinition.create.server)
@HttpCode(HttpStatus.CREATED)
@UseGuards(JwtGuard)
async createDocument(@Request() req, @Body() dto: CreateDocumentDto) {
@ -44,7 +75,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('detail/:id')
@Get(DocumentApiDefinition.getDetailById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('readable')
@UseGuards(JwtGuard)
@ -60,7 +91,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('update/:id')
@Patch(DocumentApiDefinition.updateById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('editable')
@UseGuards(JwtGuard)
@ -75,7 +106,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('version/:id')
@Get(DocumentApiDefinition.getVersionById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('readable')
@UseGuards(JwtGuard)
@ -83,66 +114,6 @@ export class DocumentController {
return await this.documentService.getDocumentVersion(req.user, documentId);
}
/**
*
* @param req
* @param data
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('children')
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('readable')
@UseGuards(JwtGuard)
async getChildrenDocuments(@Request() req, @Body() data) {
return await this.documentService.getChildrenDocuments(req.user, data);
}
/**
*
* @param req
* @param documentId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Delete('delete/:id')
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('createUser')
@UseGuards(JwtGuard)
async deleteDocument(@Request() req, @Param('id') documentId) {
return await this.documentService.deleteDocument(req.user, documentId);
}
/**
*
* @param req
* @param documentId
* @param dto
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('share/:id')
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('editable')
@UseGuards(JwtGuard)
async shareDocument(@Request() req, @Param('id') documentId, @Body() dto: ShareDocumentDto) {
return await this.documentService.shareDocument(req.user, documentId, dto);
}
/**
*
* @param req
* @param keyword
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('search')
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async search(@Request() req, @Query('keyword') keyword) {
return await this.documentService.search(req.user, keyword);
}
/**
*
* @param req
@ -150,7 +121,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('user/:id')
@Get(DocumentApiDefinition.getMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('readable')
@UseGuards(JwtGuard)
@ -166,7 +137,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('user/:id/add')
@Post(DocumentApiDefinition.addMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('createUser')
@UseGuards(JwtGuard)
@ -182,7 +153,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('user/:id/update')
@Patch(DocumentApiDefinition.updateMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('createUser')
@UseGuards(JwtGuard)
@ -198,7 +169,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('user/:id/delete')
@Post(DocumentApiDefinition.deleteMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('createUser')
@UseGuards(JwtGuard)
@ -207,16 +178,49 @@ export class DocumentController {
}
/**
* 访
*
* @param req
* @param data
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('recent')
@Post(DocumentApiDefinition.getChildren.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('readable')
@UseGuards(JwtGuard)
async getWorkspaceDocuments(@Request() req) {
return await this.documentService.getRecentDocuments(req.user);
async getChildrenDocuments(@Request() req, @Body() data) {
return await this.documentService.getChildrenDocuments(req.user, data);
}
/**
*
* @param req
* @param documentId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Delete(DocumentApiDefinition.deleteById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('createUser')
@UseGuards(JwtGuard)
async deleteDocument(@Request() req, @Param('id') documentId) {
return await this.documentService.deleteDocument(req.user, documentId);
}
/**
*
* @param req
* @param documentId
* @param dto
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post(DocumentApiDefinition.shareById.server)
@HttpCode(HttpStatus.OK)
@CheckDocumentAuthority('editable')
@UseGuards(JwtGuard)
async shareDocument(@Request() req, @Param('id') documentId, @Body() dto: ShareDocumentDto) {
return await this.documentService.shareDocument(req.user, documentId, dto);
}
/**
@ -227,7 +231,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('public/detail/:id')
@Post(DocumentApiDefinition.getPublicDetailById.server)
@CheckDocumentStatus(DocumentStatus.public)
@HttpCode(HttpStatus.OK)
async getShareDocumentDetail(@Request() req, @Param('id') documentId, @Body() dto: ShareDocumentDto) {
@ -240,7 +244,7 @@ export class DocumentController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('public/children')
@Post(DocumentApiDefinition.getPublicChildren.server)
@CheckDocumentStatus(DocumentStatus.public)
@HttpCode(HttpStatus.OK)
async getShareChildrenDocuments(@Body() data) {

View File

@ -2,6 +2,7 @@ import { JwtGuard } from '@guard/jwt.guard';
import { Controller, Post, UploadedFile, UseGuards, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { FileService } from '@services/file.service';
import { FileApiDefinition } from '@think/domains';
@Controller('file')
export class FileController {
@ -11,7 +12,7 @@ export class FileController {
*
* @param file
*/
@Post('upload')
@Post(FileApiDefinition.upload.server)
@UseInterceptors(
FileInterceptor('file', {
limits: {

View File

@ -13,37 +13,50 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { MessageService } from '@services/message.service';
import { MessageApiDefinition } from '@think/domains';
@Controller('message')
export class MessageController {
constructor(private readonly messageService: MessageService) {}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('/unread')
@Get(MessageApiDefinition.getUnread.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getUnreadMessages(@Request() req, @Query() query) {
return this.messageService.getMessages(req.user, false, query);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('/read')
@Get(MessageApiDefinition.getRead.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getReadMessages(@Request() req, @Query() query) {
return this.messageService.getMessages(req.user, true, query);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('/all')
@Get(MessageApiDefinition.getAll.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getAllReadMessages(@Request() req, @Query() query) {
return this.messageService.getAllMessages(req.user, query);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('/read/:id')
@Post(MessageApiDefinition.readMessage.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async updateComment(@Request() req, @Param('id') messageId) {

View File

@ -4,10 +4,12 @@ import {
Body,
ClassSerializerInterceptor,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Patch,
Post,
Query,
Request,
@ -15,55 +17,74 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { TemplateService } from '@services/template.service';
import { TemplateApiDefinition } from '@think/domains';
@Controller('template')
export class TemplateController {
constructor(private readonly templateService: TemplateService) {}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('add')
@Get(TemplateApiDefinition.public.server)
@HttpCode(HttpStatus.OK)
async getPublicTemplates(@Query() qurey) {
return this.templateService.getPublicTemplates(qurey);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get(TemplateApiDefinition.own.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getOwnTemplates(@Request() req, @Query() qurey) {
return this.templateService.getOwnTemplates(req.user, qurey);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post(TemplateApiDefinition.add.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async create(@Request() req, @Body() dto: TemplateDto) {
return await this.templateService.create(req.user, dto);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('update')
@Patch(TemplateApiDefinition.updateById.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async updateTemplat(@Request() req, @Body() dto: TemplateDto & { id: string }) {
return await this.templateService.updateTemplate(req.user, dto.id, dto);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('delete/:id')
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async deleteTemplat(@Request() req, @Param('id') documentId) {
return await this.templateService.deleteTemplate(req.user, documentId);
}
@UseInterceptors(ClassSerializerInterceptor)
@Get('detail/:id')
@Get(TemplateApiDefinition.getDetailById.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getTemplate(@Request() req, @Param('id') id) {
return this.templateService.getTemplate(req.user, id);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('public')
@HttpCode(HttpStatus.OK)
async getPublicTemplates(@Query() qurey) {
return this.templateService.getPublicTemplates(qurey);
}
@UseInterceptors(ClassSerializerInterceptor)
@Get('own')
@Delete(TemplateApiDefinition.deleteById.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getOwnTemplates(@Request() req, @Query() qurey) {
return this.templateService.getOwnTemplates(req.user, qurey);
async deleteTemplat(@Request() req, @Param('id') documentId) {
return await this.templateService.deleteTemplate(req.user, documentId);
}
}

View File

@ -17,21 +17,39 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { UserService } from '@services/user.service';
import { UserApiDefinition } from '@think/domains';
import { Response as ExpressResponse } from 'express';
@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('register')
@Get(UserApiDefinition.getAllUsers.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getUsers() {
return this.userService.getUsers();
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post(UserApiDefinition.register.server)
@HttpCode(HttpStatus.CREATED)
async register(@Body() user: CreateUserDto) {
return await this.userService.createUser(user);
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('login')
@Post(UserApiDefinition.login.server)
@HttpCode(HttpStatus.OK)
async login(@Body() user: LoginUserDto, @Res({ passthrough: true }) response: ExpressResponse) {
const { user: data, token } = await this.userService.login(user);
@ -39,25 +57,23 @@ export class UserController {
return { ...data, token };
}
@Get('logout')
/**
*
*/
@Get(UserApiDefinition.logout.server)
async logout(@Res({ passthrough: true }) response: ExpressResponse) {
response.cookie('token', '', { expires: new Date() });
return;
}
/**
*
*/
@UseInterceptors(ClassSerializerInterceptor)
@Patch('update')
@Patch(UserApiDefinition.update.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async updateUser(@Request() req, @Body() dto: UpdateUserDto) {
return await this.userService.updateUser(req.user, dto);
}
@UseInterceptors(ClassSerializerInterceptor)
@Get('/')
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getUsers() {
return this.userService.getUsers();
}
}

View File

@ -22,26 +22,12 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { WikiService } from '@services/wiki.service';
import { IPagination, WikiStatus, WikiUserRole } from '@think/domains';
import { IPagination, WikiApiDefinition, WikiStatus, WikiUserRole } from '@think/domains';
@Controller('wiki')
export class WikiController {
constructor(private readonly wikiService: WikiService) {}
/**
*
* @param req
* @param dto
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('create')
@HttpCode(HttpStatus.CREATED)
@UseGuards(JwtGuard)
async register(@Request() req, @Body() dto: CreateWikiDto) {
return await this.wikiService.createWiki(req.user, dto);
}
/**
*
* @param req
@ -49,7 +35,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('list/all')
@Get(WikiApiDefinition.getAllWikis.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getAllWikis(@Request() req, @Query() pagination: IPagination) {
@ -63,7 +49,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('list/own')
@Get(WikiApiDefinition.getOwnWikis.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getOwnWikis(@Request() req, @Query() pagination: IPagination) {
@ -77,7 +63,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('list/join')
@Get(WikiApiDefinition.getJoinWikis.server)
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async getJoinWikis(@Request() req, @Query() pagination: IPagination) {
@ -85,19 +71,17 @@ export class WikiController {
}
/**
*
*
* @param req
* @param wikiId
* @param dto
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('detail/:id')
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@Post(WikiApiDefinition.add.server)
@HttpCode(HttpStatus.CREATED)
@UseGuards(JwtGuard)
async getWikiDetail(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiDetail(req.user, wikiId);
async register(@Request() req, @Body() dto: CreateWikiDto) {
return await this.wikiService.createWiki(req.user, dto);
}
/**
@ -107,7 +91,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('homedoc/:id')
@Get(WikiApiDefinition.getHomeDocumentById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@ -116,6 +100,71 @@ export class WikiController {
return await this.wikiService.getWikiHomeDocument(req.user, wikiId);
}
/**
*
* @param req
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get(WikiApiDefinition.getTocsById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async getWikiTocs(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiTocs(req.user, wikiId);
}
/**
*
* @param req
* @param wikiId
* @param relations
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Patch(WikiApiDefinition.updateTocsById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async orderWikiTocs(@Body() relations) {
return await this.wikiService.orderWikiTocs(relations);
}
/**
*
* @param req
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get(WikiApiDefinition.getDocumentsById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async getWikiDocs(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiDocs(req.user, wikiId);
}
/**
*
* @param req
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get(WikiApiDefinition.getDetailById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async getWikiDetail(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiDetail(req.user, wikiId);
}
/**
*
*
@ -125,7 +174,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Patch('update/:id')
@Patch(WikiApiDefinition.updateById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -142,7 +191,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Delete('delete/:id')
@Delete(WikiApiDefinition.deleteById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -159,7 +208,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('user/:id')
@Get(WikiApiDefinition.getMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -177,7 +226,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('user/:id/add')
@Post(WikiApiDefinition.addMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -195,7 +244,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('user/:id/update')
@Patch(WikiApiDefinition.updateMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -213,7 +262,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('user/:id/delete')
@Delete(WikiApiDefinition.deleteMemberById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -231,7 +280,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('share/:id')
@Post(WikiApiDefinition.shareById.server)
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@ -240,59 +289,6 @@ export class WikiController {
return await this.wikiService.shareWiki(req.user, wikiId, dto);
}
/**
*
* @param req
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('tocs/:id')
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async getWikiTocs(@Request() req, @Param('id') wikiId) {
const sleep = (v) => {
return new Promise((r) => setTimeout(r, v * 1000));
};
await sleep(4);
return await this.wikiService.getWikiTocs(req.user, wikiId);
}
/**
*
* @param req
* @param wikiId
* @param relations
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('tocs/:id/update')
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async orderWikiTocs(@Body() relations) {
return await this.wikiService.orderWikiTocs(relations);
}
/**
*
* @param req
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('docs/:id')
@HttpCode(HttpStatus.OK)
@CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard)
async getWikiDocs(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiDocs(req.user, wikiId);
}
/**
*
* @param req
@ -300,7 +296,7 @@ export class WikiController {
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Get('public/homedoc/:id')
@Get(WikiApiDefinition.getPublicHomeDocumentById.server)
@CheckWikiStatus(WikiStatus.public)
@UseGuards(WikiStatusGuard)
@HttpCode(HttpStatus.OK)
@ -308,20 +304,6 @@ export class WikiController {
return await this.wikiService.getPublicWikiHomeDocument(wikiId, req.headers['user-agent']);
}
/**
*
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post('public/detail/:id')
@CheckWikiStatus(WikiStatus.public)
@UseGuards(WikiStatusGuard)
@HttpCode(HttpStatus.OK)
async getPublicWorkspaceDetail(@Param('id') wikiId) {
return await this.wikiService.getPublicWikiDetail(wikiId);
}
/**
*
* @param wikiId
@ -329,13 +311,27 @@ export class WikiController {
*/
@UseInterceptors(ClassSerializerInterceptor)
@HttpCode(HttpStatus.OK)
@Post('public/tocs/:id')
@Post(WikiApiDefinition.getPublicTocsById.server)
@CheckWikiStatus(WikiStatus.public)
@UseGuards(WikiStatusGuard)
async getPublicWikiTocs(@Param('id') wikiId) {
return await this.wikiService.getPublicWikiTocs(wikiId);
}
/**
*
* @param wikiId
* @returns
*/
@UseInterceptors(ClassSerializerInterceptor)
@Post(WikiApiDefinition.getPublicDetailById.server)
@CheckWikiStatus(WikiStatus.public)
@UseGuards(WikiStatusGuard)
@HttpCode(HttpStatus.OK)
async getPublicWorkspaceDetail(@Param('id') wikiId) {
return await this.wikiService.getPublicWikiDetail(wikiId);
}
/**
*
* @param pagination
@ -343,7 +339,7 @@ export class WikiController {
*/
@UseInterceptors(ClassSerializerInterceptor)
@HttpCode(HttpStatus.OK)
@Get('public/wikis')
@Get(WikiApiDefinition.getPublicWikis.server)
async getAllPublicWikis(@Query() pagination: IPagination) {
return await this.wikiService.getAllPublicWikis(pagination);
}

View File

@ -236,7 +236,7 @@ importers:
eslint: 8.14.0
eslint-config-prettier: 8.5.0_eslint@8.14.0
eslint-plugin-import: 2.26.0_eslint@8.14.0
eslint-plugin-prettier: 4.0.0_740be41c8168d0cc214a306089357ad0
eslint-plugin-prettier: 4.0.0_74ebb802163a9b4fa8f89d76ed02f62a
eslint-plugin-react: 7.29.4_eslint@8.14.0
eslint-plugin-react-hooks: 4.5.0_eslint@8.14.0
eslint-plugin-simple-import-sort: 7.0.0_eslint@8.14.0
@ -5415,6 +5415,22 @@ packages:
prettier-linter-helpers: 1.0.0
dev: true
/eslint-plugin-prettier/4.0.0_74ebb802163a9b4fa8f89d76ed02f62a:
resolution: {integrity: sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ==}
engines: {node: '>=6.0.0'}
peerDependencies:
eslint: '>=7.28.0'
eslint-config-prettier: '*'
prettier: '>=2.0.0'
peerDependenciesMeta:
eslint-config-prettier:
optional: true
dependencies:
eslint: 8.14.0
eslint-config-prettier: 8.5.0_eslint@8.14.0
prettier-linter-helpers: 1.0.0
dev: true
/eslint-plugin-react-hooks/4.5.0_eslint@8.14.0:
resolution: {integrity: sha512-8k1gRt7D7h03kd+SAAlzXkQwWK22BnK6GKZG+FJA6BAGy22CFvl8kCIXKpVux0cCxMWDQUPqSok0LKaZ0aOcCw==}
engines: {node: '>=10'}