전체 코드, 구조 검토 - P1 코드 수정 진행
This commit is contained in:
+51
-31
@@ -139,11 +139,16 @@ export async function approveExtensionRequest(
|
||||
Name: true,
|
||||
Email: true,
|
||||
AvailableActivateDateTime: true,
|
||||
ActivateStatus: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (request!.maestro.ActivateStatus !== ACTIVATE_STATUSES.ACTIVE) {
|
||||
throw new ApiError("활성화된 계정만 연장 승인이 가능합니다.", 409);
|
||||
}
|
||||
|
||||
const availableActivateDateTime = calculateExtendedAvailableDate(
|
||||
request!.maestro.AvailableActivateDateTime
|
||||
);
|
||||
@@ -185,38 +190,53 @@ export async function approveExtensionRequest(
|
||||
export async function createExtensionRequest(
|
||||
maestroID: number
|
||||
): Promise<{ maestroExtensionID: number; requestedDateTime: string; status: number }> {
|
||||
const maestro = await db.maestro.findUnique({
|
||||
where: { MaestroID: maestroID },
|
||||
select: { AccountType: true },
|
||||
return db.$transaction(async (tx) => {
|
||||
const maestro = await tx.maestro.findUnique({
|
||||
where: { MaestroID: maestroID },
|
||||
select: { AccountType: true, ActivateStatus: true, Name: true },
|
||||
});
|
||||
|
||||
if (!maestro) {
|
||||
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
|
||||
}
|
||||
|
||||
if (!(PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(maestro.AccountType)) {
|
||||
throw new ApiError("유료 요금제 계정만 연장 신청이 가능합니다.", 400);
|
||||
}
|
||||
|
||||
if (maestro.ActivateStatus !== ACTIVATE_STATUSES.ACTIVE) {
|
||||
throw new ApiError("활성화된 계정만 연장 신청이 가능합니다.", 400);
|
||||
}
|
||||
|
||||
const request = await tx.maestro_extension.create({
|
||||
data: {
|
||||
MaestroID: maestroID,
|
||||
AccountType: maestro.AccountType,
|
||||
RequestedDateTime: new Date(),
|
||||
Status: REQUEST_STATUSES.REQUESTED,
|
||||
},
|
||||
select: {
|
||||
MaestroExtensionID: true,
|
||||
RequestedDateTime: true,
|
||||
Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
await tx.maestro_log.create({
|
||||
data: {
|
||||
Type: "request_extension_maestro",
|
||||
MaestroID: maestroID,
|
||||
LogDateTime: new Date(),
|
||||
Remark: buildExtensionLogRemark(maestro.Name, maestro.AccountType),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
maestroExtensionID: request.MaestroExtensionID,
|
||||
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||
status: request.Status,
|
||||
};
|
||||
});
|
||||
|
||||
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: maestro.AccountType,
|
||||
RequestedDateTime: new Date(),
|
||||
Status: REQUEST_STATUSES.REQUESTED,
|
||||
},
|
||||
select: {
|
||||
MaestroExtensionID: true,
|
||||
RequestedDateTime: true,
|
||||
Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
maestroExtensionID: request.MaestroExtensionID,
|
||||
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||
status: request.Status,
|
||||
};
|
||||
}
|
||||
|
||||
export async function cancelExtensionRequest(
|
||||
|
||||
Reference in New Issue
Block a user