diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-02-04 15:02:14 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-04 15:02:14 +0900 |
| commit | 744c3e2ef8ef89355f72262b1e8c8f2fbb020f2a (patch) | |
| tree | de3630065fcddeb1916668ef3b0b43a219340e2e /src/api/serializers/notification.ts | |
| parent | Update dependencies :rocket: (diff) | |
| parent | wip (diff) | |
| download | sharkey-744c3e2ef8ef89355f72262b1e8c8f2fbb020f2a.tar.gz sharkey-744c3e2ef8ef89355f72262b1e8c8f2fbb020f2a.tar.bz2 sharkey-744c3e2ef8ef89355f72262b1e8c8f2fbb020f2a.zip | |
Merge pull request #1097 from syuilo/refactor
Refactor
Diffstat (limited to 'src/api/serializers/notification.ts')
| -rw-r--r-- | src/api/serializers/notification.ts | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/api/serializers/notification.ts b/src/api/serializers/notification.ts deleted file mode 100644 index ac919dc8b0..0000000000 --- a/src/api/serializers/notification.ts +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Module dependencies - */ -import * as mongo from 'mongodb'; -import Notification from '../models/notification'; -import serializeUser from './user'; -import serializePost from './post'; -import deepcopy = require('deepcopy'); - -/** - * Serialize a notification - * - * @param {any} notification - * @return {Promise<any>} - */ -export default (notification: any) => new Promise<any>(async (resolve, reject) => { - let _notification: any; - - // Populate the notification if 'notification' is ID - if (mongo.ObjectID.prototype.isPrototypeOf(notification)) { - _notification = await Notification.findOne({ - _id: notification - }); - } else if (typeof notification === 'string') { - _notification = await Notification.findOne({ - _id: new mongo.ObjectID(notification) - }); - } else { - _notification = deepcopy(notification); - } - - // Rename _id to id - _notification.id = _notification._id; - delete _notification._id; - - // Rename notifier_id to user_id - _notification.user_id = _notification.notifier_id; - delete _notification.notifier_id; - - const me = _notification.notifiee_id; - delete _notification.notifiee_id; - - // Populate notifier - _notification.user = await serializeUser(_notification.user_id, me); - - switch (_notification.type) { - case 'follow': - // nope - break; - case 'mention': - case 'reply': - case 'repost': - case 'quote': - case 'reaction': - case 'poll_vote': - // Populate post - _notification.post = await serializePost(_notification.post_id, me); - break; - default: - console.error(`Unknown type: ${_notification.type}`); - break; - } - - resolve(_notification); -}); |