summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/i/unpin.ts
blob: c1b753bfaf3c394d75f6b4fb5f56addf98f465c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import { removePinned } from '@/services/i/pin';
import define from '../../define';
import { ApiError } from '../../error';
import { Users } from '@/models/index';

export const meta = {
	tags: ['account', 'notes'],

	requireCredential: true as const,

	kind: 'write:account',

	params: {
		noteId: {
			validator: $.type(ID),
		},
	},

	errors: {
		noSuchNote: {
			message: 'No such note.',
			code: 'NO_SUCH_NOTE',
			id: '454170ce-9d63-4a43-9da1-ea10afe81e21',
		},
	},

	res: {
		type: 'object' as const,
		optional: false as const, nullable: false as const,
		ref: 'User',
	},
};

export default define(meta, async (ps, user) => {
	await removePinned(user, ps.noteId).catch(e => {
		if (e.id === 'b302d4cf-c050-400a-bbb3-be208681f40c') throw new ApiError(meta.errors.noSuchNote);
		throw e;
	});

	return await Users.pack(user.id, user, {
		detail: true,
	});
});