2019-02-05 03:48:08 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 14:55:45 +02:00
|
|
|
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';
|
2018-09-24 09:26:12 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['account', 'notes'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2018-09-24 09:26:12 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
kind: 'write:account',
|
2018-09-24 09:26:12 +02:00
|
|
|
|
|
|
|
params: {
|
2018-11-01 19:32:24 +01:00
|
|
|
noteId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
}
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchNote: {
|
|
|
|
message: 'No such note.',
|
|
|
|
code: 'NO_SUCH_NOTE',
|
|
|
|
id: '454170ce-9d63-4a43-9da1-ea10afe81e21'
|
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
ref: 'User'
|
2018-09-24 09:26:12 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
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;
|
|
|
|
});
|
2018-09-24 09:26:12 +02:00
|
|
|
|
2021-03-24 03:05:37 +01:00
|
|
|
return await Users.pack(user.id, user, {
|
2018-09-24 09:26:12 +02:00
|
|
|
detail: true
|
|
|
|
});
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|