Skip to content

Commit

Permalink
feat: add endpoint to get NirilaDeleteUserLogRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Feb 15, 2024
1 parent 9e58ab0 commit 3205654
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/server/api/EndpointsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Module } from '@nestjs/common';

import { CoreModule } from '@/core/CoreModule.js';
import * as ep___admin_nirilaDeleteUserLogAccess from './endpoints/admin/nirila-delete-user-log-access.js';
import * as ep___admin_meta from './endpoints/admin/meta.js';
import * as ep___admin_abuseUserReports from './endpoints/admin/abuse-user-reports.js';
import * as ep___admin_accounts_create from './endpoints/admin/accounts/create.js';
Expand Down Expand Up @@ -368,6 +369,7 @@ import { GetterService } from './GetterService.js';
import { ApiLoggerService } from './ApiLoggerService.js';
import type { Provider } from '@nestjs/common';

const $admin_nirilaDeleteUserLogAccess: Provider = { provide: 'ep:admin/nirila-delete-user-log-access', useClass: ep___admin_nirilaDeleteUserLogAccess.default };
const $admin_meta: Provider = { provide: 'ep:admin/meta', useClass: ep___admin_meta.default };
const $admin_abuseUserReports: Provider = { provide: 'ep:admin/abuse-user-reports', useClass: ep___admin_abuseUserReports.default };
const $admin_accounts_create: Provider = { provide: 'ep:admin/accounts/create', useClass: ep___admin_accounts_create.default };
Expand Down Expand Up @@ -734,6 +736,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
providers: [
GetterService,
ApiLoggerService,
$admin_nirilaDeleteUserLogAccess,
$admin_meta,
$admin_abuseUserReports,
$admin_accounts_create,
Expand Down Expand Up @@ -1094,6 +1097,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
$retention,
],
exports: [
$admin_nirilaDeleteUserLogAccess,
$admin_meta,
$admin_abuseUserReports,
$admin_accounts_create,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Schema } from '@/misc/json-schema.js';
import { permissions } from 'misskey-js';
import { RolePolicies } from '@/core/RoleService.js';

import * as ep___admin_nirilaDeleteUserLogAccess from './endpoints/admin/nirila-delete-user-log-access.js';
import * as ep___admin_meta from './endpoints/admin/meta.js';
import * as ep___admin_abuseUserReports from './endpoints/admin/abuse-user-reports.js';
import * as ep___admin_accounts_create from './endpoints/admin/accounts/create.js';
Expand Down Expand Up @@ -367,6 +368,7 @@ import * as ep___fetchExternalResources from './endpoints/fetch-external-resourc
import * as ep___retention from './endpoints/retention.js';

const eps = [
['admin/nirila-delete-user-log-access', ep___admin_nirilaDeleteUserLogAccess],
['admin/meta', ep___admin_meta],
['admin/abuse-user-reports', ep___admin_abuseUserReports],
['admin/accounts/create', ep___admin_accounts_create],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* SPDX-FileCopyrightText: anatawa12
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { Inject, Injectable } from '@nestjs/common';
import type { NirilaDeleteUserLogRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '@/server/api/error.js';
import { QueryService } from '@/core/QueryService.js';

export const meta = {
tags: ['admin'],

requireCredential: true,
requireModerator: true,
secure: true,
kind: 'read:admin:nirila-delete-user-log-access',

errors: {
notFound: {
message: 'DeleteLog satisfies the request not found',
code: 'NOT_FOUND',
id: 'd29927d1-5b8c-4200-aa05-5537722ee7ab',
},
},

res: { type: 'any' }, // no type data
} as const;

export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },

// access single by id
email: { type: 'string' },
username: { type: 'string' },
userId: { type: 'string', format: 'misskey:id' },
},
required: [],
} as const;

@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.nirilaDeleteUserLogRepository)
private nirilaDeleteUserLogRepository: NirilaDeleteUserLogRepository,

private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
// single query
if (ps.email) {
const found = await this.nirilaDeleteUserLogRepository.findOneBy({ email: ps.email });
if (!found) throw new ApiError(meta.errors.notFound);
return found.info;
}

if (ps.username) {
const found = await this.nirilaDeleteUserLogRepository.findOneBy({ username: ps.username });
if (!found) throw new ApiError(meta.errors.notFound);
return found.info;
}

if (ps.userId) {
const found = await this.nirilaDeleteUserLogRepository.findOneBy({ userId: ps.userId });
if (!found) throw new ApiError(meta.errors.notFound);
return found.info;
}

// list query

const logs = await this.queryService.makePaginationQuery(this.nirilaDeleteUserLogRepository.createQueryBuilder('deleteLog'), ps.sinceId, ps.untilId)
.limit(ps.limit)
.getMany();

return logs.map(x => Object.assign(x.info, { id: x.id }));
});
}
}
1 change: 1 addition & 0 deletions packages/misskey-js/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const followingVisibilities = ['public', 'followers', 'private'] as const
export const followersVisibilities = ['public', 'followers', 'private'] as const;

export const permissions = [
'read:admin:nirila-delete-user-log-access',
'read:account',
'write:account',
'read:blocks',
Expand Down

0 comments on commit 3205654

Please sign in to comment.