mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 21:43:09 +02:00
a07d753da8
* Update api document in admin/announcements * Update api document in announcements * Update api document in i/read-announcements * Update api document in username/available * Update api document & Fix typo in API 403 error * Update api document * Update api document * Update api document * Fix API permission definition * Update api document * Update api document * Update api document * Update api document * Update api document * Update api document * Update api document * Update api document * Fix bug in users (api) * Apply reviews #6757 * Apply reviews #6757 Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
import $ from 'cafy';
|
|
import { ID } from '../../../../../misc/cafy-id';
|
|
import define from '../../../define';
|
|
import { ApiError } from '../../../error';
|
|
import { getNote } from '../../../common/getters';
|
|
import { PromoNotes } from '../../../../../models';
|
|
|
|
export const meta = {
|
|
desc: {
|
|
'ja-JP': 'プロモーションを作成します。',
|
|
'en-US': 'Create a promotion.'
|
|
},
|
|
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true as const,
|
|
requireModerator: true,
|
|
|
|
params: {
|
|
noteId: {
|
|
validator: $.type(ID),
|
|
},
|
|
|
|
expiresAt: {
|
|
validator: $.num.int()
|
|
},
|
|
},
|
|
|
|
errors: {
|
|
noSuchNote: {
|
|
message: 'No such note.',
|
|
code: 'NO_SUCH_NOTE',
|
|
id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc'
|
|
},
|
|
|
|
alreadyPromoted: {
|
|
message: 'The note has already promoted.',
|
|
code: 'ALREADY_PROMOTED',
|
|
id: 'ae427aa2-7a41-484f-a18c-2c1104051604'
|
|
},
|
|
}
|
|
};
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
const note = await getNote(ps.noteId).catch(e => {
|
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
|
throw e;
|
|
});
|
|
|
|
const exist = await PromoNotes.findOne(note.id);
|
|
|
|
if (exist != null) {
|
|
throw new ApiError(meta.errors.alreadyPromoted);
|
|
}
|
|
|
|
await PromoNotes.save({
|
|
noteId: note.id,
|
|
createdAt: new Date(),
|
|
expiresAt: new Date(ps.expiresAt),
|
|
userId: note.userId,
|
|
});
|
|
});
|