feat: wire up loyalty + chat — register routes, API types, connect LoyaltyPage, add ChatWidget to layout
This commit is contained in:
23
backend/migrations/038_loyalty_settings.sql
Normal file
23
backend/migrations/038_loyalty_settings.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE IF NOT EXISTS loyalty_settings (
|
||||
hotel_id UUID PRIMARY KEY REFERENCES hotels(id) ON DELETE CASCADE,
|
||||
is_active BOOLEAN NOT NULL DEFAULT true,
|
||||
points_per_ruble NUMERIC(10,4) NOT NULL DEFAULT 0.1,
|
||||
point_value NUMERIC(10,4) NOT NULL DEFAULT 0.01,
|
||||
expiry_months INT NOT NULL DEFAULT 12,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS loyalty_transactions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hotel_id UUID NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
|
||||
guest_id UUID NOT NULL REFERENCES guests(id) ON DELETE CASCADE,
|
||||
amount INT NOT NULL, -- positive = accrual, negative = spend
|
||||
reason VARCHAR(100) NOT NULL DEFAULT 'manual',
|
||||
notes TEXT,
|
||||
staff_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Ensure guests have loyalty columns (may already exist)
|
||||
ALTER TABLE guests ADD COLUMN IF NOT EXISTS loyalty_tier VARCHAR(20) NOT NULL DEFAULT 'bronze';
|
||||
ALTER TABLE guests ADD COLUMN IF NOT EXISTS loyalty_points INT NOT NULL DEFAULT 0;
|
||||
30
backend/migrations/039_chat.sql
Normal file
30
backend/migrations/039_chat.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
CREATE TABLE IF NOT EXISTS chat_rooms (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hotel_id UUID NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
|
||||
type VARCHAR(10) NOT NULL DEFAULT 'general' CHECK (type IN ('general', 'direct')),
|
||||
name VARCHAR(100),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chat_room_members (
|
||||
room_id UUID NOT NULL REFERENCES chat_rooms(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (room_id, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chat_messages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
room_id UUID NOT NULL REFERENCES chat_rooms(id) ON DELETE CASCADE,
|
||||
hotel_id UUID NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
|
||||
sender_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
text TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_chat_messages_room ON chat_messages(room_id, created_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chat_read_status (
|
||||
room_id UUID NOT NULL REFERENCES chat_rooms(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
last_read TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
PRIMARY KEY (room_id, user_id)
|
||||
);
|
||||
Reference in New Issue
Block a user