This commit is contained in:
syuilo
2018-04-11 18:24:42 +09:00
parent 534ef9e999
commit 4166fd87c2
2 changed files with 67 additions and 1 deletions

View File

@@ -69,6 +69,38 @@ export type INote = {
};
};
// TODO
export async function physicalDelete(note: string | mongo.ObjectID | INote) {
let n: INote;
// Populate
if (mongo.ObjectID.prototype.isPrototypeOf(note)) {
n = await Note.findOne({
_id: note
});
} else if (typeof note === 'string') {
n = await Note.findOne({
_id: new mongo.ObjectID(note)
});
} else {
n = note as INote;
}
if (n == null) return;
// この投稿の返信をすべて削除
const replies = await Note.find({
replyId: n._id
});
await Promise.all(replies.map(r => physicalDelete(r)));
// この投稿のWatchをすべて削除
// この投稿のReactionをすべて削除
// この投稿に対するFavoriteをすべて削除
}
/**
* Pack a note for API response
*