35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import type { ChannelFollowingsRepository, ChannelsRepository } from '@/models/index.js';
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ApiError } from '../../error.js';
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<'channels/unfollow'> {
|
|
name = 'channels/unfollow' as const;
|
|
constructor(
|
|
@Inject(DI.channelsRepository)
|
|
private channelsRepository: ChannelsRepository,
|
|
|
|
@Inject(DI.channelFollowingsRepository)
|
|
private channelFollowingsRepository: ChannelFollowingsRepository,
|
|
) {
|
|
super(async (ps, me) => {
|
|
const channel = await this.channelsRepository.findOneBy({
|
|
id: ps.channelId,
|
|
});
|
|
|
|
if (channel == null) {
|
|
throw new ApiError(this.meta.errors.noSuchChannel);
|
|
}
|
|
|
|
await this.channelFollowingsRepository.delete({
|
|
followerId: me.id,
|
|
followeeId: channel.id,
|
|
});
|
|
});
|
|
}
|
|
}
|