Spaces:
Runtime error
Runtime error
Download src/controllers/gateController.js from yeshwanth-kr/dss-server: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/yeshwanth-kr/dss-server/resolve/main/src/controllers/gateController.js
- Command line
-
hf download hf://spaces/yeshwanth-kr/dss-server/src/controllers/gateController.js
-
curl -L -o gateController.js https://huggingface.co/spaces/yeshwanth-kr/dss-server/resolve/main/src/controllers/gateController.js
1.15 kB
| const dayjs = require('dayjs'); | |
| const { GatePass, Employee, Vendor } = require('../models'); | |
| async function gateSync(req, res, next) { | |
| try { | |
| const { barcode } = req.params; | |
| const gatePass = await GatePass.findOne({ barcode }).sort({ created_at: -1 }).lean(); | |
| if (!gatePass) { | |
| return res.status(404).json({ message: 'Pass not found' }); | |
| } | |
| const employee = await Employee.findById(gatePass.employee_id, { name: 1, vendor_id: 1 }).lean(); | |
| if (!employee) { | |
| return res.status(404).json({ message: 'Employee not found' }); | |
| } | |
| const vendor = await Vendor.findById(employee.vendor_id, { name: 1 }).lean(); | |
| const isExpired = dayjs(gatePass.expiry_date).isBefore(dayjs().startOf('day')); | |
| const status = gatePass.status === 'Active' && !isExpired | |
| ? 'VALID' | |
| : (isExpired ? 'EXPIRED' : gatePass.status); | |
| return res.json({ | |
| name: employee.name, | |
| contractor: vendor?.name || 'N/A', | |
| expiry_date: gatePass.expiry_date ? dayjs(gatePass.expiry_date).format('DD/MM/YYYY') : null, | |
| status | |
| }); | |
| } catch (error) { | |
| return next(error); | |
| } | |
| } | |
| module.exports = { gateSync }; | |