mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-23 02:17:40 -07:00
[API] Implement notes/watching/
This commit is contained in:
parent
620a21f916
commit
0f65a6a077
3 changed files with 97 additions and 0 deletions
44
src/server/api/endpoints/notes/watching/create.ts
Normal file
44
src/server/api/endpoints/notes/watching/create.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import Note from '../../../../../models/note';
|
||||
import define from '../../../define';
|
||||
import watch from '../../../../../services/note/watch';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
||||
desc: {
|
||||
'ja-JP': '指定した投稿をウォッチします。',
|
||||
'en-US': 'Watch a note.'
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'account-write',
|
||||
|
||||
params: {
|
||||
noteId: {
|
||||
validator: $.type(ID),
|
||||
transform: transform,
|
||||
desc: {
|
||||
'ja-JP': '対象の投稿のID',
|
||||
'en-US': 'Target note ID.'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get note
|
||||
const note = await Note.findOne({
|
||||
_id: ps.noteId
|
||||
});
|
||||
|
||||
if (note === null) {
|
||||
return rej('note not found');
|
||||
}
|
||||
|
||||
await watch(user._id, note);
|
||||
|
||||
// Send response
|
||||
res();
|
||||
}));
|
44
src/server/api/endpoints/notes/watching/delete.ts
Normal file
44
src/server/api/endpoints/notes/watching/delete.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import Note from '../../../../../models/note';
|
||||
import define from '../../../define';
|
||||
import unwatch from '../../../../../services/note/unwatch';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
||||
desc: {
|
||||
'ja-JP': '指定した投稿のウォッチを解除します。',
|
||||
'en-US': 'Unwatch a note.'
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'account-write',
|
||||
|
||||
params: {
|
||||
noteId: {
|
||||
validator: $.type(ID),
|
||||
transform: transform,
|
||||
desc: {
|
||||
'ja-JP': '対象の投稿のID',
|
||||
'en-US': 'Target note ID.'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get note
|
||||
const note = await Note.findOne({
|
||||
_id: ps.noteId
|
||||
});
|
||||
|
||||
if (note === null) {
|
||||
return rej('note not found');
|
||||
}
|
||||
|
||||
await unwatch(user._id, note);
|
||||
|
||||
// Send response
|
||||
res();
|
||||
}));
|
9
src/services/note/unwatch.ts
Normal file
9
src/services/note/unwatch.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import * as mongodb from 'mongodb';
|
||||
import Watching from '../../models/note-watching';
|
||||
|
||||
export default async (me: mongodb.ObjectID, note: object) => {
|
||||
await Watching.remove({
|
||||
noteId: (note as any)._id,
|
||||
userId: me
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue