Created
January 20, 2019 19:40
-
-
Save krvajal/d97858aad62dd095d3b3a761110cd329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// V1 | |
export class NotificationsRequests extends SweepbrightCrudRequest { | |
constructor() { | |
super(); | |
// @ts-ignore | |
this.setMiddlewares([parseJson, response => response.data]); | |
} | |
getAll = (attributes: { page: number }): Promise<NotificationsResponse> => { | |
return this.withQueryParameters(attributes).get('notifications'); | |
}; | |
readNotification(notificationId: string): Promise<Notification> { | |
return this.put(`/notification/${notificationId}`, { | |
last_read_at: new Date().toISOString(), | |
}); | |
} | |
readAllNotifications = () => { | |
return this.put('notifications', { | |
last_read_at: new Date().toISOString(), | |
}); | |
}; | |
} | |
// V2 | |
export default function NotificationsRequests(httpClient: CrudRequest = new SweepbrightCrudRequest()) { | |
httpClient.setMiddlewares([parseJson, response => response.data]); | |
const _userId = () => { | |
return AuthManager.getUser().id; | |
}; | |
const getAll = (attributes: { page: number }): Promise<NotificationsResponse> => { | |
return httpClient.withQueryParameters({ ...attributes, limit: 50 }).get(`users/${_userId()}/notifications`); | |
}; | |
const readNotification = (notificationId: string): Promise<Notification> => { | |
return httpClient.put(`users/${_userId()}/notifications/${notificationId}`, { | |
last_read_at: new Date().toISOString(), | |
}); | |
}; | |
const readAllNotifications = () => { | |
return httpClient.put(`users/${_userId()}/notifications/read-all`, { | |
last_read_at: new Date().toISOString(), | |
}); | |
}; | |
return { | |
getAll, | |
readNotification, | |
readAllNotifications, | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment