Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Components/admin/Csr/Modals/NewBookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const ADD_ON_PRICES = {
extraSlippers: 30,
};

const statusOptions = ["pending", "approved", "declined", "checked-in", "checked-out", "cancelled", "completed"];
const statusOptions = ["pending", "approved", "declined", "checked-in", "checked-out", "cancelled", "completed", "failed"];
const paymentMethods = ["cash", "gcash", "bank-transfer", "credit-card"];

export default function NewBookingModal({ onClose, initialBooking, onSuccess }: NewBookingModalProps) {
Expand Down
8 changes: 5 additions & 3 deletions backend/controller/bookingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const updateBookingDetails = async (
"checked-in",
"completed",
"cancelled",
"failed",
];
if (typeof status !== "undefined" && status !== null) {
if (typeof status !== "string" || !validStatuses.includes(status)) {
Expand Down Expand Up @@ -345,7 +346,8 @@ export interface Booking {
| "confirmed"
| "checked-in"
| "completed"
| "cancelled";
| "cancelled"
| "failed";
add_ons?: AddOnItem[];
created_at?: string;
updated_at?: string;
Expand Down Expand Up @@ -995,7 +997,7 @@ export const updateBookingStatus = async (
// If status is provided, validate it
const validStatuses = [
"pending", "approved", "rejected", "confirmed",
"checked-in", "completed", "cancelled",
"checked-in", "completed", "cancelled", "failed",
];
if (typeof status !== "undefined" && status !== null) {
if (typeof status !== "string" || !validStatuses.includes(status)) {
Expand Down Expand Up @@ -1419,4 +1421,4 @@ export const getRoomBookings = async (
{ status: 500 },
);
}
};
};
52 changes: 52 additions & 0 deletions backend/migrations/2026-03-02-add-failed-booking-status.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- Staycation/backend/migrations/2026-03-02-add-failed-booking-status.sql
-- Migration: allow booking.status = 'failed' for edit/update flows.
--
-- IMPORTANT:
-- - BACKUP your database before running this migration.
-- - Run in staging first.
-- - This script is idempotent for environments with varying constraint names.

BEGIN;

-- Drop existing booking status check constraint(s) regardless of generated name.
DO $$
DECLARE
c RECORD;
BEGIN
FOR c IN
SELECT conname
FROM pg_constraint
WHERE conrelid = 'booking'::regclass
AND contype = 'c'
AND pg_get_constraintdef(oid) ILIKE '%status%'
AND pg_get_constraintdef(oid) ILIKE '%pending%'
AND pg_get_constraintdef(oid) ILIKE '%approved%'
LOOP
EXECUTE format('ALTER TABLE booking DROP CONSTRAINT IF EXISTS %I', c.conname);
END LOOP;
END
$$;

ALTER TABLE booking
ADD CONSTRAINT booking_status_check
CHECK (
status IN (
'pending',
'approved',
'rejected',
'confirmed',
'checked-in',
'completed',
'cancelled',
'failed'
)
);

COMMIT;

-- Verify constraint now allows failed.
SELECT conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE conrelid = 'booking'::regclass
AND contype = 'c'
AND pg_get_constraintdef(oid) ILIKE '%status%';
3 changes: 2 additions & 1 deletion backend/models/bookings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ CREATE TABLE booking (
'confirmed',
'checked-in',
'completed',
'cancelled'
'cancelled',
'failed'
)),

rejection_reason TEXT,
Expand Down