Skip to content
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

fix(subscription): サブスクリプションが有効な状態でアカウントが削除できてしまう問題を修正 #20

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading