This commit is contained in:
tamaina 2023-06-04 14:59:14 +00:00
parent 1f64b7c9ea
commit 93d111bfb6
2 changed files with 30 additions and 27 deletions

View file

@ -5,47 +5,24 @@ import { GlobalEventService } from '@/core/GlobalEventService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
export const meta = {
tags: ['antennas'],
requireCredential: true,
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: 'b34dcf9d-348f-44bb-99d0-6c9314cfe2df',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },
},
required: ['antennaId'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'antennas/delete'> {
name = 'antennas/delete' as const;
constructor( constructor(
@Inject(DI.antennasRepository) @Inject(DI.antennasRepository)
private antennasRepository: AntennasRepository, private antennasRepository: AntennasRepository,
private globalEventService: GlobalEventService, private globalEventService: GlobalEventService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const antenna = await this.antennasRepository.findOneBy({ const antenna = await this.antennasRepository.findOneBy({
id: ps.antennaId, id: ps.antennaId,
userId: me.id, userId: me.id,
}); });
if (antenna == null) { if (antenna == null) {
throw new ApiError(meta.errors.noSuchAntenna); throw new ApiError(this.meta.errors.noSuchAntenna);
} }
await this.antennasRepository.delete(antenna.id); await this.antennasRepository.delete(antenna.id);

View file

@ -2035,6 +2035,32 @@ export const endpoints = {
} }
}], }],
}, },
'antennas/delete': {
tags: ['antennas'],
requireCredential: true,
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: 'b34dcf9d-348f-44bb-99d0-6c9314cfe2df',
},
},
defines: [{
req: {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },
},
required: ['antennaId'],
},
res: undefined,
}],
}
//#endregion //#endregion
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };