From 41089b9f68723933d3242a18acfd6c5b4f919b57 Mon Sep 17 00:00:00 2001 From: ellen Date: Wed, 21 Aug 2024 01:50:36 +0900 Subject: [PATCH] feat: impl usage order cms 008 api --- .../controller/common-space.controller.ts | 17 ++++++ .../common-space-usage-order-d.repository.ts | 28 ++++++++- .../service/common-space.service.ts | 24 ++++++++ .../api/common-space/endpoint/apiCms008.ts | 59 +++++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 packages/interface/src/api/common-space/endpoint/apiCms008.ts diff --git a/packages/api/src/feature/common-space/controller/common-space.controller.ts b/packages/api/src/feature/common-space/controller/common-space.controller.ts index 2b26f16df..447345946 100644 --- a/packages/api/src/feature/common-space/controller/common-space.controller.ts +++ b/packages/api/src/feature/common-space/controller/common-space.controller.ts @@ -14,6 +14,7 @@ import apiCms004 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms0 import apiCms005 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms005"; import apiCms006 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms006"; import apiCms007 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms007"; +import apiCms008 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms008"; import { ZodPipe } from "@sparcs-clubs/api/common/pipe/zod-pipe"; import { Public } from "@sparcs-clubs/api/common/util/decorators/method-decorator"; @@ -48,6 +49,10 @@ import type { ApiCms007RequestQuery, ApiCms007ResponseOk, } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms007"; +import type { + ApiCms008RequestParam, + ApiCms008ResponseOk, +} from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms008"; @Controller() export class CommonSpaceController { @@ -162,4 +167,16 @@ export class CommonSpaceController { ); return result; } + + @Get("student/common-spaces/common-space/usage-order/:orderId") + @UsePipes(new ZodPipe(apiCms008)) + async getStudentCommonSpacesUsageOrderDetail( + @Param() param: ApiCms008RequestParam, + ): Promise { + const result = + await this.commonspaceService.getStudentCommonSpacesUsageOrderDetail( + param.orderId, + ); + return result; + } } diff --git a/packages/api/src/feature/common-space/repository/common-space-usage-order-d.repository.ts b/packages/api/src/feature/common-space/repository/common-space-usage-order-d.repository.ts index 74d1c317b..90652f822 100644 --- a/packages/api/src/feature/common-space/repository/common-space-usage-order-d.repository.ts +++ b/packages/api/src/feature/common-space/repository/common-space-usage-order-d.repository.ts @@ -4,7 +4,11 @@ import { MySql2Database } from "drizzle-orm/mysql2"; import { takeUnique } from "@sparcs-clubs/api/common/util/util"; import { DrizzleAsyncProvider } from "@sparcs-clubs/api/drizzle/drizzle.provider"; -import { CommonSpaceUsageOrderD } from "@sparcs-clubs/api/drizzle/schema/common-space.schema"; +import { + CommonSpace, + CommonSpaceUsageOrderD, +} from "@sparcs-clubs/api/drizzle/schema/common-space.schema"; +import { Student } from "@sparcs-clubs/api/drizzle/schema/user.schema"; import { TermList } from "../dto/common-space.dto"; @@ -85,6 +89,28 @@ export class CommonSpaceUsageOrderDRepository { return result; } + async findCommonSpaceUsageOrderById(orderId: number) { + const result = await this.db + .select({ + orderId: CommonSpaceUsageOrderD.id, + statusEnum: CommonSpace.commonSpaceEnum, + spaceName: CommonSpace.spaceName, + chargeStudentName: Student.name, + startTerm: CommonSpaceUsageOrderD.startTerm, + endTerm: CommonSpaceUsageOrderD.endTerm, + createdAt: CommonSpaceUsageOrderD.createdAt, + }) + .from(CommonSpaceUsageOrderD) + .leftJoin( + CommonSpace, + eq(CommonSpaceUsageOrderD.commonSpaceId, CommonSpace.id), + ) + .leftJoin(Student, eq(CommonSpaceUsageOrderD.chargeStudentId, Student.id)) + .where(and(eq(CommonSpaceUsageOrderD.id, orderId))) + .then(takeUnique); + return result; + } + async deleteCommonSpaceUsageOrderD(orderId: number) { await this.db .update(CommonSpaceUsageOrderD) diff --git a/packages/api/src/feature/common-space/service/common-space.service.ts b/packages/api/src/feature/common-space/service/common-space.service.ts index 7582abfb5..c23d44c88 100644 --- a/packages/api/src/feature/common-space/service/common-space.service.ts +++ b/packages/api/src/feature/common-space/service/common-space.service.ts @@ -1,5 +1,7 @@ import { HttpException, HttpStatus, Injectable } from "@nestjs/common"; +import logger from "@sparcs-clubs/api/common/util/logger"; + import { getKSTDate, isEmptyObject } from "@sparcs-clubs/api/common/util/util"; import ClubStudentTRepository from "@sparcs-clubs/api/feature/club/repository/club.club-student-t.repository"; @@ -25,6 +27,7 @@ import type { ApiCms004ResponseOK } from "@sparcs-clubs/interface/api/common-spa import type { ApiCms005ResponseCreated } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms005"; import type { ApiCms006ResponseOk } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms006"; import type { ApiCms007ResponseOk } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms007"; +import type { ApiCms008ResponseOk } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms008"; @Injectable() export class CommonSpaceService { @@ -237,4 +240,25 @@ export class CommonSpaceService { ); return result; } + + async getStudentCommonSpacesUsageOrderDetail( + orderId: number, + ): Promise { + const order = + await this.commonSpaceUsageOrderDRepository.findCommonSpaceUsageOrderById( + orderId, + ); + // const { id } = order; + logger.debug(order); + const result = { + orderId, + statusEnum: order.statusEnum, + spaceName: order.spaceName, + chargeStudentName: order.chargeStudentName, + startTerm: order.startTerm, + endTerm: order.endTerm, + createdAt: order.createdAt, + }; + return result; + } } diff --git a/packages/interface/src/api/common-space/endpoint/apiCms008.ts b/packages/interface/src/api/common-space/endpoint/apiCms008.ts new file mode 100644 index 000000000..c5d7b1f58 --- /dev/null +++ b/packages/interface/src/api/common-space/endpoint/apiCms008.ts @@ -0,0 +1,59 @@ +import { HttpStatusCode } from "axios"; +import { z } from "zod"; + +import { CommonSpaceUsageOrderStatusEnum } from "@sparcs-clubs/interface/common/enum/commonSpace.enum"; + +/** + * @version v0.1 + * @description 개별 공용공간 사용신청 내역을 가져옵니다. + */ + +const url = (orderId: number) => + `/student/common-spaces/common-space/usage-order/${orderId}`; +const method = "GET"; + +const requestParam = z.object({ + orderId: z.coerce.number().int().min(1), // orderId는 양의 정수여야 합니다. +}); + +const requestQuery = z.object({}); + +const requestBody = z.object({}); + +const responseBodyMap = { + [HttpStatusCode.Ok]: z.object({ + orderId: z.number().int().min(1), + statusEnum: z.nativeEnum(CommonSpaceUsageOrderStatusEnum), + spaceName: z.string(), + chargeStudentName: z.string().max(255), + startTerm: z.coerce.date(), // Assuming startTerm is a datetime + endTerm: z.coerce.date(), // Assuming endTerm is a datetime + createdAt: z.coerce.date(), // Assuming createdAt is a datetime + }), +}; + +const responseErrorMap = {}; + +const apiCms008 = { + url, + method, + requestParam, + requestQuery, + requestBody, + responseBodyMap, + responseErrorMap, +}; + +type ApiCms008RequestParam = z.infer; +type ApiCms008RequestQuery = z.infer; +type ApiCms008RequestBody = z.infer; +type ApiCms008ResponseOk = z.infer<(typeof apiCms008.responseBodyMap)[200]>; + +export default apiCms008; + +export type { + ApiCms008RequestParam, + ApiCms008RequestQuery, + ApiCms008RequestBody, + ApiCms008ResponseOk, +};