This commit is contained in:
こぴなたみぽ 2018-04-12 07:25:46 +09:00
parent 991635f919
commit 7b05e01819
3 changed files with 68 additions and 6 deletions

View file

@ -1,12 +1,39 @@
import { ObjectID } from 'mongodb';
import * as mongo from 'mongodb';
import db from '../db/mongodb';
const FollowedLog = db.get<IFollowedLog>('followedLogs');
export default FollowedLog;
export type IFollowedLog = {
_id: ObjectID;
_id: mongo.ObjectID;
createdAt: Date;
userId: ObjectID;
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
});
}

View file

@ -1,12 +1,39 @@
import { ObjectID } from 'mongodb';
import * as mongo from 'mongodb';
import db from '../db/mongodb';
const FollowingLog = db.get<IFollowingLog>('followingLogs');
export default FollowingLog;
export type IFollowingLog = {
_id: ObjectID;
_id: mongo.ObjectID;
createdAt: Date;
userId: ObjectID;
userId: mongo.ObjectID;
count: number;
};
/**
* 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
});
}

View file

@ -16,6 +16,8 @@ import MessagingHistory, { deleteMessagingHistory } from './messaging-history';
import DriveFile, { deleteDriveFile } from './drive-file';
import DriveFolder, { deleteDriveFolder } from './drive-folder';
import PollVote, { deletePollVote } from './poll-vote';
import FollowingLog, { deleteFollowingLog } from './following-log';
import FollowedLog, { deleteFollowedLog } from './followed-log';
const User = db.get<IUser>('users');
@ -228,8 +230,14 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
).map(x => deleteFollowing(x)));
// このユーザーのFollowingLogをすべて削除
await Promise.all((
await FollowingLog.find({ userId: u._id })
).map(x => deleteFollowingLog(x)));
// このユーザーのFollowedLogをすべて削除
await Promise.all((
await FollowedLog.find({ userId: u._id })
).map(x => deleteFollowedLog(x)));
// このユーザーを削除
}