코드 검토 및 문서 반영
This commit is contained in:
@@ -68,6 +68,14 @@ export const REQUEST_STATUS_LABELS = {
|
||||
[REQUEST_STATUSES.APPLIED]: "적용 완료",
|
||||
} as const;
|
||||
|
||||
export const PAID_ACCOUNT_TYPE_VALUES = [
|
||||
ACCOUNT_TYPES.BASIC_20,
|
||||
ACCOUNT_TYPES.STANDARD_50,
|
||||
ACCOUNT_TYPES.PRO_100,
|
||||
ACCOUNT_TYPES.SCHOOL_500,
|
||||
ACCOUNT_TYPES.SCHOOL_1000,
|
||||
] as const;
|
||||
|
||||
export type AccountType = (typeof ACCOUNT_TYPES)[keyof typeof ACCOUNT_TYPES];
|
||||
export type PaidAccountType =
|
||||
| typeof ACCOUNT_TYPES.BASIC_20
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
import { db } from "@/lib/db";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { ApiError } from "@/lib/errors";
|
||||
import { REQUEST_STATUSES } from "@/lib/constants";
|
||||
import { PAID_ACCOUNT_TYPE_VALUES, REQUEST_STATUSES } from "@/lib/constants";
|
||||
import type { Prisma } from "@/lib/generated/prisma/client";
|
||||
import {
|
||||
calculateExtendedAvailableDate,
|
||||
@@ -158,22 +158,25 @@ export async function approveExtensionRequest(
|
||||
}
|
||||
|
||||
export async function createExtensionRequest(
|
||||
maestroID: number,
|
||||
accountType: number
|
||||
maestroID: number
|
||||
): Promise<{ maestroExtensionID: number; requestedDateTime: string; status: number }> {
|
||||
const maestro = await db.maestro.findUnique({
|
||||
where: { MaestroID: maestroID },
|
||||
select: { MaestroID: true },
|
||||
select: { AccountType: true },
|
||||
});
|
||||
|
||||
if (!maestro) {
|
||||
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
|
||||
}
|
||||
|
||||
if (!(PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(maestro.AccountType)) {
|
||||
throw new ApiError("유료 요금제 계정만 연장 신청이 가능합니다.", 400);
|
||||
}
|
||||
|
||||
const request = await db.maestro_extension.create({
|
||||
data: {
|
||||
MaestroID: maestroID,
|
||||
AccountType: accountType,
|
||||
AccountType: maestro.AccountType,
|
||||
RequestedDateTime: new Date(),
|
||||
Status: REQUEST_STATUSES.REQUESTED,
|
||||
},
|
||||
|
||||
+2
-10
@@ -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, ACCOUNT_TYPES } from "@/lib/constants";
|
||||
import { ACTIVATE_STATUSES, PAID_ACCOUNT_TYPE_VALUES } from "@/lib/constants";
|
||||
import type { Prisma } from "@/lib/generated/prisma/client";
|
||||
|
||||
const pageSizeOptions = [10, 20, 50, 100] as const;
|
||||
@@ -104,14 +104,6 @@ export type MaestroDetail = {
|
||||
}>;
|
||||
};
|
||||
|
||||
const paidAccountTypeValues = [
|
||||
ACCOUNT_TYPES.BASIC_20,
|
||||
ACCOUNT_TYPES.STANDARD_50,
|
||||
ACCOUNT_TYPES.PRO_100,
|
||||
ACCOUNT_TYPES.SCHOOL_500,
|
||||
ACCOUNT_TYPES.SCHOOL_1000,
|
||||
] as const;
|
||||
|
||||
const activateStatusValues = [
|
||||
ACTIVATE_STATUSES.PENDING,
|
||||
ACTIVATE_STATUSES.TRIAL,
|
||||
@@ -130,7 +122,7 @@ export const updateMaestroSchema = z.object({
|
||||
accountType: z.coerce
|
||||
.number()
|
||||
.int()
|
||||
.refine((v) => (paidAccountTypeValues as readonly number[]).includes(v))
|
||||
.refine((v) => (PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(v))
|
||||
.optional(),
|
||||
availableActivateDateTime: z.string().min(1).optional(),
|
||||
allowEditEnterCode: z.coerce.number().int().min(0).max(1).optional(),
|
||||
|
||||
+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