1 import { HttpStatusCode, ResultList, UserNotification, UserNotificationSetting } from '@shared/models'
2 import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 export class NotificationsCommand extends AbstractCommand {
6 updateMySettings (options: OverrideCommandOptions & {
7 settings: UserNotificationSetting
9 const path = '/api/v1/users/me/notification-settings'
11 return this.putBodyRequest({
15 fields: options.settings,
17 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
21 list (options: OverrideCommandOptions & {
27 const { start, count, unread, sort = '-createdAt' } = options
28 const path = '/api/v1/users/me/notifications'
30 return this.getRequestBody<ResultList<UserNotification>>({
41 defaultExpectedStatus: HttpStatusCode.OK_200
45 markAsRead (options: OverrideCommandOptions & {
48 const { ids } = options
49 const path = '/api/v1/users/me/notifications/read'
51 return this.postBodyRequest({
57 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
61 markAsReadAll (options: OverrideCommandOptions) {
62 const path = '/api/v1/users/me/notifications/read-all'
64 return this.postBodyRequest({
69 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
73 async getLatest (options: OverrideCommandOptions = {}) {
74 const { total, data } = await this.list({
81 if (total === 0) return undefined