summaryrefslogtreecommitdiff
path: root/src/api/serializers/channel.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-10-31 21:42:11 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-10-31 21:42:11 +0900
commitdc9fddf839df7959a83819eb7064f402db05f200 (patch)
treef0abfda87a835186a605d839e5c3904bc78b9593 /src/api/serializers/channel.ts
parentMerge remote-tracking branch 'refs/remotes/origin/master' into bbs (diff)
downloadmisskey-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.ts44
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);
+});