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 FollowingLog = db.get<IFollowingLog>('followingLogs');
|
|
|
|
export default FollowingLog;
|
|
|
|
|
|
|
|
export type IFollowingLog = {
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
});
|
|
|
|
}
|