1 import { LABEL_TYPE } from '../constants';
3 const { MESSAGE_LABEL, MESSAGE_FOLDER, CONTACT_GROUP, SYSTEM_FOLDER } = LABEL_TYPE;
5 export const get = (Type: number) => ({
11 interface PartialLabelOrderArgument {
13 ParentID?: string | number;
15 interface LabelOrderArgument extends PartialLabelOrderArgument {
18 export const order = ({ LabelIDs, ParentID, Type }: LabelOrderArgument) => ({
20 url: 'core/v4/labels/order',
21 data: { LabelIDs, ParentID, Type },
24 export const orderAllFolders = () => ({
26 url: 'core/v4/labels/order/tree',
29 interface PartialCreateLabelArgument {
32 ParentID?: string | number;
37 interface CreateLabelArgument extends PartialCreateLabelArgument {
40 export const create = ({ Name, Color, Type, Notify, ParentID, Expanded }: CreateLabelArgument) => ({
42 url: 'core/v4/labels',
43 data: { Name, Color, Type, Notify, ParentID, Expanded },
46 interface UpdateLabelArguments {
50 ParentID?: string | number;
55 export const updateLabel = (
57 { Name, Color, Notify, ParentID, Sticky, Expanded, Display }: UpdateLabelArguments
60 url: `core/v4/labels/${labelID}`,
61 data: { Name, Color, Notify, ParentID, Sticky, Expanded, Display },
64 export const deleteLabel = (labelID: string) => ({
66 url: `core/v4/labels/${labelID}`,
69 export const deleteLabels = (labelIDs: string[]) => ({
71 url: 'core/v4/labels',
72 data: { LabelIDs: labelIDs },
75 export const checkLabelAvailability = (params: { Name: string; Type: LABEL_TYPE; ParentID?: string | number }) => ({
77 url: 'core/v4/labels/available',
81 export const getLabels = () => get(MESSAGE_LABEL);
82 export const getFolders = () => get(MESSAGE_FOLDER);
83 export const getSystemFolders = () => get(SYSTEM_FOLDER);
84 export const getContactGroup = () => get(CONTACT_GROUP);
86 export const orderFolders = (opt: PartialLabelOrderArgument) => order({ ...opt, Type: MESSAGE_FOLDER });
87 export const orderLabels = (opt: PartialLabelOrderArgument) => order({ ...opt, Type: MESSAGE_LABEL });
88 export const orderSystemFolders = (opt: Pick<PartialLabelOrderArgument, 'LabelIDs'>) =>
89 order({ ...opt, ParentID: undefined, Type: SYSTEM_FOLDER });
90 export const orderContactGroup = (opt: PartialLabelOrderArgument) => order({ ...opt, Type: CONTACT_GROUP });
92 export const createLabel = (opt: PartialCreateLabelArgument) => create({ ...opt, Type: MESSAGE_LABEL });
93 export const createContactGroup = (opt: PartialCreateLabelArgument) => create({ ...opt, Type: CONTACT_GROUP });
95 export const updateSystemFolders = (labelId: string, opt: Pick<UpdateLabelArguments, 'Color' | 'Name' | 'Display'>) =>
96 updateLabel(labelId, { ...opt });