RENAME: bbs -> channel

This commit is contained in:
syuilo
2017-10-31 21:42:11 +09:00
parent 0e95cdb04c
commit dc9fddf839
8 changed files with 65 additions and 67 deletions

View File

@@ -1,44 +0,0 @@
/**
* 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);
});

View File

@@ -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);
});