-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read vehicles from database and display license plates in availabilit…
…y view (#9)
- Loading branch information
1 parent
c6f5635
commit dc8515a
Showing
4 changed files
with
39 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import type { Company } from './types'; | ||
import type { Company, Vehicle } from './types'; | ||
|
||
export const getCompany = async (id: number): Promise<Company> => { | ||
const response = await fetch(`/api/company?id=${id}`); | ||
return await response.json(); | ||
}; | ||
|
||
export const getVehicles = async (company_id: number): Promise<Vehicle[]> => { | ||
const response = await fetch(`/api/vehicle?company=${company_id}`); | ||
return await response.json(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import { db } from '$lib/database'; | ||
|
||
export async function GET({ url }) { | ||
const id = Number(url.searchParams.get('company')!); | ||
const vehicles = await db.selectFrom('vehicle').where('company', '=', id).selectAll().execute(); | ||
return json(vehicles); | ||
} |