|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: anatawa12 |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-only |
| 4 | + */ |
| 5 | + |
| 6 | +import { Inject, Injectable } from '@nestjs/common'; |
| 7 | +import type { NirilaDeleteUserLogRepository } from '@/models/_.js'; |
| 8 | +import { Endpoint } from '@/server/api/endpoint-base.js'; |
| 9 | +import { DI } from '@/di-symbols.js'; |
| 10 | +import { ApiError } from '@/server/api/error.js'; |
| 11 | +import { QueryService } from '@/core/QueryService.js'; |
| 12 | + |
| 13 | +export const meta = { |
| 14 | + tags: ['admin'], |
| 15 | + |
| 16 | + requireCredential: true, |
| 17 | + requireModerator: true, |
| 18 | + secure: true, |
| 19 | + kind: 'read:admin:nirila-delete-user-log-access', |
| 20 | + |
| 21 | + errors: { |
| 22 | + notFound: { |
| 23 | + message: 'DeleteLog satisfies the request not found', |
| 24 | + code: 'NOT_FOUND', |
| 25 | + id: 'd29927d1-5b8c-4200-aa05-5537722ee7ab', |
| 26 | + }, |
| 27 | + }, |
| 28 | + |
| 29 | + res: { type: 'any' }, // no type data |
| 30 | +} as const; |
| 31 | + |
| 32 | +export const paramDef = { |
| 33 | + type: 'object', |
| 34 | + properties: { |
| 35 | + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, |
| 36 | + sinceId: { type: 'string', format: 'misskey:id' }, |
| 37 | + untilId: { type: 'string', format: 'misskey:id' }, |
| 38 | + |
| 39 | + // access single by id |
| 40 | + email: { type: 'string' }, |
| 41 | + username: { type: 'string' }, |
| 42 | + userId: { type: 'string', format: 'misskey:id' }, |
| 43 | + }, |
| 44 | + required: [], |
| 45 | +} as const; |
| 46 | + |
| 47 | +@Injectable() |
| 48 | +export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export |
| 49 | + constructor( |
| 50 | + @Inject(DI.nirilaDeleteUserLogRepository) |
| 51 | + private nirilaDeleteUserLogRepository: NirilaDeleteUserLogRepository, |
| 52 | + |
| 53 | + private queryService: QueryService, |
| 54 | + ) { |
| 55 | + super(meta, paramDef, async (ps, me) => { |
| 56 | + // single query |
| 57 | + if (ps.email) { |
| 58 | + const found = await this.nirilaDeleteUserLogRepository.findOneBy({ email: ps.email }); |
| 59 | + if (!found) throw new ApiError(meta.errors.notFound); |
| 60 | + return found.info; |
| 61 | + } |
| 62 | + |
| 63 | + if (ps.username) { |
| 64 | + const found = await this.nirilaDeleteUserLogRepository.findOneBy({ username: ps.username }); |
| 65 | + if (!found) throw new ApiError(meta.errors.notFound); |
| 66 | + return found.info; |
| 67 | + } |
| 68 | + |
| 69 | + if (ps.userId) { |
| 70 | + const found = await this.nirilaDeleteUserLogRepository.findOneBy({ userId: ps.userId }); |
| 71 | + if (!found) throw new ApiError(meta.errors.notFound); |
| 72 | + return found.info; |
| 73 | + } |
| 74 | + |
| 75 | + // list query |
| 76 | + |
| 77 | + const logs = await this.queryService.makePaginationQuery(this.nirilaDeleteUserLogRepository.createQueryBuilder('deleteLog'), ps.sinceId, ps.untilId) |
| 78 | + .limit(ps.limit) |
| 79 | + .getMany(); |
| 80 | + |
| 81 | + return logs.map(x => Object.assign(x.info, { id: x.id })); |
| 82 | + }); |
| 83 | + } |
| 84 | +} |
0 commit comments