Skip to content
Snippets Groups Projects
Commit 829f8dc5 authored by DewanaGustavus's avatar DewanaGustavus
Browse files

fix: edit some history service code

parent f5efca0d
No related merge requests found
......@@ -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);
......
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,
......
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
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