-
Notifications
You must be signed in to change notification settings - Fork 0
Add Bookings ft #7
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
Merged
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f2d8b67
added bookings
XxcuriousxX d55e990
Merge remote-tracking branch 'origin' into bookings
XxcuriousxX c11d0db
chore: navbar file
sitarass 9bd98d7
fix: useIntersectionObserver
sitarass 515cd48
added getRoutes (as driver || as passenger) func
XxcuriousxX fcc194f
chore: remove redundant file & missing await statements
sitarass b8a9053
refactor --> Routes to Ride fe & be
XxcuriousxX a4f8bf8
chore: naming updates
sitarass 205b411
getRideById impl
XxcuriousxX f6b089a
chore: clean-up & define types
sitarass f47a0a7
chore: comment fix
sitarass 63cdae5
Update back-end/src/controllers/booking.controller.ts
Sitaras 887888f
Update back-end/src/controllers/booking.controller.ts
Sitaras 1dda699
feat: book seat fe
sitarass a9434d4
chore: pagination types
sitarass a0d55d5
Update back-end/src/controllers/user.controller.ts
Sitaras c20006d
chore: upgrade next.js to 16.0.1
sitarass 60a60dc
chore: update wrtch and improve refresh token handling
sitarass bf0bce9
chore: migration zod v3 to v4
sitarass b182ab0
feat: pagination at user getRides
sitarass 161bc89
feat: driver's data
sitarass b7dc38c
feat: me/user-rides fe api
sitarass 20a1f05
refactor: corrections
sitarass 77e7bfd
Update back-end/src/controllers/user.controller.ts
Sitaras 3d4e54e
chore: linters on commit
sitarass 68da195
chore: husky install
sitarass 3144b65
chore: lint configuration
sitarass 66d77a1
chore: lint fe
sitarass e67250d
chore: lint fe
sitarass e7536b4
Logout (#9)
dabouledidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,76 @@ | ||
| import { Response } from "express"; | ||
| import { Booking } from "../models/booking.model"; | ||
| import { Ride } from "../models/ride.model"; | ||
| import { Types } from "mongoose"; | ||
| import { AuthRequest } from "../middleware/auth.middleware"; | ||
| import { isUserInRide } from "../utils/rideUtils"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { ICreateBookingPayload } from "@/schemas/bookingSchema"; | ||
|
|
||
| export class BookingController { | ||
| static async createBooking( | ||
| req: AuthRequest<{}, {}, ICreateBookingPayload>, | ||
| res: Response | ||
| ) { | ||
| try { | ||
| const { rideId } = req.body; | ||
| const passengerId = req.user?.userId; | ||
|
|
||
| if (!Types.ObjectId.isValid(rideId)) { | ||
| return res.error("Invalid Ride ID", StatusCodes.BAD_REQUEST); | ||
| } | ||
|
|
||
| const rideDoc = await Ride.findById(rideId); | ||
| if (!rideDoc) { | ||
| return res.error("Ride not found", StatusCodes.NOT_FOUND); | ||
| } | ||
|
|
||
| if (!rideDoc.isBookable()) { | ||
| return res.error( | ||
| "Ride is not available for booking.", | ||
| StatusCodes.BAD_REQUEST | ||
| ); | ||
| } | ||
|
|
||
| if (rideDoc.driver.toString() === passengerId) { | ||
| return res.error( | ||
| "Driver cannot book their own ride.", | ||
| StatusCodes.BAD_REQUEST | ||
| ); | ||
| } | ||
|
|
||
| if (await isUserInRide(passengerId!, rideId)) { | ||
| return res.error( | ||
| "User already in ride or has pending booking.", | ||
| StatusCodes.BAD_REQUEST | ||
| ); | ||
| } | ||
|
|
||
| rideDoc.passengers.push({ | ||
| user: new Types.ObjectId(passengerId), | ||
| seatsBooked: 1, | ||
| status: "pending", | ||
| }); | ||
| await rideDoc.save(); | ||
|
|
||
| const booking = await Booking.create({ | ||
| passenger: passengerId, | ||
| driver: rideDoc.driver, | ||
| ride: rideId, | ||
| status: "pending", | ||
| }); | ||
|
|
||
| return res.success( | ||
| { status: booking.status }, | ||
| "Booking created successfully.", | ||
| StatusCodes.CREATED | ||
| ); | ||
| } catch (error) { | ||
| return res.error( | ||
| "Server Error", | ||
| StatusCodes.INTERNAL_SERVER_ERROR, | ||
| error | ||
| ); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.