This commit is contained in:
tamaina
2023-05-22 01:43:00 +00:00
parent 8adf2701d2
commit 810d065d21
19 changed files with 144 additions and 543 deletions

View File

@@ -4,40 +4,18 @@ import type { AdsRepository } from '@/models/index.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
errors: {
noSuchAd: {
message: 'No such ad.',
code: 'NO_SUCH_AD',
id: 'ccac9863-3a03-416e-b899-8a64041118b1',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },
},
required: ['id'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'admin/ad/delete'> {
name = 'admin/ad/delete' as const;
constructor(
@Inject(DI.adsRepository)
private adsRepository: AdsRepository,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
const ad = await this.adsRepository.findOneBy({ id: ps.id });
if (ad == null) throw new ApiError(meta.errors.noSuchAd);
if (ad == null) throw new ApiError(this.meta.errors.noSuchAd);
await this.adsRepository.delete(ad.id);
});