diff --git a/src/handler/history/history.router.ts b/src/handler/history/history.router.ts index 4ec93972e61e5653d8a8bda1e9332e51eb4cfcc3..a8a8dfaa5f68621ee8c2a769b0c5ec357c8917f3 100644 --- a/src/handler/history/history.router.ts +++ b/src/handler/history/history.router.ts @@ -5,16 +5,16 @@ import * as HistoryServices from './history.service' export const HistoryRouter = express.Router() -HistoryRouter.get('/', async (request: Request, response: Response) => { +HistoryRouter.get('/:username', async (request: Request, response: Response) => { try { - const history = await HistoryServices.getHistory(); + const history = await HistoryServices.getHistory(request.params.username); return response.status(200).json(history); } catch (error: any) { return response.status(500).json(error.message); } }) -HistoryRouter.get('/:id', async (request: Request, response: Response) => { +HistoryRouter.get('/detail/:id', async (request: Request, response: Response) => { const id: number = parseInt(request.params.id, 10); try { const history = await HistoryServices.getHistoryDetail(id); diff --git a/src/handler/history/history.service.ts b/src/handler/history/history.service.ts index 357001aa523acfe5ac87adfff946095fdd2e337c..5ffb5d6da356a957fa9a93fdabc403bc83dee2df 100644 --- a/src/handler/history/history.service.ts +++ b/src/handler/history/history.service.ts @@ -1,12 +1,13 @@ import { History } from "../../interfaces/History"; import { HistoryDetail } from "../../interfaces/HistoryDetail"; import {db} from "../../utils/db.server" +import { getUserId } from "../../utils/getUserId"; -export async function getHistory () : Promise<History[]> { - const user_id = 2; //ini buat temp aja karena auth belom dibuat +export async function getHistory (username : string) : Promise<History[]> { + const userId = await getUserId(username); return db.history.findMany({ where:{ - user_id : user_id, + user_id : userId, }, select: { id: true, diff --git a/src/utils/getUserId.ts b/src/utils/getUserId.ts new file mode 100644 index 0000000000000000000000000000000000000000..a9ca97ef381b86b6ff2f6f59ab0a452546a37a41 --- /dev/null +++ b/src/utils/getUserId.ts @@ -0,0 +1,15 @@ +import {db} from "./db.server" + +export async function getUserId(username : string) { + const result = await db.user.findFirst({ + where: { + username : username + }, + select: { + id : true + } + }); + const userId = result ? result.id : 0; + + return userId; +} \ No newline at end of file