-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update driver api #232
update driver api #232
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
throw error(400, 'Bad request'); | ||
} | ||
|
||
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)) { | ||
throw error(404, 'Not found'); | ||
} | ||
|
||
return new Response(null, { status: 204 }); | ||
}; |
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'; | ||
throw error(400, 'Bad request'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
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)) { | ||
throw error(404, 'Not found'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error |
||
} | ||
|
||
return new Response(null, { status: 204 }); | ||
}; |
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 { json, error } 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)) { | ||
throw error(400, 'Bad request'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
return json(await getTours(false, companyId, [fromTime, toTime])); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
https://svelte.dev/docs/kit/errors