Skip to content

Commit

Permalink
Fix for pro (#23)
Browse files Browse the repository at this point in the history
* Update function

* Change logic

* Change coord
  • Loading branch information
ZhengLinLei authored May 9, 2024
1 parent edadad3 commit 690392f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/drone-api/controllers/Drones.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DroneModel from '../models/Drones.js';
import _Common from './common.js';
import logger from './logger.js';

export default class _DroneController {
static async findAll() {
Expand All @@ -24,6 +25,7 @@ export default class _DroneController {
}

static async insertOneWithFlight (dic, auth_code, route, priority, altitude) {
logger.info(`Inserting drone with dic: ${dic} and auth_code: ${auth_code}`);
const newDrone = new DroneModel({
dic,
auth_code,
Expand All @@ -37,6 +39,7 @@ export default class _DroneController {
}

static async updateOneWithFlight (dic, auth_code, route, priority, altitude) {
logger.info(`Inserting drone with dic: ${dic} and auth_code: ${auth_code}`);
await DroneModel.updateOne({
dic,
auth_code
Expand Down
24 changes: 10 additions & 14 deletions src/drone-api/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,18 @@ router.post('/routes/:dic', async (req, res) => {
let response = await provider.getProvider(req.params.dic, auth, route);

if (response.status == 200) {
let jsonStr = response.json()
// Get the status of the route
if (jsonStr.status == 1) {
// Insrt drone with all data, and if already exist update the data
let drone = await _DroneController.findDroneExist(req.params.dic, auth);

route = JSON.stringify(route);
if (drone.length == 0) {
await _DroneController.insertOneWithFlight(req.params.dic, auth, route, 1, jsonStr.dangerous_level);
}
else {
await _DroneController.updateOneWithFlight(req.params.dic, auth, route, 1, jsonStr.dangerous_level);
}

// Insrt drone with all data, and if already exist update the data
let drone = await _DroneController.findDroneExist(req.params.dic, auth);

if (drone.length == 0) {
await _DroneController.insertOneWithFlight(req.params.dic, auth, route["coord"], 1, 0);
}
else {
await _DroneController.updateOneWithFlight(req.params.dic, auth, route["coord"], 1, 0);
}

return _Common.rJson(res, jsonStr);
return _Common.rJson(res, {});
}

if (response.status == 404) {
Expand Down

0 comments on commit 690392f

Please # to comment.