코드 검토 및 문서 반영
This commit is contained in:
+38
-32
@@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
import { db } from "@/lib/db";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { ApiError } from "@/lib/errors";
|
||||
import { ACTIVATE_STATUSES, REQUEST_STATUSES } from "@/lib/constants";
|
||||
import { ACTIVATE_STATUSES, PAID_ACCOUNT_TYPE_VALUES, REQUEST_STATUSES } from "@/lib/constants";
|
||||
import type { Prisma } from "@/lib/generated/prisma/client";
|
||||
import {
|
||||
calculateUpgradePrice,
|
||||
@@ -171,38 +171,44 @@ export async function createUpgradeRequest(
|
||||
maestroID: number,
|
||||
requestedAccountType: number
|
||||
): Promise<{ maestroUpgradeID: number; registeredAccountType: number; requestedDateTime: string; status: number }> {
|
||||
const maestro = await db.maestro.findUnique({
|
||||
where: { MaestroID: maestroID },
|
||||
select: { ActivateStatus: true, AccountType: true },
|
||||
return db.$transaction(async (tx) => {
|
||||
const maestro = await tx.maestro.findUnique({
|
||||
where: { MaestroID: maestroID },
|
||||
select: { ActivateStatus: true, AccountType: true },
|
||||
});
|
||||
|
||||
if (!maestro) {
|
||||
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
|
||||
}
|
||||
|
||||
if (requestedAccountType <= maestro.AccountType) {
|
||||
throw new ApiError("현재 요금제보다 높은 요금제로만 업그레이드 신청이 가능합니다.", 400);
|
||||
}
|
||||
|
||||
const request = await tx.maestro_upgrade.create({
|
||||
data: {
|
||||
MaestroID: maestroID,
|
||||
RegisteredActivateStatus: maestro.ActivateStatus,
|
||||
RegisteredAccountType: maestro.AccountType,
|
||||
RequestedAccountType: requestedAccountType,
|
||||
RequestedDateTime: new Date(),
|
||||
Status: REQUEST_STATUSES.REQUESTED,
|
||||
},
|
||||
select: {
|
||||
MaestroUpgradeID: true,
|
||||
RegisteredAccountType: true,
|
||||
RequestedDateTime: true,
|
||||
Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
maestroUpgradeID: request.MaestroUpgradeID,
|
||||
registeredAccountType: request.RegisteredAccountType,
|
||||
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||
status: request.Status,
|
||||
};
|
||||
});
|
||||
|
||||
if (!maestro) {
|
||||
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
|
||||
}
|
||||
|
||||
const request = await db.maestro_upgrade.create({
|
||||
data: {
|
||||
MaestroID: maestroID,
|
||||
RegisteredActivateStatus: maestro.ActivateStatus,
|
||||
RegisteredAccountType: maestro.AccountType,
|
||||
RequestedAccountType: requestedAccountType,
|
||||
RequestedDateTime: new Date(),
|
||||
Status: REQUEST_STATUSES.REQUESTED,
|
||||
},
|
||||
select: {
|
||||
MaestroUpgradeID: true,
|
||||
RegisteredAccountType: true,
|
||||
RequestedDateTime: true,
|
||||
Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
maestroUpgradeID: request.MaestroUpgradeID,
|
||||
registeredAccountType: request.RegisteredAccountType,
|
||||
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||
status: request.Status,
|
||||
};
|
||||
}
|
||||
|
||||
export async function rejectUpgradeRequest(
|
||||
|
||||
Reference in New Issue
Block a user