Actualizar server.js
This commit is contained in:
@@ -1809,11 +1809,12 @@ app.post("/services/:id/location", authMiddleware, async (req, res) => {
|
|||||||
|
|
||||||
const locData = { lat, lng, updated_at: new Date().toISOString() };
|
const locData = { lat, lng, updated_at: new Date().toISOString() };
|
||||||
|
|
||||||
|
// CORRECCIÓN: Ahora usa owner_id para que funcione aunque el admin esté haciendo la prueba
|
||||||
await pool.query(`
|
await pool.query(`
|
||||||
UPDATE scraped_services
|
UPDATE scraped_services
|
||||||
SET raw_data = jsonb_set(COALESCE(raw_data, '{}'::jsonb), '{worker_location}', $1::jsonb)
|
SET raw_data = jsonb_set(COALESCE(raw_data, '{}'::jsonb), '{worker_location}', $1::jsonb)
|
||||||
WHERE id = $2 AND assigned_to = $3
|
WHERE id = $2 AND owner_id = $3
|
||||||
`, [JSON.stringify(locData), req.params.id, req.user.sub]);
|
`, [JSON.stringify(locData), req.params.id, req.user.accountId]);
|
||||||
|
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1825,12 +1826,9 @@ app.post("/services/:id/location", authMiddleware, async (req, res) => {
|
|||||||
app.get("/public/portal/:token/location/:serviceId", async (req, res) => {
|
app.get("/public/portal/:token/location/:serviceId", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { token, serviceId } = req.params;
|
const { token, serviceId } = req.params;
|
||||||
|
|
||||||
// Verificar dueño
|
|
||||||
const clientQ = await pool.query("SELECT owner_id FROM clients WHERE portal_token = $1", [token]);
|
const clientQ = await pool.query("SELECT owner_id FROM clients WHERE portal_token = $1", [token]);
|
||||||
if (clientQ.rowCount === 0) return res.status(404).json({ ok: false });
|
if (clientQ.rowCount === 0) return res.status(404).json({ ok: false });
|
||||||
|
|
||||||
// Cargar datos
|
|
||||||
const serviceQ = await pool.query("SELECT raw_data FROM scraped_services WHERE id = $1 AND owner_id = $2", [serviceId, clientQ.rows[0].owner_id]);
|
const serviceQ = await pool.query("SELECT raw_data FROM scraped_services WHERE id = $1 AND owner_id = $2", [serviceId, clientQ.rows[0].owner_id]);
|
||||||
if (serviceQ.rowCount === 0) return res.status(404).json({ ok: false });
|
if (serviceQ.rowCount === 0) return res.status(404).json({ ok: false });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user