diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-10-31 21:42:11 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-10-31 21:42:11 +0900 |
| commit | dc9fddf839df7959a83819eb7064f402db05f200 (patch) | |
| tree | f0abfda87a835186a605d839e5c3904bc78b9593 /src/api/serializers/channel.ts | |
| parent | Merge remote-tracking branch 'refs/remotes/origin/master' into bbs (diff) | |
| download | misskey-dc9fddf839df7959a83819eb7064f402db05f200.tar.gz misskey-dc9fddf839df7959a83819eb7064f402db05f200.tar.bz2 misskey-dc9fddf839df7959a83819eb7064f402db05f200.zip | |
RENAME: bbs -> channel
Diffstat (limited to 'src/api/serializers/channel.ts')
| -rw-r--r-- | src/api/serializers/channel.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/api/serializers/channel.ts b/src/api/serializers/channel.ts new file mode 100644 index 0000000000..d4e16d6be3 --- /dev/null +++ b/src/api/serializers/channel.ts @@ -0,0 +1,44 @@ +/** + * Module dependencies + */ +import * as mongo from 'mongodb'; +import deepcopy = require('deepcopy'); +import { IUser } from '../models/user'; +import { default as Channel, IChannel } from '../models/channel'; + +/** + * Serialize a channel + * + * @param channel target + * @param me? serializee + * @return response + */ +export default ( + channel: string | mongo.ObjectID | IChannel, + me?: string | mongo.ObjectID | IUser +) => new Promise<any>(async (resolve, reject) => { + + let _channel: any; + + // Populate the channel if 'channel' is ID + if (mongo.ObjectID.prototype.isPrototypeOf(channel)) { + _channel = await Channel.findOne({ + _id: channel + }); + } else if (typeof channel === 'string') { + _channel = await Channel.findOne({ + _id: new mongo.ObjectID(channel) + }); + } else { + _channel = deepcopy(channel); + } + + // Rename _id to id + _channel.id = _channel._id; + delete _channel._id; + + // Remove needless properties + delete _channel.user_id; + + resolve(_channel); +}); |