2020-01-29 20:37:25 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import { ID } from '../../../../misc/cafy-id';
|
|
|
|
import define from '../../define';
|
|
|
|
import { ApiError } from '../../error';
|
|
|
|
import { Antennas } from '../../../../models';
|
2021-03-23 07:06:56 +01:00
|
|
|
import { publishInternalEvent } from '../../../../services/stream';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2021-03-06 14:34:11 +01:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'アンテナを削除します。',
|
|
|
|
'en-US': 'Delete a antenna.'
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
tags: ['antennas'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
antennaId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
|
|
|
id: 'b34dcf9d-348f-44bb-99d0-6c9314cfe2df'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const antenna = await Antennas.findOne({
|
|
|
|
id: ps.antennaId,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
|
|
|
|
|
|
|
await Antennas.delete(antenna.id);
|
2021-03-23 07:06:56 +01:00
|
|
|
|
|
|
|
publishInternalEvent('antennaDeleted', antenna);
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|