1 import { HttpStatusCode, ResultList } from '@shared/models'
2 import { UserNotification, UserNotificationSetting } from '../../models/users'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 export class NotificationsCommand extends AbstractCommand {
7 updateMySettings (options: OverrideCommandOptions & {
8 settings: UserNotificationSetting
10 const path = '/api/v1/users/me/notification-settings'
12 return this.putBodyRequest({
16 fields: options.settings,
18 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
22 list (options: OverrideCommandOptions & {
28 const { start, count, unread, sort = '-createdAt' } = options
29 const path = '/api/v1/users/me/notifications'
31 return this.getRequestBody<ResultList<UserNotification>>({
42 defaultExpectedStatus: HttpStatusCode.OK_200
46 markAsRead (options: OverrideCommandOptions & {
49 const { ids } = options
50 const path = '/api/v1/users/me/notifications/read'
52 return this.postBodyRequest({
58 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
62 markAsReadAll (options: OverrideCommandOptions) {
63 const path = '/api/v1/users/me/notifications/read-all'
65 return this.postBodyRequest({
70 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
74 async getLastest (options: OverrideCommandOptions = {}) {
75 const { total, data } = await this.list({
82 if (total === 0) return undefined