summaryrefslogtreecommitdiff
path: root/src/server/api/models/channel.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-29 20:32:18 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-29 20:32:18 +0900
commitcf33e483f7e6f40e8cbbbc0118a7df70bdaf651f (patch)
tree318279530d3392ee40d91968477fc0e78d5cf0f7 /src/server/api/models/channel.ts
parentUpdate .travis.yml (diff)
downloadsharkey-cf33e483f7e6f40e8cbbbc0118a7df70bdaf651f.tar.gz
sharkey-cf33e483f7e6f40e8cbbbc0118a7df70bdaf651f.tar.bz2
sharkey-cf33e483f7e6f40e8cbbbc0118a7df70bdaf651f.zip
整理した
Diffstat (limited to 'src/server/api/models/channel.ts')
-rw-r--r--src/server/api/models/channel.ts75
1 files changed, 0 insertions, 75 deletions
diff --git a/src/server/api/models/channel.ts b/src/server/api/models/channel.ts
deleted file mode 100644
index 9f94c5a8d1..0000000000
--- a/src/server/api/models/channel.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import * as mongo from 'mongodb';
-import deepcopy = require('deepcopy');
-import { IUser } from './user';
-import Watching from './channel-watching';
-import db from '../../../db/mongodb';
-
-const Channel = db.get<IChannel>('channels');
-export default Channel;
-
-export type IChannel = {
- _id: mongo.ObjectID;
- createdAt: Date;
- title: string;
- userId: mongo.ObjectID;
- index: number;
- watchingCount: number;
-};
-
-/**
- * Pack a channel for API response
- *
- * @param channel target
- * @param me? serializee
- * @return response
- */
-export const pack = (
- 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.userId;
-
- // Me
- const meId: mongo.ObjectID = me
- ? mongo.ObjectID.prototype.isPrototypeOf(me)
- ? me as mongo.ObjectID
- : typeof me === 'string'
- ? new mongo.ObjectID(me)
- : (me as IUser)._id
- : null;
-
- if (me) {
- //#region Watchしているかどうか
- const watch = await Watching.findOne({
- userId: meId,
- channelId: _channel.id,
- deletedAt: { $exists: false }
- });
-
- _channel.isWatching = watch !== null;
- //#endregion
- }
-
- resolve(_channel);
-});