1 import { ResultList } from '@shared/models'
2 import { HttpStatusCode } from '@shared/models'
3 import { UserNotification, UserNotificationSetting } from '../../models/users'
4 import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 export class NotificationsCommand extends AbstractCommand {
8 updateMySettings (options: OverrideCommandOptions & {
9 settings: UserNotificationSetting
11 const path = '/api/v1/users/me/notification-settings'
13 return this.putBodyRequest({
17 fields: options.settings,
19 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
23 list (options: OverrideCommandOptions & {
29 const { start, count, unread, sort = '-createdAt' } = options
30 const path = '/api/v1/users/me/notifications'
32 return this.getRequestBody<ResultList<UserNotification>>({
43 defaultExpectedStatus: HttpStatusCode.OK_200
47 markAsRead (options: OverrideCommandOptions & {
50 const { ids } = options
51 const path = '/api/v1/users/me/notifications/read'
53 return this.postBodyRequest({
59 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
63 markAsReadAll (options: OverrideCommandOptions) {
64 const path = '/api/v1/users/me/notifications/read-all'
66 return this.postBodyRequest({
71 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
75 async getLastest (options: OverrideCommandOptions = {}) {
76 const { total, data } = await this.list({
83 if (total === 0) return undefined