2020-01-29 20:37:25 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 11:33:41 +02:00
|
|
|
import define from '../../../define.js';
|
|
|
|
import { ID } from '@/misc/cafy-id.js';
|
|
|
|
import { Announcements } from '@/models/index.js';
|
|
|
|
import { ApiError } from '../../../error.js';
|
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: {
|
|
|
|
validator: $.type(ID)
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
validator: $.str.min(1)
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
validator: $.str.min(1)
|
|
|
|
},
|
|
|
|
imageUrl: {
|
|
|
|
validator: $.nullable.str.min(1)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAnnouncement: {
|
|
|
|
message: 'No such announcement.',
|
|
|
|
code: 'NO_SUCH_ANNOUNCEMENT',
|
|
|
|
id: 'd3aae5a7-6372-4cb4-b61c-f511ffc2d7cc'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
});
|