think/packages/domains/src/util.ts

76 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-03-12 02:31:03 +00:00
import { WikiStatus, WikiUserRole, DocumentStatus, IWiki, IDocument } from './models';
2022-03-11 05:57:55 +00:00
/**
*
*/
export const WIKI_STATUS_LIST = [
{
value: WikiStatus.private,
2022-03-12 02:31:03 +00:00
label: '私有',
2022-03-11 05:57:55 +00:00
},
{
value: WikiStatus.public,
2022-03-12 02:31:03 +00:00
label: '公开',
2022-03-11 05:57:55 +00:00
},
];
/**
*
*/
export const WIKI_USER_ROLES = [
{
2022-03-12 02:31:03 +00:00
value: 'admin',
label: '管理员',
2022-03-11 05:57:55 +00:00
},
{
2022-03-12 02:31:03 +00:00
value: 'normal',
label: '成员',
2022-03-11 05:57:55 +00:00
},
];
/**
*
*/
export const DOCUMENT_STATUS = [
{
value: DocumentStatus.private,
2022-03-12 02:31:03 +00:00
label: '私有',
2022-03-11 05:57:55 +00:00
},
{
value: DocumentStatus.public,
2022-03-12 02:31:03 +00:00
label: '公开',
2022-03-11 05:57:55 +00:00
},
];
/**
*
* @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
*/
2022-03-12 02:31:03 +00:00
export const isPublicWiki = (currentStatus: IWiki['status']) => currentStatus === WikiStatus.public;
2022-03-11 05:57:55 +00:00
/**
*
* @param role role
* @returns
*/
export const getWikiUserRoleText = (role: WikiUserRole) => {
return WIKI_USER_ROLES.find((d) => d.value === role).label;
};
/**
*
* @param currentStatus document status
* @returns
*/
2022-03-22 05:37:53 +00:00
export const isPublicDocument = (currentStatus: IDocument['status']) => currentStatus === DocumentStatus.public;