yumechi-no-kuni/src/server/api/endpoints/notifications/mark_all_as_read.ts

45 lines
900 B
TypeScript
Raw Normal View History

2018-03-29 06:32:18 -05:00
import Notification from '../../../../models/notification';
2018-07-29 17:20:27 -05:00
import { publishUserStream } from '../../../../stream';
2018-06-17 19:54:53 -05:00
import User, { ILocalUser } from '../../../../models/user';
2018-07-16 14:36:44 -05:00
export const meta = {
desc: {
ja: '全ての通知を既読にします。',
en: 'Mark all notifications as read.'
2018-07-16 14:36:44 -05:00
},
requireCredential: true,
kind: 'notification-write'
};
/**
* Mark all notifications as read
*/
2018-07-05 12:58:29 -05:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Update documents
await Notification.update({
2018-03-29 00:48:47 -05:00
notifieeId: user._id,
isRead: false
}, {
$set: {
isRead: true
}
}, {
multi: true
});
// Response
res();
2018-05-28 11:22:39 -05:00
// Update flag
User.update({ _id: user._id }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての通知を読みましたよというイベントを発行
2018-07-29 17:20:27 -05:00
publishUserStream(user._id, 'read_all_notifications');
});