전체 코드, 구조 검토 - P1 코드 수정 진행

This commit is contained in:
2026-07-04 15:32:19 +09:00
parent 3c5848cdc5
commit 41a246ad7b
6 changed files with 110 additions and 41 deletions
+38 -3
View File
@@ -143,10 +143,22 @@ export async function approveUpgradeRequest(
RequestedAccountType: true,
RegisteredActivateStatus: true,
RegisteredAccountType: true,
maestro: { select: { Name: true, Email: true } },
maestro: { select: { Name: true, Email: true, AccountType: true, ActivateStatus: true } },
},
});
// Re-verify upgrade direction at approval time (maestro AccountType may have changed since request)
const isApprovalTrial = request!.maestro.ActivateStatus === ACTIVATE_STATUSES.TRIAL;
const isStillValidUpgrade = isApprovalTrial
? request!.RequestedAccountType >= request!.maestro.AccountType
: request!.RequestedAccountType > request!.maestro.AccountType;
if (!isStillValidUpgrade) {
throw new ApiError(
"마에스트로의 현재 요금제 기준으로 유효하지 않은 업그레이드입니다. 신청 내용을 확인해 주세요.",
409
);
}
const availableActivateDateTime = calculateUpgradeAvailableDate();
await tx.maestro.update({
@@ -202,8 +214,18 @@ export async function createUpgradeRequest(
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
}
if (requestedAccountType <= maestro.AccountType) {
throw new ApiError("현재 요금제보다 높은 요금제로만 업그레이드 신청이 가능합니다.", 400);
const isTrial = maestro.ActivateStatus === ACTIVATE_STATUSES.TRIAL;
const isValidUpgrade = isTrial
? requestedAccountType >= maestro.AccountType
: requestedAccountType > maestro.AccountType;
if (!isValidUpgrade) {
throw new ApiError(
isTrial
? "체험 계정은 동일 요금제 이상으로만 업그레이드 신청이 가능합니다."
: "현재 요금제보다 높은 요금제로만 업그레이드 신청이 가능합니다.",
400
);
}
const request = await tx.maestro_upgrade.create({
@@ -223,6 +245,19 @@ export async function createUpgradeRequest(
},
});
await tx.maestro_log.create({
data: {
Type: "request_upgrade_maestro",
MaestroID: maestroID,
LogDateTime: new Date(),
Remark: buildUpgradeLogRemark(
maestro.ActivateStatus,
maestro.AccountType,
requestedAccountType
),
},
});
return {
maestroUpgradeID: request.MaestroUpgradeID,
registeredAccountType: request.RegisteredAccountType,