forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: ログインポイント送信機能 #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3b71c63
rebuild i18n
Suzlun 45a6de0
point/sendエンドポイントを追加
Suzlun 4774311
ポイント送信ポリシーを追加
Suzlun 719f0f0
ポイント受領通知を追加
Suzlun a4a2d24
point送信UIを追加
Suzlun 4cfe99b
fix/usernameとnameが逆になっていた問題を修正
Suzlun 4429881
ぽりしーが足りない場合はエンドポイントのほうでも送信不可に。
Suzlun 3cca8a9
Merge branch 'develop' into 81-feat_send_point
mattyatea be98c32
errorハンドリングでApiErrorを使うようにする
Suzlun db8cf3b
バリテーションを追記
Suzlun eb95a5b
Merge remote-tracking branch 'origin/81-feat_send_point' into 81-feat…
mattyatea 3fd9e4c
Merge remote-tracking branch 'origin/develop' into 81-feat_send_point
mattyatea e2fce85
コミット忘れ
mattyatea a5e26f3
LockFile
mattyatea 9f5c51a
Merge remote-tracking branch 'refs/remotes/origin/develop' into 81-fe…
mattyatea c682b8b
misskey-js回りを更新
mattyatea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v22.11.0 | ||
| v22.14.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/backend/src/server/api/endpoints/point/send.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * 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'; | ||
| import { RoleService } from '@/core/RoleService.js'; | ||
| import { ApiError } from '../../error.js'; | ||
|
|
||
| export const meta = { | ||
| tag: ['point'], | ||
| requireCredential: true, | ||
| kind: 'write:points', | ||
| secure: true, | ||
| errors: { | ||
| userIsNotFound: { | ||
| message: 'user is not found.', | ||
| code: 'USER_IS_NOT_FOUND', | ||
| id: '87472165-2e39-fcb9-352b-98c24a6d825e', | ||
| }, | ||
| notEnoughPoints: { | ||
| message: 'not enough points.', | ||
| code: 'NOT_ENOUGH_POINTS', | ||
| id: '10e9f46d-9f1f-7a4b-801b-5fe88e4bb1aa', | ||
| }, | ||
| cannotSendPoints: { | ||
| message: 'cannot send points.', | ||
| code: 'CANNOT_SEND_POINTS', | ||
| id: 'f1cf2616-db7b-3f97-5a14-06a0a0005f8f', | ||
| }, | ||
| recipientIsYou: { | ||
| message: 'recipient is you.', | ||
| code: 'RECIPIENT_IS_ME', | ||
| id: '24095319-69ee-8033-b0a2-9ad6928bbcb8', | ||
| }, | ||
| }, | ||
|
|
||
| } 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<typeof meta, typeof paramDef> { | ||
| constructor( | ||
| @Inject(DI.usersRepository) | ||
| private usersRepository: UsersRepository, | ||
| private notificationService: NotificationService, | ||
| private roleService: RoleService, | ||
| ) { | ||
| super(meta, paramDef, async (ps, me) => { | ||
| const sender = await this.usersRepository.findOneBy({ id: me.id }); | ||
| const user = await this.usersRepository.findOneBy({ id: ps.userId }); | ||
|
|
||
| if (sender == null || user == null) { | ||
| throw new ApiError(meta.errors.userIsNotFound); | ||
| } | ||
|
|
||
| if ((await this.roleService.getUserPolicies(sender.id)).canSendPoints === false) { | ||
mattyatea marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new ApiError(meta.errors.cannotSendPoints); | ||
| } | ||
| //送れるかどうかチェック | ||
| if (sender.getPoints < ps.points) { | ||
| throw new ApiError(meta.errors.notEnoughPoints); | ||
| } | ||
|
|
||
| // 受信者が自分ならエラー | ||
| if (sender.id === user.id) { | ||
| throw new ApiError(meta.errors.recipientIsYou); | ||
| } | ||
|
|
||
| // 送るポイントが0以下の場合はエラー | ||
| if (ps.points <= 0) { | ||
| throw new ApiError(meta.errors.cannotSendPoints); | ||
| } | ||
|
|
||
| //ポイントを送る | ||
| await this.usersRepository.update(sender.id, { | ||
| getPoints: sender.getPoints - ps.points, | ||
| }); | ||
| await this.usersRepository.update(user.id, { | ||
| getPoints: user.getPoints + ps.points, | ||
| }); | ||
|
|
||
| this.notificationService.createNotification(user.id, 'acceptPoints', { | ||
| getPoint: ps.points, | ||
| }, sender.id); | ||
|
|
||
| return {}; | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.