From b95fbc0002de2e9adeb635053ad7bece09d09d73 Mon Sep 17 00:00:00 2001 From: Ulung32 <13521122@mahasiswa.itb.ac.id> Date: Fri, 17 Nov 2023 10:47:55 +0700 Subject: [PATCH] add getHistoryByIdPenerima + give rating (for php) --- src/handler/history/history.router.ts | 14 ++++++++++++++ src/handler/history/history.service.ts | 15 +++++++++++++++ src/handler/user/user.router.ts | 11 +++++++++++ src/handler/user/user.service.ts | 19 +++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/src/handler/history/history.router.ts b/src/handler/history/history.router.ts index c6edfbd..f0f9a04 100644 --- a/src/handler/history/history.router.ts +++ b/src/handler/history/history.router.ts @@ -44,4 +44,18 @@ HistoryRouter.get('/penerima/:id', async (request: Request, response: Response) } catch (error: any) { return response.status(500).json(error.message); } +}) + +HistoryRouter.put('/rating/:id', async (request: Request, response: Response) => { + const id: number = parseInt(request.params.id, 10); + const rating = request.body.rating; + console.log(request.body); + console.log(id) + console.log(rating); + try { + const history = await HistoryServices.updateRating(id, rating); + return response.status(200).json("success"); + } catch (error: any) { + return response.status(500).json(error.message); + } }) \ No newline at end of file diff --git a/src/handler/history/history.service.ts b/src/handler/history/history.service.ts index d10db01..c23e20c 100644 --- a/src/handler/history/history.service.ts +++ b/src/handler/history/history.service.ts @@ -76,4 +76,19 @@ export async function getHistoryByIdPenerima(idPenerima:number) : Promise<Histor }) console.log(history) return history; +} + +export async function updateRating(idHistory:number, rating:number){ + try { + await db.history.update({ + where: { + id: idHistory, + }, + data: { + rating: rating, + }, + }); + } catch (error) { + throw error; // Optionally, rethrow the error for the calling code to handle + } } \ No newline at end of file diff --git a/src/handler/user/user.router.ts b/src/handler/user/user.router.ts index 5bbe0da..6123739 100644 --- a/src/handler/user/user.router.ts +++ b/src/handler/user/user.router.ts @@ -86,3 +86,14 @@ UserRouter.put('/user-detail/:username', async (request: Request, response: Resp return response.status(500).json(error.message); } }) + +UserRouter.get('/user-details/id/:id', async (request: Request, response: Response) => { + console.log("tes2") + try { + const id: number = parseInt(request.params.id, 10); + const responseString = await UserServices.getUserById(id); + return response.status(200).json(responseString); + } catch (error: any) { + return response.status(500).json(error.message); + } +}) \ No newline at end of file diff --git a/src/handler/user/user.service.ts b/src/handler/user/user.service.ts index e6fc76b..6931728 100644 --- a/src/handler/user/user.service.ts +++ b/src/handler/user/user.service.ts @@ -151,3 +151,22 @@ export async function editUserByUsername(username : string, newUserDetail : User console.log(responseString); return responseString; } + +export async function getUserById(userId: number) { + console.log("Test1") + const userDetail : UserDetail | null = await db.user.findFirst({ + where:{ + id : userId, + }, + select: { + username : true, + name : true, + email : true, + saldo : true + } + }) + + console.log("Test1") + + return userDetail; +} \ No newline at end of file -- GitLab