From 26bb2d42f91decaee4674f8c221a6eb5d1c70ad5 Mon Sep 17 00:00:00 2001 From: mattyatea Date: Fri, 17 May 2024 01:17:16 +0900 Subject: [PATCH] update --- .../backend/src/server/api/EndpointsModule.ts | 5 +- packages/backend/src/server/api/endpoints.ts | 6 ++- .../admin/accounts/present-points.ts | 52 +++++++++++++++++++ .../backend/src/server/api/endpoints/i.ts | 2 +- packages/frontend/src/pages/admin-user.vue | 12 +++++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 packages/backend/src/server/api/endpoints/admin/accounts/present-points.ts diff --git a/packages/backend/src/server/api/EndpointsModule.ts b/packages/backend/src/server/api/EndpointsModule.ts index f7d7c5ed9e..c9834c2821 100644 --- a/packages/backend/src/server/api/EndpointsModule.ts +++ b/packages/backend/src/server/api/EndpointsModule.ts @@ -388,13 +388,14 @@ import * as ep___reversi_surrender from './endpoints/reversi/surrender.js'; import * as ep___reversi_verify from './endpoints/reversi/verify.js'; import { GetterService } from './GetterService.js'; import { ApiLoggerService } from './ApiLoggerService.js'; +import * as ep___admin_accounts_present_points from './endpoints/admin/accounts/present-points.js'; import type { Provider } from '@nestjs/common'; - 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 }; const $admin_accounts_delete: Provider = { provide: 'ep:admin/accounts/delete', useClass: ep___admin_accounts_delete.default }; const $admin_accounts_findByEmail: Provider = { provide: 'ep:admin/accounts/find-by-email', useClass: ep___admin_accounts_findByEmail.default }; +const $admin_accounts_present_points: Provider = { provide: 'ep:admin/accounts/present-points', useClass: ep___admin_accounts_present_points.default }; const $admin_ad_create: Provider = { provide: 'ep:admin/ad/create', useClass: ep___admin_ad_create.default }; const $admin_ad_delete: Provider = { provide: 'ep:admin/ad/delete', useClass: ep___admin_ad_delete.default }; const $admin_ad_list: Provider = { provide: 'ep:admin/ad/list', useClass: ep___admin_ad_list.default }; @@ -783,6 +784,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__ $admin_accounts_create, $admin_accounts_delete, $admin_accounts_findByEmail, + $admin_accounts_present_points, $admin_ad_create, $admin_ad_delete, $admin_ad_list, @@ -1165,6 +1167,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__ $admin_accounts_create, $admin_accounts_delete, $admin_accounts_findByEmail, + $admin_accounts_present_points, $admin_ad_create, $admin_ad_delete, $admin_ad_list, diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index d65c6271d3..4c835f25e2 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -4,7 +4,7 @@ */ import { permissions } from 'misskey-js'; -import type { KeyOf,Schema } from '@/misc/json-schema.js'; +import type { KeyOf, Schema } from '@/misc/json-schema.js'; import { RolePolicies } from '@/core/RoleService.js'; import * as ep___admin_emoji_setlocalOnlyBulk from './endpoints/admin/emoji/set-localonly-bulk.js'; import * as ep___admin_emoji_setisSensitiveBulk from './endpoints/admin/emoji/set-issensitive-bulk.js'; @@ -13,6 +13,8 @@ import * as ep___admin_abuseUserReports from './endpoints/admin/abuse-user-repor import * as ep___admin_accounts_create from './endpoints/admin/accounts/create.js'; import * as ep___admin_accounts_delete from './endpoints/admin/accounts/delete.js'; import * as ep___admin_accounts_findByEmail from './endpoints/admin/accounts/find-by-email.js'; +import * as ep___admin_accounts_present_points from './endpoints/admin/accounts/present-points.js'; + import * as ep___admin_ad_create from './endpoints/admin/ad/create.js'; import * as ep___admin_ad_delete from './endpoints/admin/ad/delete.js'; import * as ep___admin_ad_list from './endpoints/admin/ad/list.js'; @@ -386,13 +388,13 @@ import * as ep___reversi_invitations from './endpoints/reversi/invitations.js'; import * as ep___reversi_showGame from './endpoints/reversi/show-game.js'; import * as ep___reversi_surrender from './endpoints/reversi/surrender.js'; import * as ep___reversi_verify from './endpoints/reversi/verify.js'; - const eps = [ ['admin/meta', ep___admin_meta], ['admin/abuse-user-reports', ep___admin_abuseUserReports], ['admin/accounts/create', ep___admin_accounts_create], ['admin/accounts/delete', ep___admin_accounts_delete], ['admin/accounts/find-by-email', ep___admin_accounts_findByEmail], + ['admin/accounts/present-points', ep___admin_accounts_present_points], ['admin/ad/create', ep___admin_ad_create], ['admin/ad/delete', ep___admin_ad_delete], ['admin/ad/list', ep___admin_ad_list], diff --git a/packages/backend/src/server/api/endpoints/admin/accounts/present-points.ts b/packages/backend/src/server/api/endpoints/admin/accounts/present-points.ts new file mode 100644 index 0000000000..d69c6b83c7 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/admin/accounts/present-points.ts @@ -0,0 +1,52 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Inject, Injectable } from '@nestjs/common'; +import { Endpoint } from '@/server/api/endpoint-base.js'; +import type { UsersRepository } from '@/models/_.js'; +import { DI } from '@/di-symbols.js'; +import { NotificationService } from '@/core/NotificationService.js'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireAdmin: true, + kind: 'write:admin:account', +} as const; + +export const paramDef = { + type: 'object', + properties: { + userId: { type: 'string', format: 'misskey:id' }, + points: { type: 'number' }, + }, + required: ['userId', 'points'], +} as const; + +@Injectable() +export default class extends Endpoint { // eslint-disable-line import/no-default-export + constructor( + @Inject(DI.usersRepository) + private usersRepository: UsersRepository, + private notificationService: NotificationService, + ) { + super(meta, paramDef, async (ps, me) => { + const user = await this.usersRepository.findOneBy({ id: ps.userId }); + + if (user == null) { + throw new Error('user not found'); + } + this.usersRepository.update( user.id, { + getPoints: user.getPoints + ps.points, + }); + this.notificationService.createNotification(user.id, 'loginbonus', { + loginbonus: ps.points, + }); + + return {}; + }); + } +} diff --git a/packages/backend/src/server/api/endpoints/i.ts b/packages/backend/src/server/api/endpoints/i.ts index 4284670499..6f36acb0b8 100644 --- a/packages/backend/src/server/api/endpoints/i.ts +++ b/packages/backend/src/server/api/endpoints/i.ts @@ -76,7 +76,7 @@ export default class extends Endpoint { // eslint- this.usersRepository.update( user.id, { getPoints: user.getPoints + todayGetPoints, }); - this.notificationService.createNotification(user.id, 'loginbonus', { + this.notificationService.createNotification(user. id, 'loginbonus', { loginbonus: todayGetPoints, }); userProfile.loggedInDates = [...userProfile.loggedInDates, today]; diff --git a/packages/frontend/src/pages/admin-user.vue b/packages/frontend/src/pages/admin-user.vue index f57aa51b5b..305d89395d 100644 --- a/packages/frontend/src/pages/admin-user.vue +++ b/packages/frontend/src/pages/admin-user.vue @@ -98,6 +98,9 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.resetPassword }}
+
+ ぷりずむを付与する +
@@ -312,6 +315,15 @@ async function resetPassword() { } } +async function presentsPoints() { + const { canceled, result } = await os.inputText({ + title: 'ポイント', + }); + if (canceled) return; + if (result === null) return; + await misskeyApi('admin/accounts/present-points', { userId: user.value.id, points: parseInt(result) }); +} + async function toggleSuspend(v) { const confirm = await os.confirm({ type: 'warning',