alksdfja
This commit is contained in:
@@ -1411,6 +1411,18 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex
|
||||
// @access Private
|
||||
router.get('/logs', async (req, res, next) => {
|
||||
try {
|
||||
const { planId } = req.query;
|
||||
|
||||
let whereConditions = ['p.user_id = $1'];
|
||||
let queryParams = [req.user.id];
|
||||
|
||||
if (planId) {
|
||||
whereConditions.push('al.plan_id = $2');
|
||||
queryParams.push(planId);
|
||||
}
|
||||
|
||||
const whereClause = whereConditions.join(' AND ');
|
||||
|
||||
const result = await pool.query(`
|
||||
SELECT
|
||||
al.*,
|
||||
@@ -1424,9 +1436,9 @@ router.get('/logs', async (req, res, next) => {
|
||||
JOIN properties p ON ls.property_id = p.id
|
||||
JOIN user_equipment ue ON al.equipment_id = ue.id
|
||||
LEFT JOIN equipment_types et ON ue.equipment_type_id = et.id
|
||||
WHERE p.user_id = $1
|
||||
WHERE ${whereClause}
|
||||
ORDER BY al.application_date DESC, al.created_at DESC
|
||||
`, [req.user.id]);
|
||||
`, queryParams);
|
||||
|
||||
const logs = result.rows.map(row => ({
|
||||
id: row.id,
|
||||
@@ -1444,6 +1456,11 @@ router.get('/logs', async (req, res, next) => {
|
||||
createdAt: row.created_at
|
||||
}));
|
||||
|
||||
console.log(`GET /logs query with planId: ${planId}, found ${logs.length} logs`);
|
||||
if (logs.length > 0) {
|
||||
console.log('First log GPS track:', logs[0].gpsTrack);
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user