2020-01-30 04:37:25 +09:00
|
|
|
import $ from 'cafy';
|
2021-08-19 21:55:45 +09:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import define from '../../define';
|
|
|
|
import { ApiError } from '../../error';
|
|
|
|
import { Antennas } from '@/models/index';
|
|
|
|
import { publishInternalEvent } from '@/services/stream';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['antennas'],
|
|
|
|
|
2020-02-15 21:33:32 +09:00
|
|
|
requireCredential: true as const,
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
antennaId: {
|
|
|
|
validator: $.type(ID),
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: 'b34dcf9d-348f-44bb-99d0-6c9314cfe2df',
|
|
|
|
},
|
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const antenna = await Antennas.findOne({
|
|
|
|
id: ps.antennaId,
|
2021-12-09 23:58:30 +09:00
|
|
|
userId: user.id,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
|
|
|
|
|
|
|
await Antennas.delete(antenna.id);
|
2021-03-23 15:06:56 +09:00
|
|
|
|
|
|
|
publishInternalEvent('antennaDeleted', antenna);
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|