2020-01-29 20:37:25 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 14:55:45 +02:00
|
|
|
import define from '../../../define';
|
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import { Announcements } from '@/models/index';
|
|
|
|
import { ApiError } from '../../../error';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2020-01-29 20:37:25 +01:00
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
id: {
|
2021-12-09 15:58:30 +01:00
|
|
|
validator: $.type(ID),
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
title: {
|
2021-12-09 15:58:30 +01:00
|
|
|
validator: $.str.min(1),
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
text: {
|
2021-12-09 15:58:30 +01:00
|
|
|
validator: $.str.min(1),
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
imageUrl: {
|
2021-12-09 15:58:30 +01:00
|
|
|
validator: $.nullable.str.min(1),
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAnnouncement: {
|
|
|
|
message: 'No such announcement.',
|
|
|
|
code: 'NO_SUCH_ANNOUNCEMENT',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'd3aae5a7-6372-4cb4-b61c-f511ffc2d7cc',
|
|
|
|
},
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
};
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2020-01-29 20:37:25 +01:00
|
|
|
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.update(announcement.id, {
|
|
|
|
updatedAt: new Date(),
|
|
|
|
title: ps.title,
|
|
|
|
text: ps.text,
|
|
|
|
imageUrl: ps.imageUrl,
|
|
|
|
});
|
|
|
|
});
|