2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { GalleryPostsRepository } from '@/models/index.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { ApiError } from '../../../error.js';
|
2021-04-26 11:10:45 +09:00
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-07-03 08:57:13 +00:00
|
|
|
export default class extends Endpoint<'gallery/posts/delete'> {
|
|
|
|
|
name = 'gallery/posts/delete' as const;
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.galleryPostsRepository)
|
|
|
|
|
private galleryPostsRepository: GalleryPostsRepository,
|
|
|
|
|
) {
|
2023-07-03 08:57:13 +00:00
|
|
|
super(async (ps, me) => {
|
2022-09-18 03:27:08 +09:00
|
|
|
const post = await this.galleryPostsRepository.findOneBy({
|
|
|
|
|
id: ps.postId,
|
|
|
|
|
userId: me.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (post == null) {
|
2023-07-03 08:57:13 +00:00
|
|
|
throw new ApiError(this.meta.errors.noSuchPost);
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.galleryPostsRepository.delete(post.id);
|
|
|
|
|
});
|
2021-04-26 11:10:45 +09:00
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|