2018-04-11 15:25:46 -07:00
|
|
|
import * as mongo from 'mongodb';
|
2018-04-02 05:57:36 -07:00
|
|
|
import db from '../db/mongodb';
|
|
|
|
|
|
|
|
const FollowedLog = db.get<IFollowedLog>('followedLogs');
|
|
|
|
export default FollowedLog;
|
|
|
|
|
|
|
|
export type IFollowedLog = {
|
2018-04-11 15:25:46 -07:00
|
|
|
_id: mongo.ObjectID;
|
2018-04-02 07:19:07 -07:00
|
|
|
createdAt: Date;
|
2018-04-11 15:25:46 -07:00
|
|
|
userId: mongo.ObjectID;
|
2018-04-02 05:57:36 -07:00
|
|
|
count: number;
|
|
|
|
};
|
2018-04-11 15:25:46 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FollowedLogを物理削除します
|
|
|
|
*/
|
|
|
|
export async function deleteFollowedLog(followedLog: string | mongo.ObjectID | IFollowedLog) {
|
|
|
|
let f: IFollowedLog;
|
|
|
|
|
|
|
|
// Populate
|
|
|
|
if (mongo.ObjectID.prototype.isPrototypeOf(followedLog)) {
|
|
|
|
f = await FollowedLog.findOne({
|
|
|
|
_id: followedLog
|
|
|
|
});
|
|
|
|
} else if (typeof followedLog === 'string') {
|
|
|
|
f = await FollowedLog.findOne({
|
|
|
|
_id: new mongo.ObjectID(followedLog)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
f = followedLog as IFollowedLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f == null) return;
|
|
|
|
|
|
|
|
// このFollowedLogを削除
|
|
|
|
await FollowedLog.remove({
|
|
|
|
_id: f._id
|
|
|
|
});
|
|
|
|
}
|