This commit is contained in:
tamaina 2023-06-04 17:50:42 +00:00
parent 7f28b7334c
commit 80bd84932c
6 changed files with 199 additions and 187 deletions

View file

@ -5,50 +5,23 @@ import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js';
export const meta = {
tags: ['channels'],
requireCredential: false,
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Channel',
},
errors: {
noSuchChannel: {
message: 'No such channel.',
code: 'NO_SUCH_CHANNEL',
id: '6f6c314b-7486-4897-8966-c04a66a02923',
},
},
} 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<typeof meta, typeof paramDef> {
export default class extends Endpoint<'channels/show'> {
name = 'channels/show' as const;
constructor(
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
private channelEntityService: ChannelEntityService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
const channel = await this.channelsRepository.findOneBy({
id: ps.channelId,
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
throw new ApiError(this.meta.errors.noSuchChannel);
}
return await this.channelEntityService.pack(channel, me, true);