diff --git a/src/handler/history/history.router.ts b/src/handler/history/history.router.ts index c6edfbd3fe7e50779bfab1c5bf8604db7b91e07b..f0f9a04ad68007d4e41ef9045468a8d7c48d50f7 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 d10db0112d77c555095a79012c517e958797337d..c23e20cda8c177a3ba0cb9ff24309f068bae740d 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 5bbe0da57bd532c17f227795cbf4c8158fe2e769..6123739549b3152cb636e70dba87402fcbab47fa 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 e6fc76b5578fa5360fc584a41e4804274b68043c..69317281882ed5e62117ba94ad4879a967536796 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