summaryrefslogtreecommitdiff
path: root/src/api/serializers
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-10-30 17:30:32 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-10-30 17:30:32 +0900
commit77528f022d2e9f76298331b55303cfc42359c7af (patch)
tree043b951c7ab28de28f2f4407b9eab6a0cd834019 /src/api/serializers
parenti18n (diff)
downloadmisskey-77528f022d2e9f76298331b55303cfc42359c7af.tar.gz
misskey-77528f022d2e9f76298331b55303cfc42359c7af.tar.bz2
misskey-77528f022d2e9f76298331b55303cfc42359c7af.zip
wip
Diffstat (limited to 'src/api/serializers')
-rw-r--r--src/api/serializers/bbs-thread.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/api/serializers/bbs-thread.ts b/src/api/serializers/bbs-thread.ts
new file mode 100644
index 0000000000..d9e41a8468
--- /dev/null
+++ b/src/api/serializers/bbs-thread.ts
@@ -0,0 +1,44 @@
+/**
+ * Module dependencies
+ */
+import * as mongo from 'mongodb';
+import deepcopy = require('deepcopy');
+import { IUser } from '../models/user';
+import { default as Thread, IBbsThread } from '../models/bbs-thread';
+
+/**
+ * Serialize a thread
+ *
+ * @param thread target
+ * @param me? serializee
+ * @return response
+ */
+export default (
+ thread: string | mongo.ObjectID | IBbsThread,
+ me?: string | mongo.ObjectID | IUser
+) => new Promise<any>(async (resolve, reject) => {
+
+ let _thread: any;
+
+ // Populate the thread if 'thread' is ID
+ if (mongo.ObjectID.prototype.isPrototypeOf(thread)) {
+ _thread = await Thread.findOne({
+ _id: thread
+ });
+ } else if (typeof thread === 'string') {
+ _thread = await Thread.findOne({
+ _id: new mongo.ObjectID(thread)
+ });
+ } else {
+ _thread = deepcopy(thread);
+ }
+
+ // Rename _id to id
+ _thread.id = _thread._id;
+ delete _thread._id;
+
+ // Remove needless properties
+ delete _thread.user_id;
+
+ resolve(_thread);
+});