2021-05-04 14:15:57 +02: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 { Ads } from '@/models/index.js';
|
|
|
|
import { ApiError } from '../../../error.js';
|
2021-05-04 14:15:57 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
|
|
|
requireCredential: true as const,
|
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
id: {
|
|
|
|
validator: $.type(ID)
|
|
|
|
},
|
|
|
|
memo: {
|
|
|
|
validator: $.str
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
validator: $.str.min(1)
|
|
|
|
},
|
|
|
|
imageUrl: {
|
|
|
|
validator: $.str.min(1)
|
|
|
|
},
|
|
|
|
place: {
|
|
|
|
validator: $.str
|
|
|
|
},
|
|
|
|
priority: {
|
|
|
|
validator: $.str
|
|
|
|
},
|
2021-05-07 07:22:13 +02:00
|
|
|
ratio: {
|
|
|
|
validator: $.num.int().min(0)
|
|
|
|
},
|
2021-05-04 14:15:57 +02:00
|
|
|
expiresAt: {
|
|
|
|
validator: $.num.int()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAd: {
|
|
|
|
message: 'No such ad.',
|
|
|
|
code: 'NO_SUCH_AD',
|
|
|
|
id: 'b7aa1727-1354-47bc-a182-3a9c3973d300'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, me) => {
|
|
|
|
const ad = await Ads.findOne(ps.id);
|
|
|
|
|
|
|
|
if (ad == null) throw new ApiError(meta.errors.noSuchAd);
|
|
|
|
|
|
|
|
await Ads.update(ad.id, {
|
|
|
|
url: ps.url,
|
|
|
|
place: ps.place,
|
|
|
|
priority: ps.priority,
|
2021-05-07 07:22:13 +02:00
|
|
|
ratio: ps.ratio,
|
2021-05-04 14:15:57 +02:00
|
|
|
memo: ps.memo,
|
|
|
|
imageUrl: ps.imageUrl,
|
|
|
|
expiresAt: new Date(ps.expiresAt),
|
|
|
|
});
|
|
|
|
});
|