From eff5e5b02fec26fe355b685de534fd13870c45e4 Mon Sep 17 00:00:00 2001 From: leGit-y <99312658+leGit-y@users.noreply.github.com> Date: Sun, 19 Nov 2023 21:42:45 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"[FEAT]=20=ED=85=9C=ED=94=8C=EB=A6=BF?= =?UTF-8?q?=EB=B3=84=20=EA=B3=A0=EB=AF=BC=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20API=EC=97=90=EB=8F=84=20pagination=EC=B6=94?= =?UTF-8?q?=EA=B0=80"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/worryController.ts | 8 ++++---- src/repository/worryRepository.ts | 28 +++++++++++++++++++++++++--- src/router/worryRouter.ts | 4 +--- src/service/worryService.ts | 6 +++--- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/controller/worryController.ts b/src/controller/worryController.ts index 6c507f7..fd24459 100644 --- a/src/controller/worryController.ts +++ b/src/controller/worryController.ts @@ -108,11 +108,11 @@ const getWorryList = async (req: Request, res: Response, next: NextFunction) => const getWorryListByTemplate = async (req: Request, res: Response, next: NextFunction) => { try { - const { templateId,page,limit } = req.query; - if(!templateId || !page || !limit) - throw new ClientException("필요한 query 값이 존재하지 않습니다."); + const { templateId } = req.query; + if(!templateId) + throw new ClientException("templateId 값이 존재하지 않습니다."); const { userId }= req.body; - const data = await worryService.getWorryListByTemplate(+templateId,userId,+page,+limit); + const data = await worryService.getWorryListByTemplate(+templateId,userId); return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_LIST_BY_TEMPLATE_SUCCESS,data)); diff --git a/src/repository/worryRepository.ts b/src/repository/worryRepository.ts index d2d1fd2..93de1f4 100644 --- a/src/repository/worryRepository.ts +++ b/src/repository/worryRepository.ts @@ -130,6 +130,29 @@ const updateDeadline = async(deadlineUpdateDAO: deadlineUpdateDAO) => { }) } +const findAllWorryListSolved = async(userId: number) => { + + return await prisma.worry.findMany({ + select:{ + id:true, + user_id:true, + template_id:true, + title:true, + created_at:true, + updated_at:true + }, + where: { + user_id: userId, + final_answer:{ + not: null + } + }, + orderBy:{ + updated_at: 'desc' + } + }) +} + const findWorryListSolved = async(userId: number, page: number, limit: number) => { return await prisma.worry.findMany({ @@ -176,7 +199,7 @@ const findWorryListUnsolved = async(userId: number, page: number, limit: number) }) } -const findWorryListByTemplate = async(templateId: number,userId: number, page: number, limit: number) => { +const findWorryListByTemplate = async(templateId: number,userId: number) => { return await prisma.worry.findMany({ select:{ @@ -193,8 +216,6 @@ const findWorryListByTemplate = async(templateId: number,userId: number, page: n not: null } }, - skip: (page - 1) * limit, - take: limit, orderBy:{ updated_at: 'desc' } @@ -209,6 +230,7 @@ export default { createFinalAnswer, updateDeadline, findWorryListSolved, + findAllWorryListSolved, findWorryListUnsolved, findWorryListByTemplate diff --git a/src/router/worryRouter.ts b/src/router/worryRouter.ts index ed18e31..518b329 100644 --- a/src/router/worryRouter.ts +++ b/src/router/worryRouter.ts @@ -37,9 +37,7 @@ router.patch("/", router.get("/", auth, [ - query('templateId').notEmpty().withMessage("query string 에 'templateId' 값이 존재하지 않습니다"), - query('page').notEmpty().withMessage("query string 에 'page' 값이 존재하지 않습니다"), - query('limit').notEmpty().withMessage("query string 에 'limit' 값이 존재하지 않습니다") + query('templateId').notEmpty().withMessage("query string 에 'templateId' 값이 존재하지 않습니다") ], validate, worryController.getWorryListByTemplate, diff --git a/src/service/worryService.ts b/src/service/worryService.ts index 230fc21..d73c6a5 100644 --- a/src/service/worryService.ts +++ b/src/service/worryService.ts @@ -244,12 +244,12 @@ const getWorryList =async (isSolved: number, page: number, limit: number, userId } -const getWorryListByTemplate =async (templateId: number, userId: number, page: number, limit: number) => { +const getWorryListByTemplate =async (templateId: number, userId: number) => { let worry; if(templateId == 0) - worry = await worryRepository.findWorryListSolved(userId,page,limit); + worry = await worryRepository.findAllWorryListSolved(userId); else - worry = await worryRepository.findWorryListByTemplate(templateId,userId,page,limit); + worry = await worryRepository.findWorryListByTemplate(templateId,userId); if (!worry) { throw new ClientException(rm.GET_WORRY_LIST_BY_TEMPLATE_FAIL);