2022-09-17 13:27:08 -05:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 15:33:11 -05:00
|
|
|
import type { AdsRepository } from '@/models/index.js';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { IdService } from '@/core/IdService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2021-05-04 07:15:57 -05:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 07:27:10 -06:00
|
|
|
requireCredential: true,
|
2021-05-04 07:15:57 -05:00
|
|
|
requireModerator: true,
|
2022-02-18 23:05:32 -06:00
|
|
|
} as const;
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-02-19 22:15:40 -06:00
|
|
|
export const paramDef = {
|
2022-02-18 23:05:32 -06:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
url: { type: 'string', minLength: 1 },
|
|
|
|
memo: { type: 'string' },
|
|
|
|
place: { type: 'string' },
|
|
|
|
priority: { type: 'string' },
|
|
|
|
ratio: { type: 'integer' },
|
|
|
|
expiresAt: { type: 'integer' },
|
2023-02-14 23:31:59 -06:00
|
|
|
startsAt: { type: 'integer' },
|
2022-02-18 23:05:32 -06:00
|
|
|
imageUrl: { type: 'string', minLength: 1 },
|
2021-05-04 07:15:57 -05:00
|
|
|
},
|
2023-02-14 23:31:59 -06:00
|
|
|
required: ['url', 'memo', 'place', 'priority', 'ratio', 'expiresAt', 'startsAt', 'imageUrl'],
|
2022-01-18 07:27:10 -06:00
|
|
|
} as const;
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-01-02 11:12:50 -06:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 13:27:08 -05:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.adsRepository)
|
|
|
|
private adsRepository: AdsRepository,
|
|
|
|
|
|
|
|
private idService: IdService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
await this.adsRepository.insert({
|
|
|
|
id: this.idService.genId(),
|
|
|
|
createdAt: new Date(),
|
|
|
|
expiresAt: new Date(ps.expiresAt),
|
2023-02-14 23:31:59 -06:00
|
|
|
startsAt: new Date(ps.startsAt),
|
2022-09-17 13:27:08 -05:00
|
|
|
url: ps.url,
|
|
|
|
imageUrl: ps.imageUrl,
|
|
|
|
priority: ps.priority,
|
|
|
|
ratio: ps.ratio,
|
|
|
|
place: ps.place,
|
|
|
|
memo: ps.memo,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|