think/packages/domains/src/util.ts

84 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-03-11 05:57:55 +00:00
import {
WikiStatus,
WikiUserRole,
DocumentStatus,
IWiki,
IDocument,
} from "./models";
/**
*
*/
export const WIKI_STATUS_LIST = [
{
value: WikiStatus.private,
label: "私有",
},
{
value: WikiStatus.public,
label: "公开",
},
];
/**
*
*/
export const WIKI_USER_ROLES = [
{
value: "admin",
label: "管理员",
},
{
value: "normal",
label: "成员",
},
];
/**
*
*/
export const DOCUMENT_STATUS = [
{
value: DocumentStatus.private,
label: "私有",
},
{
value: DocumentStatus.public,
label: "公开",
},
];
/**
*
* @param wiki
* @returns
*/
export const getWikiStatusText = (wiki: IWiki): string => {
return WIKI_STATUS_LIST.find((t) => t.value === wiki.status).label;
};
/**
*
* @param currentStatus wiki status
* @returns
*/
export const isPublicWiki = (currentStatus: IWiki["status"]) =>
currentStatus === WikiStatus.public;
/**
*
* @param role role
* @returns
*/
export const getWikiUserRoleText = (role: WikiUserRole) => {
return WIKI_USER_ROLES.find((d) => d.value === role).label;
};
/**
*
* @param currentStatus document status
* @returns
*/
export const isPublicDocument = (currentStatus: IDocument["status"]) =>
currentStatus === DocumentStatus.public;