{"size": 1006, "ext": "js", "max_stars_repo_path": "routes/pi.js", "max_stars_repo_name": "mooseetws/mooseetws-backend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "routes/pi.js", "max_issues_repo_name": "mooseetws/mooseetws-backend", "max_issues_repo_issues_event_min_datetime": "2021-05-08T17:33:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-08T17:33:53.000Z", "max_forks_repo_path": "routes/pi.js", "max_forks_repo_name": "mooseetws/mooseetws-backend", "max_forks_repo_forks_event_min_datetime": "2019-08-21T13:17:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-21T13:17:13.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 21.8695652174, "max_line_length": 67, "alphanum_fraction": 0.6928429423}
var express = require('express');
var router = express.Router();

const {
  getPIData,
  generateTopology1
} = require('./../data/data');

const {
  getNearestLampList,
  getNotificationIds
} = require('./../engine/topology');

const {
  sendNotification
} = require('./../engine/notification');

router.get('/', function (req, res, next) {
  const data = getPIData();
  res.status(200).json(data);
});

/**
 * PI endpoint
 * It will receive a list of detected object passed from tensorflow
 * and store it in the database.
 * # todo if the object type if categorised as hazardous
 * Send notification to nearby poles immediately
 */

router.post('/', function (req, res, next) {
  const data = req.body;

  const topo1 = generateTopology1();
  const id = parseInt(data.poleId, 10);
  let lampList = getNearestLampList(id, topo1);
  console.log(lampList);
  let personList = getNotificationIds(lampList);

  sendNotification(personList);

  return res.status(200).send(data);
});

module.exports = router;
