feat: room photo gallery, featured photo, and comments moderation
This commit is contained in:
@@ -71,3 +71,8 @@ export async function requireAuth() {
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function canComment(userId: number) {
|
||||
const { rows } = await db.query('SELECT comments_disabled FROM users WHERE id = $1', [userId]);
|
||||
return rows.length === 0 || !rows[0].comments_disabled;
|
||||
}
|
||||
|
||||
+34
-8
@@ -136,14 +136,40 @@ export async function initSchema() {
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS calendar_events (
|
||||
CREATE TABLE IF NOT EXISTS room_comments (
|
||||
id SERIAL PRIMARY KEY,
|
||||
date DATE NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(50) NOT NULL CHECK (type IN ('holiday', 'season', 'weather', 'event')),
|
||||
description TEXT,
|
||||
color VARCHAR(50) DEFAULT '#E8A849',
|
||||
active BOOLEAN DEFAULT TRUE,
|
||||
room_id INTEGER REFERENCES rooms(id) ON DELETE CASCADE,
|
||||
photo_url VARCHAR(500),
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
||||
first_name VARCHAR(100) NOT NULL,
|
||||
last_initial VARCHAR(10),
|
||||
text TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
deleted_by_admin BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
ALTER TABLE rooms ADD COLUMN IF NOT EXISTS featured_photo VARCHAR(500);
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS comments_disabled BOOLEAN DEFAULT FALSE;
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS first_name VARCHAR(100);
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS last_name VARCHAR(100);
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS user_sessions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
||||
token TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
`);
|
||||
@@ -255,7 +281,7 @@ export async function seed() {
|
||||
}
|
||||
|
||||
export async function resetDatabase() {
|
||||
await db.query('DROP TABLE IF EXISTS reviews, places, menu_items, rooms, config, benefits, offers, coupons, reservations, images, users, slides, calendar_events CASCADE');
|
||||
await db.query('DROP TABLE IF EXISTS room_comments, reviews, places, menu_items, rooms, config, benefits, offers, coupons, reservations, images, users, slides, calendar_events CASCADE');
|
||||
await initSchema();
|
||||
await seed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user