Optimize notification endpoint
This commit is contained in:
parent
c511c3f010
commit
119b16e5ac
1 changed files with 11 additions and 11 deletions
|
@ -337,25 +337,25 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
|
||||||
ActorFollow: ActorFollowModel
|
ActorFollow: ActorFollowModel
|
||||||
|
|
||||||
static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
|
static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
|
||||||
|
const where = { userId }
|
||||||
|
|
||||||
const query: FindOptions = {
|
const query: FindOptions = {
|
||||||
offset: start,
|
offset: start,
|
||||||
limit: count,
|
limit: count,
|
||||||
order: getSort(sort),
|
order: getSort(sort),
|
||||||
where: {
|
where
|
||||||
userId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unread !== undefined) query.where['read'] = !unread
|
if (unread !== undefined) query.where['read'] = !unread
|
||||||
|
|
||||||
return UserNotificationModel.scope(ScopeNames.WITH_ALL)
|
return Promise.all([
|
||||||
.findAndCountAll(query)
|
UserNotificationModel.count({ where })
|
||||||
.then(({ rows, count }) => {
|
.then(count => count || 0),
|
||||||
return {
|
|
||||||
data: rows,
|
count === 0
|
||||||
total: count
|
? []
|
||||||
}
|
: UserNotificationModel.scope(ScopeNames.WITH_ALL).findAll(query)
|
||||||
})
|
]).then(([ total, data ]) => ({ total, data }))
|
||||||
}
|
}
|
||||||
|
|
||||||
static markAsRead (userId: number, notificationIds: number[]) {
|
static markAsRead (userId: number, notificationIds: number[]) {
|
||||||
|
|
Loading…
Reference in a new issue