mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-24 04:59:06 +01:00
40 lines
846 B
TypeScript
40 lines
846 B
TypeScript
import * as mongo from 'mongodb';
|
|
import db from '../db/mongodb';
|
|
|
|
const FollowedLog = db.get<IFollowedLog>('followedLogs');
|
|
export default FollowedLog;
|
|
|
|
export type IFollowedLog = {
|
|
_id: mongo.ObjectID;
|
|
createdAt: Date;
|
|
userId: mongo.ObjectID;
|
|
count: number;
|
|
};
|
|
|
|
/**
|
|
* 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
|
|
});
|
|
}
|