40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
|
|
const express = require('express');
|
||
|
|
const { query } = require('../config/database');
|
||
|
|
const router = express.Router();
|
||
|
|
|
||
|
|
router.get('/', async (req, res) => {
|
||
|
|
try {
|
||
|
|
const products = await query(
|
||
|
|
'SELECT id, name, description, price, imageurl FROM products WHERE isactive = true ORDER BY createdat DESC LIMIT 8'
|
||
|
|
);
|
||
|
|
const sections = await query(
|
||
|
|
'SELECT * FROM homepagesections ORDER BY displayorder ASC'
|
||
|
|
);
|
||
|
|
res.render('public/home', {
|
||
|
|
title: 'Welcome - SkyArtShop',
|
||
|
|
products: products.rows,
|
||
|
|
sections: sections.rows
|
||
|
|
});
|
||
|
|
} catch (error) {
|
||
|
|
console.error('Home page error:', error);
|
||
|
|
res.status(500).send('Server error');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
router.get('/shop', async (req, res) => {
|
||
|
|
try {
|
||
|
|
const products = await query(
|
||
|
|
'SELECT id, name, description, price, imageurl, category FROM products WHERE isactive = true ORDER BY name ASC'
|
||
|
|
);
|
||
|
|
res.render('public/shop', {
|
||
|
|
title: 'Shop - SkyArtShop',
|
||
|
|
products: products.rows
|
||
|
|
});
|
||
|
|
} catch (error) {
|
||
|
|
console.error('Shop page error:', error);
|
||
|
|
res.status(500).send('Server error');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
module.exports = router;
|