Sharkey/packages/backend/src/server/api/endpoints/admin/announcements/delete.ts

36 lines
801 B
TypeScript
Raw Normal View History

import $ from 'cafy';
import define from '../../../define';
import { ID } from '@/misc/cafy-id';
import { Announcements } from '@/models/index';
import { ApiError } from '../../../error';
export const meta = {
tags: ['admin'],
2020-02-15 14:33:32 +02:00
requireCredential: true as const,
requireModerator: true,
params: {
id: {
2021-12-09 16:58:30 +02:00
validator: $.type(ID),
},
},
errors: {
noSuchAnnouncement: {
message: 'No such announcement.',
code: 'NO_SUCH_ANNOUNCEMENT',
2021-12-09 16:58:30 +02:00
id: 'ecad8040-a276-4e85-bda9-015a708d291e',
},
},
};
2022-01-02 19:12:50 +02:00
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
const announcement = await Announcements.findOne(ps.id);
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
await Announcements.delete(announcement.id);
});