2018-04-07 19:30:37 +02:00
|
|
|
import Note from '../../../../models/note';
|
2018-04-06 23:59:20 +02:00
|
|
|
import { IRemoteUser } from '../../../../models/user';
|
2018-05-28 07:39:46 +02:00
|
|
|
import deleteNode from '../../../../services/note/delete';
|
2019-02-03 10:16:57 +01:00
|
|
|
import { apLogger } from '../../logger';
|
2018-04-06 12:35:23 +02:00
|
|
|
|
2019-02-03 10:16:57 +01:00
|
|
|
const logger = apLogger;
|
2018-04-06 23:44:29 +02:00
|
|
|
|
2018-04-06 23:59:20 +02:00
|
|
|
export default async function(actor: IRemoteUser, uri: string): Promise<void> {
|
2019-02-03 10:16:57 +01:00
|
|
|
logger.info(`Deleting the Note: ${uri}`);
|
2018-04-06 23:44:29 +02:00
|
|
|
|
2018-04-07 19:30:37 +02:00
|
|
|
const note = await Note.findOne({ uri });
|
2018-04-06 23:51:35 +02:00
|
|
|
|
2018-04-07 19:30:37 +02:00
|
|
|
if (note == null) {
|
|
|
|
throw new Error('note not found');
|
2018-04-06 23:51:35 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 19:30:37 +02:00
|
|
|
if (!note.userId.equals(actor._id)) {
|
2018-04-06 23:51:35 +02:00
|
|
|
throw new Error('投稿を削除しようとしているユーザーは投稿の作成者ではありません');
|
|
|
|
}
|
|
|
|
|
2018-05-28 07:39:46 +02:00
|
|
|
await deleteNode(actor, note);
|
2018-04-06 12:35:23 +02:00
|
|
|
}
|