-
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.
* update driver api * fix test run * wip * wip * wip * wip --------- Co-authored-by: Felix Gündling <[email protected]>
- Loading branch information
1 parent
f5e2aae
commit f68447c
Showing
4 changed files
with
58 additions
and
24 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
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,16 +1,24 @@ | ||
import { db } from '$lib/server/db'; | ||
import { readInt } from '$lib/server/util/readForm.js'; | ||
import { json } from '@sveltejs/kit'; | ||
import { error } from '@sveltejs/kit'; | ||
|
||
export const POST = async ({ url }) => { | ||
export const PUT = async ({ url }) => { | ||
const tourId = readInt(url.searchParams.get('tourId')); | ||
const fare = readInt(url.searchParams.get('fare')); | ||
|
||
if (isNaN(fare) || isNaN(tourId)) { | ||
throw 'bad params'; | ||
error(400, { message: 'Invalid fare or tourId parameter' }); | ||
} | ||
|
||
await db.updateTable('tour').set({ fare: fare }).where('id', '=', tourId).execute(); | ||
const result = await db | ||
.updateTable('tour') | ||
.set({ fare: fare }) | ||
.where('id', '=', tourId) | ||
.executeTakeFirst(); | ||
|
||
return json({ success: true }); | ||
if (result.numUpdatedRows === BigInt(0)) { | ||
error(404, { message: 'Tour not found' }); | ||
} | ||
|
||
return new Response(null, { status: 204 }); | ||
}; |
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,21 +1,25 @@ | ||
import { db } from '$lib/server/db'; | ||
import { readInt } from '$lib/server/util/readForm.js'; | ||
import { json } from '@sveltejs/kit'; | ||
import { error } from '@sveltejs/kit'; | ||
|
||
export const POST = async ({ url }) => { | ||
export const PUT = async ({ url }) => { | ||
const requestId = readInt(url.searchParams.get('requestId')); | ||
const ticketCode = url.searchParams.get('ticketCode'); | ||
|
||
if (typeof ticketCode !== 'string' || isNaN(requestId)) { | ||
throw 'bad params'; | ||
error(400, { message: 'Invalid ticketCode parameter' }); | ||
} | ||
|
||
await db | ||
const result = await db | ||
.updateTable('request') | ||
.set({ ticketChecked: true }) | ||
.where('id', '=', requestId) | ||
.where('ticketCode', '=', ticketCode) | ||
.execute(); | ||
.executeTakeFirst(); | ||
|
||
return json({ success: true }); | ||
if (result.numUpdatedRows === BigInt(0)) { | ||
error(404, { message: 'Request not found or invalid ticket code' }); | ||
} | ||
|
||
return new Response(null, { status: 204 }); | ||
}; |
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,10 +1,15 @@ | ||
import { getTours } from '$lib/server/db/getTours'; | ||
import { readInt } from '$lib/server/util/readForm.js'; | ||
import { json } from '@sveltejs/kit'; | ||
import { error, json } from '@sveltejs/kit'; | ||
|
||
export const GET = async ({ locals, url }) => { | ||
const companyId = locals.session!.companyId!; | ||
const fromTime = readInt(url.searchParams.get('fromTime')); | ||
const toTime = readInt(url.searchParams.get('toTime')); | ||
|
||
if (isNaN(fromTime) || isNaN(toTime)) { | ||
error(400, { message: 'Invalid time range' }); | ||
} | ||
|
||
return json(await getTours(false, companyId, [fromTime, toTime])); | ||
}; |