From b1e7c9f05f7790545375aeb369924624003c873a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Tue, 23 Jul 2024 12:43:44 +0900 Subject: [PATCH] =?UTF-8?q?isPaid=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routers/task/historyRouter.ts | 16 ++++++++++++---- src/services/historyService.ts | 13 ++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/routers/task/historyRouter.ts b/src/routers/task/historyRouter.ts index cee48d1..9ef38f1 100644 --- a/src/routers/task/historyRouter.ts +++ b/src/routers/task/historyRouter.ts @@ -1,6 +1,6 @@ import { internalServerErrorResponse, notFoundResponse, requiredFieldMissingResponse } from '@src/models/commons/responses'; import { HistoryListResponse, HistoryResponse } from '@src/models/History'; -import { getHistories } from '@src/services/historyService'; +import { getHistories, updateHistoryPaidStatus } from '@src/services/historyService'; import { Router } from 'express'; import Logger from '@src/logger' @@ -32,9 +32,17 @@ parentRouter.delete("/:historyId", (req, res) => { // TODO: 履歴削除 }); -parentRouter.patch("/:childId/:historyId", (req, res) => { - res.status(501).send("WIP"); - // TODO: 履歴手動追加 +parentRouter.post("/:historyId/paid", (req, res) => { + const isPaid = req.query.isPaid === "true"; + const historyId = req.params.historyId; + if (!historyId) { + const historyIdMissingResponse = requiredFieldMissingResponse(["historyId"]); + res.status(historyIdMissingResponse.statusCode).send(historyIdMissingResponse.body); + return; + } + updateHistoryPaidStatus(historyId, isPaid).then(() => { + res.status(200).send(); // TODO: 固定値化 + }); }); export { parentRouter, commonRouter }; diff --git a/src/services/historyService.ts b/src/services/historyService.ts index ee2bc9e..6b54c8b 100644 --- a/src/services/historyService.ts +++ b/src/services/historyService.ts @@ -23,4 +23,15 @@ async function getHistories(childId: string, containPaid: boolean): Promise { + await prisma.taskCompletion.update({ + where: { + id: historyId, + }, + data: { + is_paid: isPaid, + }, + }); +} + +export { getHistories, updateHistoryPaidStatus }