This commit is contained in:
syuilo 2018-04-13 00:07:16 +09:00
commit 0cf7c76d2c
7 changed files with 176 additions and 8 deletions

View File

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

@ -11,3 +11,30 @@ export type IFollowing = {
followeeId: mongo.ObjectID; followeeId: mongo.ObjectID;
followerId: mongo.ObjectID; followerId: mongo.ObjectID;
}; };
/**
* Followingを物理削除します
*/
export async function deleteFollowing(following: string | mongo.ObjectID | IFollowing) {
let f: IFollowing;
// Populate
if (mongo.ObjectID.prototype.isPrototypeOf(following)) {
f = await Following.findOne({
_id: following
});
} else if (typeof following === 'string') {
f = await Following.findOne({
_id: new mongo.ObjectID(following)
});
} else {
f = following as IFollowing;
}
if (f == null) return;
// このFollowingを削除
await Following.remove({
_id: f._id
});
}

View File

@ -5,12 +5,13 @@ import db from '../db/mongodb';
import { IUser, pack as packUser } from './user'; import { IUser, pack as packUser } from './user';
import { pack as packApp } from './app'; import { pack as packApp } from './app';
import { pack as packChannel } from './channel'; import { pack as packChannel } from './channel';
import Vote from './poll-vote'; import Vote, { deletePollVote } from './poll-vote';
import Reaction, { deleteNoteReaction } from './note-reaction'; import Reaction, { deleteNoteReaction } from './note-reaction';
import { pack as packFile } from './drive-file'; import { pack as packFile } from './drive-file';
import NoteWatching, { deleteNoteWatching } from './note-watching'; import NoteWatching, { deleteNoteWatching } from './note-watching';
import NoteReaction from './note-reaction'; import NoteReaction from './note-reaction';
import Favorite, { deleteFavorite } from './favorite'; import Favorite, { deleteFavorite } from './favorite';
import PollVote from './poll-vote';
const Note = db.get<INote>('notes'); const Note = db.get<INote>('notes');
@ -113,6 +114,11 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) {
await NoteReaction.find({ noteId: n._id }) await NoteReaction.find({ noteId: n._id })
).map(x => deleteNoteReaction(x))); ).map(x => deleteNoteReaction(x)));
// この投稿に対するPollVoteをすべて削除
await Promise.all((
await PollVote.find({ noteId: n._id })
).map(x => deletePollVote(x)));
// この投稿に対するFavoriteをすべて削除 // この投稿に対するFavoriteをすべて削除
await Promise.all(( await Promise.all((
await Favorite.find({ noteId: n._id }) await Favorite.find({ noteId: n._id })

View File

@ -11,3 +11,30 @@ export interface IPollVote {
noteId: mongo.ObjectID; noteId: mongo.ObjectID;
choice: number; choice: number;
} }
/**
* PollVoteを物理削除します
*/
export async function deletePollVote(pollVote: string | mongo.ObjectID | IPollVote) {
let p: IPollVote;
// Populate
if (mongo.ObjectID.prototype.isPrototypeOf(pollVote)) {
p = await PollVote.findOne({
_id: pollVote
});
} else if (typeof pollVote === 'string') {
p = await PollVote.findOne({
_id: new mongo.ObjectID(pollVote)
});
} else {
p = pollVote as IPollVote;
}
if (p == null) return;
// このPollVoteを削除
await PollVote.remove({
_id: p._id
});
}

View File

@ -11,3 +11,31 @@ export interface ISwSubscription {
auth: string; auth: string;
publickey: string; publickey: string;
} }
/**
* SwSubscriptionを物理削除します
*/
export async function deleteSwSubscription(swSubscription: string | mongo.ObjectID | ISwSubscription) {
let s: ISwSubscription;
// Populate
if (mongo.ObjectID.prototype.isPrototypeOf(swSubscription)) {
s = await SwSubscription.findOne({
_id: swSubscription
});
} else if (typeof swSubscription === 'string') {
s = await SwSubscription.findOne({
_id: new mongo.ObjectID(swSubscription)
});
} else {
s = swSubscription as ISwSubscription;
}
if (s == null) return;
// このSwSubscriptionを削除
await SwSubscription.remove({
_id: s._id
});
}

View File

@ -3,7 +3,7 @@ import deepcopy = require('deepcopy');
import rap from '@prezzemolo/rap'; import rap from '@prezzemolo/rap';
import db from '../db/mongodb'; import db from '../db/mongodb';
import Note, { INote, pack as packNote, deleteNote } from './note'; import Note, { INote, pack as packNote, deleteNote } from './note';
import Following from './following'; import Following, { deleteFollowing } from './following';
import Mute, { deleteMute } from './mute'; import Mute, { deleteMute } from './mute';
import getFriends from '../server/api/common/get-friends'; import getFriends from '../server/api/common/get-friends';
import config from '../config'; import config from '../config';
@ -15,6 +15,10 @@ import MessagingMessage, { deleteMessagingMessage } from './messaging-message';
import MessagingHistory, { deleteMessagingHistory } from './messaging-history'; import MessagingHistory, { deleteMessagingHistory } from './messaging-history';
import DriveFile, { deleteDriveFile } from './drive-file'; import DriveFile, { deleteDriveFile } from './drive-file';
import DriveFolder, { deleteDriveFolder } from './drive-folder'; import DriveFolder, { deleteDriveFolder } from './drive-folder';
import PollVote, { deletePollVote } from './poll-vote';
import FollowingLog, { deleteFollowingLog } from './following-log';
import FollowedLog, { deleteFollowedLog } from './followed-log';
import SwSubscription, { deleteSwSubscription } from './sw-subscription';
const User = db.get<IUser>('users'); const User = db.get<IUser>('users');
@ -171,6 +175,11 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
await NoteWatching.find({ userId: u._id }) await NoteWatching.find({ userId: u._id })
).map(x => deleteNoteWatching(x))); ).map(x => deleteNoteWatching(x)));
// このユーザーのPollVoteをすべて削除
await Promise.all((
await PollVote.find({ userId: u._id })
).map(x => deletePollVote(x)));
// このユーザーのFavoriteをすべて削除 // このユーザーのFavoriteをすべて削除
await Promise.all(( await Promise.all((
await Favorite.find({ userId: u._id }) await Favorite.find({ userId: u._id })
@ -212,12 +221,29 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
).map(x => deleteMute(x))); ).map(x => deleteMute(x)));
// このユーザーのFollowingをすべて削除 // このユーザーのFollowingをすべて削除
await Promise.all((
await Following.find({ followerId: u._id })
).map(x => deleteFollowing(x)));
// このユーザーへのFollowingをすべて削除 // このユーザーへのFollowingをすべて削除
await Promise.all((
await Following.find({ followeeId: u._id })
).map(x => deleteFollowing(x)));
// このユーザーのFollowingLogをすべて削除 // このユーザーのFollowingLogをすべて削除
await Promise.all((
await FollowingLog.find({ userId: u._id })
).map(x => deleteFollowingLog(x)));
// このユーザーのFollowedLogをすべて削除 // このユーザーのFollowedLogをすべて削除
await Promise.all((
await FollowedLog.find({ userId: u._id })
).map(x => deleteFollowedLog(x)));
// このユーザーのSwSubscriptionをすべて削除
await Promise.all((
await SwSubscription.find({ userId: u._id })
).map(x => deleteSwSubscription(x)));
// このユーザーを削除 // このユーザーを削除
} }