From b6544afd0202a994f91127b4c07269d27ccac089 Mon Sep 17 00:00:00 2001 From: SIGMazer Date: Sat, 16 Dec 2023 01:13:49 +0200 Subject: [PATCH] fix timer --- src/controllers/carController.js | 17 +++++++---------- src/controllers/requestController.js | 1 - 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/controllers/carController.js b/src/controllers/carController.js index a60e519..701d745 100644 --- a/src/controllers/carController.js +++ b/src/controllers/carController.js @@ -41,18 +41,15 @@ exports.updateCarLocation = async function updateCarLocation(carID, location) { exports.updateCarStatus = async function updateCarStatus(carID, status, location) { try { - const update = {carStatus: status}; + const update = {carStatus: status, destination: location}; const options = {new: true}; const result = await Car.findByIdAndUpdate(carID, {$set: update}, options); - await updateCarDestination(carID, location); - if(status !==0){ - setTimeout(async () => { - const update = {carStatus: 0}; - await Car.findByIdAndUpdate(carID, {$set: update}, options); - await requestController.deleteLastRequest(carID); - await updateCarLocation(carID, location); - }, 5 * 1000 * 60); - } + setTimeout(async () => { + const update = {carStatus: 0}; + await Car.findByIdAndUpdate(carID, {$set: update}, options); + await requestController.deleteLastRequest(carID); + await this.updateCarLocation(carID, location); + }, 5 * 1000 ); return result; } catch(error) { diff --git a/src/controllers/requestController.js b/src/controllers/requestController.js index 2eb30ed..9c19862 100644 --- a/src/controllers/requestController.js +++ b/src/controllers/requestController.js @@ -5,7 +5,6 @@ const userController = require("./userController"); const functionController = require("./functionController"); function stopBracelet(braceletID) { - console.log("hello") const b =JSON.parse(`{"braceletId": "${braceletID}"}`); fetch('http://localhost:1337/api/stop/', {