Skip to content

Commit

Permalink
Merge pull request #20 from nafu-at/hotfix/subscription
Browse files Browse the repository at this point in the history
fix(subscription): サブスクリプションが有効な状態でアカウントが削除できてしまう問題を修正
  • Loading branch information
nafu-at authored Oct 21, 2024
2 parents 74e37b0 + a851fb1 commit 088d1b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/accounts/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export const meta = {
code: 'CANNOT_DELETE_MODERATOR',
id: 'd195c621-f21a-4c2f-a634-484c2a616311',
},

subscriptionIsActive: {
message: 'If Subscription is active, cannot move account.',
code: 'SUBSCRIPTION_IS_ACTIVE',
id: 'f5c8b3b4-9e4d-4b7f-9f4d-9f1f0a7a3d0a',
},
},
} as const;

Expand Down Expand Up @@ -57,6 +63,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (user == null) throw new ApiError(meta.errors.userNotFound);
if (await this.roleService.isModerator(user)) throw new ApiError(meta.errors.cannotDeleteModerator);

if (!(user.subscriptionStatus === 'unpaid' || user.subscriptionStatus === 'canceled' || user.subscriptionStatus === 'none')) {
throw new ApiError(meta.errors.subscriptionIsActive);
}

await this.deleteAccountService.deleteAccount(user, ps.soft, me);
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/server/api/endpoints/i/delete-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private deleteAccountService: DeleteAccountService,
) {
super(meta, paramDef, async (ps, me) => {
if (!(me.subscriptionStatus === 'unpaid' || me.subscriptionStatus === 'canceled' || me.subscriptionStatus === 'none')) {
throw new ApiError(meta.errors.subscriptionIsActive);
}

const profile = await this.userProfilesRepository.findOneByOrFail({ userId: me.id });

const userDetailed = await this.usersRepository.findOneByOrFail({ id: me.id });
Expand Down

0 comments on commit 088d1b4

Please sign in to comment.