From 0ef280377bbbd357bef688ab5c7fd609fd78af72 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 15 Apr 2018 06:34:55 +0900 Subject: wip --- src/models/notification.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/models/notification.ts') diff --git a/src/models/notification.ts b/src/models/notification.ts index d5ca7135b7..76871166a9 100644 --- a/src/models/notification.ts +++ b/src/models/notification.ts @@ -49,6 +49,33 @@ export interface INotification { isRead: Boolean; } +/** + * Notificationを物理削除します + */ +export async function deleteNotification(notification: string | mongo.ObjectID | INotification) { + let n: INotification; + + // Populate + if (mongo.ObjectID.prototype.isPrototypeOf(notification)) { + n = await Notification.findOne({ + _id: notification + }); + } else if (typeof notification === 'string') { + n = await Notification.findOne({ + _id: new mongo.ObjectID(notification) + }); + } else { + n = notification as INotification; + } + + if (n == null) return; + + // このNotificationを削除 + await Notification.remove({ + _id: n._id + }); +} + /** * Pack a notification for API response */ -- cgit v1.2.3-freya