2018-04-12 07:25:46 +09:00
|
|
|
import * as mongo from 'mongodb';
|
2018-04-02 21:57:36 +09:00
|
|
|
import db from '../db/mongodb';
|
|
|
|
|
|
|
|
const FollowingLog = db.get<IFollowingLog>('followingLogs');
|
|
|
|
export default FollowingLog;
|
|
|
|
|
|
|
|
export type IFollowingLog = {
|
2018-04-12 07:25:46 +09:00
|
|
|
_id: mongo.ObjectID;
|
2018-04-02 23:19:07 +09:00
|
|
|
createdAt: Date;
|
2018-04-12 07:25:46 +09:00
|
|
|
userId: mongo.ObjectID;
|
2018-04-02 21:57:36 +09:00
|
|
|
count: number;
|
|
|
|
};
|
2018-04-12 07:25:46 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FollowingLogを物理削除します
|
|
|
|
*/
|
|
|
|
export async function deleteFollowingLog(followingLog: string | mongo.ObjectID | IFollowingLog) {
|
|
|
|
let f: IFollowingLog;
|
|
|
|
|
|
|
|
// Populate
|
|
|
|
if (mongo.ObjectID.prototype.isPrototypeOf(followingLog)) {
|
|
|
|
f = await FollowingLog.findOne({
|
|
|
|
_id: followingLog
|
|
|
|
});
|
|
|
|
} else if (typeof followingLog === 'string') {
|
|
|
|
f = await FollowingLog.findOne({
|
|
|
|
_id: new mongo.ObjectID(followingLog)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
f = followingLog as IFollowingLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f == null) return;
|
|
|
|
|
|
|
|
// このFollowingLogを削除
|
|
|
|
await FollowingLog.remove({
|
|
|
|
_id: f._id
|
|
|
|
});
|
|
|
|
}
|