import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { ChannelFavoritesRepository, ChannelsRepository } from '@/models/index.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../error.js'; export const meta = { tags: ['channels'], requireCredential: true, prohibitMoved: true, kind: 'write:channels', errors: { noSuchChannel: { message: 'No such channel.', code: 'NO_SUCH_CHANNEL', id: '353c68dd-131a-476c-aa99-88a345e83668', }, }, } as const; export const paramDef = { type: 'object', properties: { channelId: { type: 'string', format: 'misskey:id' }, }, required: ['channelId'], } as const; // eslint-disable-next-line import/no-default-export @Injectable() export default class extends Endpoint { constructor( @Inject(DI.channelsRepository) private channelsRepository: ChannelsRepository, @Inject(DI.channelFavoritesRepository) private channelFavoritesRepository: ChannelFavoritesRepository, ) { super(meta, paramDef, async (ps, me) => { const channel = await this.channelsRepository.findOneBy({ id: ps.channelId, }); if (channel == null) { throw new ApiError(meta.errors.noSuchChannel); } await this.channelFavoritesRepository.delete({ userId: me.id, channelId: channel.id, }); }); } }