Skip to content
Snippets Groups Projects
Commit 59933a49 authored by Ulung32's avatar Ulung32
Browse files

feat add getHistory and getHistoryDetail

parent f5c751ed
Branches
Tags
No related merge requests found
import express from "express";
import type { Request, Response } from "express";
// import { body, validationResult } from "express-validator";
import * as HistoryServices from './history.service'
export const HistoryRouter = express.Router()
HistoryRouter.get('/', async (request: Request, response: Response) => {
try {
const history = await HistoryServices.getHistory();
return response.status(200).json(history);
} catch (error: any) {
return response.status(500).json(error.message);
}
})
HistoryRouter.get('/:id', async (request: Request, response: Response) => {
const id: number = parseInt(request.params.id, 10);
try {
const history = await HistoryServices.getHistoryDetail(id);
return response.status(200).json(history);
} catch (error: any) {
return response.status(500).json(error.message);
}
})
\ No newline at end of file
import {db} from "../utils/db.server"
type History = {
id: number,
user_id : number,
alamat_tujuan: string,
nama_penerima: string,
rating: number,
}
type HistoryDetail = {
id: number,
history_id : number,
product_name: string,
quantity: number,
}
export const getHistory = async (): Promise<History[]> => {
const user_id = 2; //ini buat temp aja karena auth belom dibuat
return db.history.findMany({
where:{
user_id : user_id,
},
select: {
id: true,
user_id: true,
alamat_tujuan: true,
nama_penerima: true,
rating: true
}
})
}
export const getHistoryDetail = async (historyId: number): Promise<HistoryDetail[]> => {
return db.historyDetail.findMany({
where:{
history_id: historyId
},
select:{
id: true,
history_id: true,
product_name: true,
quantity: true
}
})
}
\ No newline at end of file
import express, {Express, Request, Response} from "express"; import express, {Express, Request, Response} from "express";
import { HistoryRouter } from "./history/history.router";
const app = express(); const app = express();
const port = 5000; const port = 5000;
app.use('/history', HistoryRouter);
app.get("/", (req, res) => { app.get("/", (req, res) => {
res.send("test get home"); res.send("test get home");
}) })
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment