Skip to content

Owner registrantion - #6

Merged
prepwave merged 3 commits into
mainfrom
development
Jul 24, 2026
Merged

Owner registrantion#6
prepwave merged 3 commits into
mainfrom
development

Conversation

@prepwave

@prepwave prepwave commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Integrated real backend APIs for authentication, restaurant browsing/search, slot availability by date, booking confirmation, and owner restaurant creation.
    • Added server-driven restaurant recommendations and per-date slot availability, plus Cloud-hosted image uploads for restaurant profiles.
  • Bug Fixes
    • Implemented real “My Bookings” and improved booking cancellation with ownership checks and correct status updates.
    • Updated booking filtering and display to use booking date/time and status; aligned “full”/disabled slot logic to returned availability.
    • Fixed the user registration route and improved error/loading behavior across key pages.
  • Chores
    • Standardized API routing paths and improved startup/operational logging.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c761cd9-81e9-4a2b-8f0a-362d8042c4a4

📥 Commits

Reviewing files that changed from the base of the PR and between 0ea56a0 and c5c63fd.

📒 Files selected for processing (1)
  • server/server.ts
💤 Files with no reviewable changes (1)
  • server/server.ts

📝 Walkthrough

Walkthrough

The client now uses backend APIs for authentication, restaurant discovery, availability, bookings, and owner restaurant creation. The server adds booking retrieval and cancellation, restaurant availability, Cloudinary initialization, route updates, and related authentication and upload wiring.

Changes

API-backed application flows

Layer / File(s) Summary
Authentication and API client foundation
client/package.json, client/src/lib/api.ts, client/src/context/AppContext.tsx, server/middlewares/auth.ts, server/routes/authRoutes.ts
Adds the shared Axios client, bearer-token handling, API authentication calls, current-user loading, and the corrected registration route.
Restaurant discovery and availability
client/src/assets/assets.ts, client/src/pages/Home.tsx, client/src/pages/Search.tsx, client/src/pages/RestaurantDetail.tsx, client/src/components/restaurant/BookingWidget.tsx, server/controllers/restaurantController.ts, server/routes/restaurantRoutes.ts, server/routes/adminRautes.ts, server/server.ts
Replaces restaurant seed data with restaurant and featured-listing requests, adds date-based availability, updates slot state handling, and aligns restaurant route mounts.
Booking retrieval, confirmation, and cancellation
client/src/pages/BookingConfirmation.tsx, client/src/pages/Dashboard.tsx, server/controllers/bookingController.ts
Adds API-backed booking confirmation, user booking retrieval, cancellation authorization and persistence, recommendation loading, and booking status/date rendering.
Owner restaurant creation and image upload
client/src/components/owner/RestaurantWizard.tsx, server/config/cloudinary.ts, server/controllers/ownerController.ts, server/routes/ownerRoutes.ts, server/server.ts
Submits multipart restaurant data through the API, stores selected image state, configures Cloudinary, and wires protected owner routes and upload handling.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RestaurantDetail
  participant api
  participant restaurantController
  participant Booking
  RestaurantDetail->>api: GET /restaurant/:slug
  api->>restaurantController: Request restaurant details
  restaurantController-->>api: Return restaurant
  api-->>RestaurantDetail: Set restaurant and selected date
  RestaurantDetail->>api: GET /restaurant/:id/availability?date=...
  api->>restaurantController: Request date availability
  restaurantController->>Booking: Query pending and confirmed bookings
  Booking-->>restaurantController: Return bookings
  restaurantController-->>api: Return slot availability
  api-->>RestaurantDetail: Set slotsAvailability
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change around owner restaurant registration, though it contains a spelling error.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch development

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 16

🧹 Nitpick comments (4)
client/src/lib/api.ts (1)

3-5: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider adding a request timeout.

No timeout is set on the shared instance, so a slow/unresponsive backend can leave requests pending indefinitely on every page that uses api.

♻️ Suggested fix
 const api = axios.create({
   baseURL: import.meta.env.VITE_API_URL || "http://localhost:5000/api",
+  timeout: 10000,
 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/lib/api.ts` around lines 3 - 5, Update the shared axios instance
in api to configure a finite request timeout alongside baseURL, using the
project’s established timeout setting if one exists or an appropriate bounded
default otherwise.
client/src/pages/Dashboard.tsx (1)

60-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optimistic local update after cancel — fine, but no ownership/response validation.

The local status update assumes the PUT succeeded and uses the client-known bookingId rather than the server's returned booking. Low risk since errors are caught, but consider using res.data.booking from the response to stay in sync with any server-side fields (e.g., updated status if server logic changes).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/pages/Dashboard.tsx` around lines 60 - 62, Update the cancel flow
in Dashboard.tsx to capture the response from api.put and use res.data.booking
for the local bookings update instead of constructing a status-only object from
bookingId. Replace or merge the matching booking using the server-returned
booking data while preserving the existing error handling.
server/controllers/bookingController.ts (1)

96-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a typed Request augmentation instead of repeated as any.

Both handlers cast req as any to reach .user. Extending Express's Request type once (e.g., via a declare global { namespace Express { interface Request { user?: { id: string } } } } augmentation) would remove the repeated unsafe casts and give compile-time safety for req.user.

Also applies to: 130-130

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/controllers/bookingController.ts` at line 96, Replace the repeated req
as any casts in the booking handlers with a shared Express Request type
augmentation defining the optional user object and string id, then access
req.user?.id directly in both handlers. Ensure the augmentation is loaded by
TypeScript and preserve the existing optional-user behavior.
client/src/context/AppContext.tsx (1)

83-97: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Unconditional logout on any /auth/me failure.

Any error (network hiccup, transient 500) causes an immediate logout(), not just an unauthorized/expired-token response. This forces users off the app on recoverable errors. Consider only logging out on 401/403 responses and otherwise leaving the token/session intact.

♻️ Suggested fix
                try {
                 const res= await api.get("/auth/me");
                 setUser(res.data);
                } catch (error: any) {
                    toast.error(error.response?.data?.message || error?.message);
-                   logout();
+                   if (error.response?.status === 401 || error.response?.status === 403) {
+                       logout();
+                   }
                }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/context/AppContext.tsx` around lines 83 - 97, Update the error
handling in the loadUser effect to call logout only when the /auth/me request
returns a 401 or 403 response. Preserve the current error toast, but leave the
token and session intact for network errors and other response failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/src/components/owner/RestaurantWizard.tsx`:
- Around line 95-100: Update the restaurant assignment in the RestaurantWizard
submission flow to store the returned entity from res.data.restaurant rather
than the response envelope. Keep the existing API request and setRestaurant flow
unchanged otherwise, so downstream restaurant properties resolve correctly.

In `@client/src/components/restaurant/BookingWidget.tsx`:
- Around line 87-92: Update the fallback mapping in BookingWidget’s slot
availability logic so a failed or empty slotsAvailability request does not
convert restaurant.availableSlots into entries marked available. Fail closed by
returning no slots or the existing retry state, while preserving normal
rendering when valid availability data is present.

In `@client/src/context/AppContext.tsx`:
- Around line 44-56: Update the success toast in the login flow to use a
template literal so `${userData.name}` is interpolated and the user's name
appears in the welcome message; leave the surrounding token, user, loading, and
error handling unchanged.

In `@client/src/pages/RestaurantDetail.tsx`:
- Around line 58-68: Reset the selected slot when the availability-fetching flow
in RestaurantDetail refreshes slots for a new selectedDate. Clear the selection
before or alongside setSlotsAvailability so stale slots cannot be submitted by
the reserve handler.
- Around line 39-41: Replace the UTC-based date calculation in the
RestaurantDetail initialization with the shared local-date helper, and update
BookingWidget’s today-date calculation and date-input minimum to use that same
helper. Ensure all booking date defaults and “today” filtering reflect the
user’s local calendar date.

In `@client/src/pages/Search.tsx`:
- Around line 42-55: Update the search request effect around the api.get call to
identify and ignore canceled or obsolete responses before calling
setRestaurants. Ensure failed or superseded searches clear the restaurant
results, while preserving loading cleanup and displaying errors only for active,
non-canceled requests.

In `@server/controllers/bookingController.ts`:
- Around line 128-149: Update cancelBooking to read the authenticated user ID
defensively using the same optional-user guard as getMyBooking. When req.user or
its id is absent, return the explicit 401 response before accessing booking
ownership; preserve the existing authorization and cancellation flow for
authenticated requests.
- Around line 106-108: Update the restaurant field selection in the Booking.find
populate within the booking controller to include cuisine alongside name, image,
location, and slug, so Dashboard.tsx receives the restaurant.cuisine value it
renders.

In `@server/controllers/ownerController.ts`:
- Around line 83-86: Remove the raw req.user, req.file, and req.body logging
from the restaurant creation flow, including the duplicate logs around the
referenced area. Replace upload diagnostics with a non-sensitive indicator such
as whether req.file exists, and retain only safe, necessary diagnostic output.
- Around line 172-182: Update the error response in the restaurant creation
handler to stop exposing error.message; retain detailed logging server-side and
return a stable generic internal-error message in the res.status(500).json
response.

In `@server/controllers/restaurantController.ts`:
- Around line 197-200: Update the error response in the restaurant controller’s
catch handler to stop returning error.message, log the exception server-side,
and return a stable generic 500 message to API clients while preserving the
existing success:false response shape.
- Around line 251-255: Remove the raw bookings console.log from the booking flow
around bookedSlots; retain the bookedSlots diagnostic only if needed, ensuring
no complete booking records or customer-linked reservation metadata are emitted.
- Around line 220-226: Standardize booking-date handling across
bookingController.ts and restaurantController.ts by choosing one day-boundary
convention, preferably UTC or restaurant-local time, and apply it consistently
when storing bookingDate, checking duplicates, and building availability query
bounds. Update the logic around selectedDate, startOfDay, and endOfDay to use
the same normalization path rather than mixing new Date(bookingDate) with new
Date(date) and local setHours calls.

In `@server/middlewares/auth.ts`:
- Around line 16-23: Remove the Authorization header and any extracted-token,
decoded-claims, or email/user-data logging from the protect middleware’s
authentication flow, including the surrounding logs in the try block. Preserve
the authentication behavior and retain only non-sensitive diagnostic logging if
needed.

In `@server/routes/authRoutes.ts`:
- Line 7: Update registerUser to ignore or validate req.body.role server-side,
allowing only intended self-service roles and defaulting all other values to the
safe standard role before persistence and token generation. Ensure public
registration cannot create privileged roles such as admin or owner, while
preserving the existing registration route.

In `@server/server.ts`:
- Around line 15-19: Remove the environment-value console.log statements for
CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, and MONGODB_URI near the Express app
initialization, while leaving the configuration usage and app setup unchanged.

---

Nitpick comments:
In `@client/src/context/AppContext.tsx`:
- Around line 83-97: Update the error handling in the loadUser effect to call
logout only when the /auth/me request returns a 401 or 403 response. Preserve
the current error toast, but leave the token and session intact for network
errors and other response failures.

In `@client/src/lib/api.ts`:
- Around line 3-5: Update the shared axios instance in api to configure a finite
request timeout alongside baseURL, using the project’s established timeout
setting if one exists or an appropriate bounded default otherwise.

In `@client/src/pages/Dashboard.tsx`:
- Around line 60-62: Update the cancel flow in Dashboard.tsx to capture the
response from api.put and use res.data.booking for the local bookings update
instead of constructing a status-only object from bookingId. Replace or merge
the matching booking using the server-returned booking data while preserving the
existing error handling.

In `@server/controllers/bookingController.ts`:
- Line 96: Replace the repeated req as any casts in the booking handlers with a
shared Express Request type augmentation defining the optional user object and
string id, then access req.user?.id directly in both handlers. Ensure the
augmentation is loaded by TypeScript and preserve the existing optional-user
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e0cc66da-89bd-43d8-8a81-11a694b1a522

📥 Commits

Reviewing files that changed from the base of the PR and between dac45b3 and 34b5ddb.

⛔ Files ignored due to path filters (1)
  • client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (21)
  • client/package.json
  • client/src/assets/assets.ts
  • client/src/components/owner/RestaurantWizard.tsx
  • client/src/components/restaurant/BookingWidget.tsx
  • client/src/context/AppContext.tsx
  • client/src/lib/api.ts
  • client/src/pages/BookingConfirmation.tsx
  • client/src/pages/Dashboard.tsx
  • client/src/pages/Home.tsx
  • client/src/pages/RestaurantDetail.tsx
  • client/src/pages/Search.tsx
  • server/config/cloudinary.ts
  • server/controllers/bookingController.ts
  • server/controllers/ownerController.ts
  • server/controllers/restaurantController.ts
  • server/middlewares/auth.ts
  • server/routes/adminRautes.ts
  • server/routes/authRoutes.ts
  • server/routes/ownerRoutes.ts
  • server/routes/restaurantRoutes.ts
  • server/server.ts

Comment thread client/src/components/owner/RestaurantWizard.tsx
Comment thread client/src/components/restaurant/BookingWidget.tsx
Comment thread client/src/context/AppContext.tsx
Comment thread client/src/pages/RestaurantDetail.tsx
Comment thread client/src/pages/RestaurantDetail.tsx
Comment thread server/controllers/restaurantController.ts
Comment thread server/controllers/restaurantController.ts
Comment thread server/middlewares/auth.ts
Comment thread server/routes/authRoutes.ts
Comment thread server/server.ts Outdated
@prepwave
prepwave merged commit ba6ee73 into main Jul 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant