diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0eadc728519de89e749b901c58594ba9e18ab4f2..03e38656f0efd9dc0a3060136a2041516c3d9c40 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -27,7 +27,9 @@ model History { user_id Int user User @relation(fields: [user_id], references: [id]) alamat_tujuan String + id_penerima Int nama_penerima String + biaya_pengiriman Int rating Int @default(0) history_detail HistoryDetail[] } @@ -38,6 +40,7 @@ model HistoryDetail { history History @relation(fields: [history_id], references: [id]) product_name String quantity Int + price Int } diff --git a/src/handler/history/history.router.ts b/src/handler/history/history.router.ts index a8a8dfaa5f68621ee8c2a769b0c5ec357c8917f3..3e974d4bc69eff790a19328b207a8a8f6fad30be 100644 --- a/src/handler/history/history.router.ts +++ b/src/handler/history/history.router.ts @@ -22,4 +22,14 @@ HistoryRouter.get('/detail/:id', async (request: Request, response: Response) => } catch (error: any) { return response.status(500).json(error.message); } +}) + +HistoryRouter.get('/history/:id', async (request: Request, response: Response) => { + const id: number = parseInt(request.params.id, 10); + try { + const history = await HistoryServices.getHistoryById(id); + return response.status(200).json(history); + } 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 5ffb5d6da356a957fa9a93fdabc403bc83dee2df..7cff54a5edcd4bf5bc62e9fa1623b5f52e33d50f 100644 --- a/src/handler/history/history.service.ts +++ b/src/handler/history/history.service.ts @@ -13,7 +13,9 @@ export async function getHistory (username : string) : Promise<History[]> { id: true, user_id: true, alamat_tujuan: true, + id_penerima: true, nama_penerima: true, + biaya_pengiriman: true, rating: true } }) @@ -28,7 +30,31 @@ export async function getHistoryDetail (historyId: number) : Promise<HistoryDeta id: true, history_id: true, product_name: true, - quantity: true + quantity: true, + price: true } }) +} + +export async function getHistoryById (historyId: number) : Promise<History> { + const history = await db.history.findFirst({ + where:{ + id: historyId + }, + select:{ + id: true, + user_id: true, + alamat_tujuan: true, + id_penerima: true, + nama_penerima: true, + biaya_pengiriman: true, + rating: true + } + }) + + if(history === null) { + throw "error"; + } + + return history; } \ No newline at end of file diff --git a/src/interfaces/History.ts b/src/interfaces/History.ts index 3d85e7f05bdf724121012422d19523db2d1c9b05..9b5ada7b6be11c9876745161a3c6f9751fe95e7e 100644 --- a/src/interfaces/History.ts +++ b/src/interfaces/History.ts @@ -1,8 +1,10 @@ export interface History { - id: number, - user_id : number, - alamat_tujuan: string, - nama_penerima: string, - rating: number, + id: number + user_id : number + alamat_tujuan : string + id_penerima : number + nama_penerima : string + biaya_pengiriman : number + rating : number } diff --git a/src/interfaces/HistoryDetail.ts b/src/interfaces/HistoryDetail.ts index 6c769d4c92781f65e6ecc54fe8d12d366f28cdf4..0c5d4fa36e8b9647ad78b1ae2df7358fb199025c 100644 --- a/src/interfaces/HistoryDetail.ts +++ b/src/interfaces/HistoryDetail.ts @@ -1,7 +1,8 @@ export interface HistoryDetail { - id: number, - history_id : number, - product_name: string, - quantity: number, -} \ No newline at end of file + id: number + history_id : number + product_name: string + quantity: number + price : number +} diff --git a/src/interfaces/User.ts b/src/interfaces/User.ts index d95d48832cd3ac9e52c8fb993c03c69f373882f6..bb4b95bdac7818d2235bc03bd42c22fdf9ef92af 100644 --- a/src/interfaces/User.ts +++ b/src/interfaces/User.ts @@ -1,9 +1,9 @@ export interface User { - id : number, - username : string, - name : string, - email : string, - password : string, - saldo : number, + id : number + username : string + name : string + email : string + password : string + saldo : number } \ No newline at end of file