paricafe/packages/backend/src/server/api/endpoints/i/unpin.ts
Shun Sakai c2370a1be6
chore: 著作権とライセンスについての情報を各ファイルに追加する (#11348)
* chore: Add the SPDX information to each file

Add copyright and licensing information as defined in version 3.0 of
the REUSE Specification.

* tweak format

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-07-27 14:31:52 +09:00

60 lines
1.5 KiB
TypeScript

/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { NotePiningService } from '@/core/NotePiningService.js';
import { ApiError } from '../../error.js';
export const meta = {
tags: ['account', 'notes'],
requireCredential: true,
kind: 'write:account',
errors: {
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: '454170ce-9d63-4a43-9da1-ea10afe81e21',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'MeDetailed',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },
},
required: ['noteId'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
private userEntityService: UserEntityService,
private notePiningService: NotePiningService,
) {
super(meta, paramDef, async (ps, me) => {
await this.notePiningService.removePinned(me, ps.noteId).catch(err => {
if (err.id === 'b302d4cf-c050-400a-bbb3-be208681f40c') throw new ApiError(meta.errors.noSuchNote);
throw err;
});
return await this.userEntityService.pack<true, true>(me.id, me, {
detail: true,
});
});
}
}