прибрался

This commit is contained in:
2026-05-07 20:40:49 +05:00
parent e1aada4777
commit b162f2495d
4 changed files with 1346 additions and 1300 deletions

View File

@@ -31,8 +31,17 @@ db.run(`CREATE TABLE IF NOT EXISTS bookings (
children INTEGER NOT NULL,
checkin_date TEXT NOT NULL,
checkout_date TEXT NOT NULL,
wishes TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`);
)`, (err) => {
if (err) console.error('Table creation error:', err);
});
db.run(`ALTER TABLE bookings ADD COLUMN wishes TEXT`, (err) => {
if (err && !err.message.includes('duplicate column name')) {
console.error('Migration error:', err);
}
});
// Image conversion (automatically convert JPEG/PNG to WebP)
async function convertImages() {
@@ -63,13 +72,13 @@ async function convertImages() {
// API: POST /api/bookings сохранить новую заявку
app.post('/api/bookings', (req, res) => {
const { name, phone, adults, children, checkin, checkout } = req.body;
const { name, phone, adults, children, checkin, checkout, wishes } = req.body;
if (!name || !phone || !adults || !checkin || !checkout) {
return res.status(400).json({ error: 'Missing required fields' });
}
const stmt = db.prepare(`INSERT INTO bookings (name, phone, adults, children, checkin_date, checkout_date)
VALUES (?, ?, ?, ?, ?, ?)`);
stmt.run(name, phone, adults, children || 0, checkin, checkout, function(err) {
const stmt = db.prepare(`INSERT INTO bookings (name, phone, adults, children, checkin_date, checkout_date, wishes)
VALUES (?, ?, ?, ?, ?, ?, ?)`);
stmt.run(name, phone, parseInt(adults), parseInt(children || 0), checkin, checkout, wishes || null, function(err) {
if (err) {
console.error(err);
return res.status(500).json({ error: 'Database error' });
@@ -85,7 +94,7 @@ app.get('/api/bookings', (req, res) => {
if (!providedKey || providedKey !== API_KEY) {
return res.status(401).json({ error: 'Invalid or missing API key' });
}
db.all(`SELECT id, name, phone, adults, children, checkin_date, checkout_date, created_at
db.all(`SELECT id, name, phone, adults, children, checkin_date, checkout_date, wishes, created_at
FROM bookings ORDER BY created_at DESC`, (err, rows) => {
if (err) {
console.error(err);