Skip to content

Commit

Permalink
fix timer
Browse files Browse the repository at this point in the history
  • Loading branch information
SIGMazer committed Dec 15, 2023
1 parent 16709a7 commit b6544af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/controllers/carController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/controllers/requestController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/', {
Expand Down

0 comments on commit b6544af

Please sign in to comment.