notification.ts 2.27 KB
import { AttributeData, QueryForParams, ServiceResponse } from '@/types/global';

// eslint-disable-next-line import/no-cycle
import { Notification } from '@/utils/model';
import axios from 'axios';

export default class useNotificationApi {
  static typeOption = [
    { value: 1, label: '文本' },
    { value: 2, label: '图文' },
  ];

  static alertOption = [
    { value: 1, label: '弹出' },
    { value: 0, label: '不弹出' },
  ];

  static statusOption = [
    { value: 0, label: '待发送' },
    { value: 1, label: '处理中' },
    { value: 2, label: '已发送' },
    { value: -1, label: '发送失败' },
    { value: -2, label: '取消发送' },
    { value: 3, label: '已撤销' },
  ];

  static publishTypeOption = [
    { value: 1, label: '立即发送' },
    { value: 2, label: '定时发送' },
  ];

  static linkTypeOption = [
    { value: 'none', label: '无' },
    { value: 'user', label: '用户' },
    { value: 'activity', label: '歌曲' },
    { value: 'project', label: '厂牌' },
    { value: 'rich', label: '自定义H5页面' },
  ];

  static get(params?: QueryForParams): Promise<ServiceResponse<Notification[]>> {
    return axios.get('system/notification', { params });
  }

  static async create(data?: AttributeData): Promise<Notification> {
    return axios.post('system/notification', data).then((res) => Promise.resolve(res.data));
  }

  static async show(id: number): Promise<Notification> {
    return axios.get(`system/notification/${id}`).then((res) => Promise.resolve(res.data));
  }

  static async update(id: number, data = {}): Promise<Notification> {
    return axios.put(`system/notification/${id}`, data).then((res) => Promise.resolve(res.data));
  }

  static async user(id: number, params?: QueryForParams) {
    return axios.get(`system/notification/${id}/users`, { params });
  }

  static async send(id: number): Promise<unknown> {
    return axios.put(`system/notification/${id}/send`).then((res) => Promise.resolve(res.data));
  }

  static async cancel(id: number): Promise<unknown> {
    return axios.put(`system/notification/${id}/cancel`).then((res) => Promise.resolve(res.data));
  }

  static async rollback(id: number): Promise<unknown> {
    return axios.put(`system/notification/${id}/rollback`).then((res) => Promise.resolve(res.data));
  }
}