mirror of
https://github.com/MisskeyIO/misskey
synced 2024-12-28 05:28:41 +09:00
38 lines
802 B
TypeScript
38 lines
802 B
TypeScript
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
|
|
import User, { ILocalUser } from '../../../../models/user';
|
|
import Note from '../../../../models/note';
|
|
import { pack } from '../../../../models/user';
|
|
|
|
/**
|
|
* Pin note
|
|
*/
|
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
|
// Get 'noteId' parameter
|
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
|
if (noteIdErr) return rej('invalid noteId param');
|
|
|
|
// Fetch pinee
|
|
const note = await Note.findOne({
|
|
_id: noteId,
|
|
userId: user._id
|
|
});
|
|
|
|
if (note === null) {
|
|
return rej('note not found');
|
|
}
|
|
|
|
await User.update(user._id, {
|
|
$set: {
|
|
pinnedNoteId: note._id
|
|
}
|
|
});
|
|
|
|
// Serialize
|
|
const iObj = await pack(user, user, {
|
|
detail: true
|
|
});
|
|
|
|
// Send response
|
|
res(iObj);
|
|
});
|