Commit 5abe6169 authored by Pinon Gregory's avatar Pinon Gregory 🦉
Browse files

Initial commit

parents
node_modules/*
test
.nyc_output
logs
\ No newline at end of file
#TODO: Change 127.0.0.1 to db-ignite
DB_URL=172.17.0.1:10800
DB_USER=ignite
DB_PASSWORD=oemcs2
DEFAULT_USER=admin
DEFAULT_PASSWORD=admin
JWT_SECRET=D94AD7C66DA6FE86FD91D478DF2AC
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/backend-supervision.iml" filepath="$PROJECT_DIR$/.idea/backend-supervision.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
FROM node:12
WORKDIR /app
COPY package*.json ./
RUN npm install && \
npm rebuild bcrypt --build-from-source
COPY . .
RUN chmod +x start.sh
CMD [ "node", "index.js" ]
\ No newline at end of file
const { Router } = require("express");
const patient = require("./routes/patient.route");
const personnel = require("./routes/personnel.route");
const auth = require("./routes/auth.route");
const plan = require("./routes/plan.route");
const { verify } = require("./middlewares");
const app = Router();
//TODO : Extends test cases
app.use("/patient", verify, patient);
app.use("/personnel", verify, personnel);
app.use("/plan", verify, plan);
app.use(auth);
module.exports = app;
const jwt = require("jsonwebtoken");
const logger = require("../../loaders/logger");
exports.verify = async function (req, res, next) {
let token = req.headers["x-access-token"] || req.headers["authorization"];
if (token) {
if (token.startsWith("Bearer ")) {
token = token.slice(7, token.length).trimLeft();
}
try {
let decoded = jwt.verify(token, process.env.JWT_SECRET);
req.body.user = { id: decoded.id };
next();
} catch (e) {
logger.warn(`Error during JWT verify - ${e.message}`, { tag: "jwt" });
res.status(401).send("Wrong authorization token");
}
} else {
res.status(401).send("No token in header");
}
};
var express = require("express");
var router = express.Router();
const bcrypt = require("bcrypt");
const jwt = require("jsonwebtoken");
const PersonnelModel = require("../../models/PersonnelModel");
const { verify } = require("../middlewares");
const { celebrate, Joi, Segments } = require("celebrate");
router.post(
"/login",
celebrate({
[Segments.BODY]: Joi.object().keys({
username: Joi.string().required(),
password: Joi.string().required(),
}),
}),
async function (req, res) {
let user = { username: req.body.username, password: req.body.password };
if (!user.username || !user.password) {
res.status(401).send("Not complete fields");
} else {
let personnel = await PersonnelModel.getWithName(user.username);
if (
personnel &&
(await bcrypt.compare(user.password, personnel.password))
) {
let token = jwt.sign({ id: personnel.id }, process.env.JWT_SECRET, {
expiresIn: "12h",
});
res.send({ token: token, id: personnel.id });
} else {
res.status(401).send("Wrong credentials");
}
}
}
);
router.get("/login", verify, async function (req, res) {
// for (let i = 0; i < 3; i++) {
// await bcrypt.hash("foobarfoobarfoo", 10);
// }
res.send([req.body.user]);
});
module.exports = router;
var express = require("express");
var router = express.Router();
const { celebrate, Joi, Segments } = require("celebrate");
const PatientModel = require("../../models/PatientModel");
router.get("", async function (req, res) {
res.send(await PatientModel.getAll());
});
router.post(
"",
celebrate({
[Segments.BODY]: Joi.object()
.keys({
name: Joi.string().required(),
baliseID: Joi.string().required(),
chambre: Joi.string().required(),
escalier: Joi.number().required(),
porte: Joi.number().required(),
ascenceur: Joi.number().required(),
difficulte: Joi.number().required(),
})
.unknown(),
}),
async function (req, res) {
let patient = await PatientModel.insert(req.body);
if (patient) {
res.send(patient);
} else {
res.status(404).send();
}
}
);
router.put(
"",
celebrate({
[Segments.BODY]: Joi.object()
.keys({
name: Joi.string().required(),
baliseID: Joi.string().required(),
chambre: Joi.string().required(),
escalier: Joi.boolean().required(),
difficulte: Joi.number().required(),
})
.unknown(),
}),
async function (req, res) {
let patient = await PatientModel.update(req.body);
if (patient) {
res.send(patient);
} else {
res.status(404).send();
}
}
);
router.get("/:id", async function (req, res) {
let patient = await PatientModel.getWithID(parseInt(req.params.id));
if (patient) {
res.send(patient);
} else {
res.status(404).send();
}
});
router.delete("/:id", async function (req, res) {
if (await PatientModel.delete(parseInt(req.params.id))) {
res.send({ id: parseInt(req.params.id) });
} else {
res.status(404).send();
}
});
module.exports = router;
var express = require("express");
var router = express.Router();
const bcrypt = require("bcrypt");
const { celebrate, Joi, Segments } = require("celebrate");
const PersonnelModel = require("../../models/PersonnelModel");
router.get("", async function (req, res) {
let personnels = await PersonnelModel.getAll();
for (p of personnels) delete p.password;
res.send(personnels);
});
router.post(
"",
celebrate({
[Segments.BODY]: Joi.object()
.keys({
username: Joi.string().required(),
password: Joi.string().required(),
})
.unknown(),
}),
async function (req, res) {
if (await PersonnelModel.checkUniqueName(req.body.username)) {
const hashedPassword = await bcrypt.hash(req.body.password, 10);
req.body.password = hashedPassword;
let personnel = await PersonnelModel.insert(req.body);
if (personnel) {
delete personnel.password;
res.send(personnel);
} else {
res.status(404).send();
}
} else {
res.status(404).send("Username already exists");
}
}
);
router.put(
"",
celebrate({
[Segments.BODY]: Joi.object()
.keys({
id: Joi.number().required(),
username: Joi.string().required(),
password: Joi.string().required(),
})
.unknown(),
}),
async function (req, res) {
let sameName = await PersonnelModel.getWithName(req.body.username);
if (!sameName || sameName.id === req.body.id) {
const hashedPassword = await bcrypt.hash(req.body.password, 10);
req.body.password = hashedPassword;
let personnel = await PersonnelModel.update(req.body);
if (personnel) {
delete personnel.password;
res.send(personnel);
} else {
res.status(404).send();
}
} else {
res.status(404).send("Username already exists");
}
}
);
router.get("/:id", async function (req, res) {
let personnel = await PersonnelModel.getWithID(parseInt(req.params.id));
if (personnel) {
delete personnel.password;
res.send(personnel);
} else {
res.status(404).send();
}
});
router.delete("/:id", async function (req, res) {
if (await PersonnelModel.delete(parseInt(req.params.id))) {
res.send({ id: parseInt(req.params.id) });
} else {
res.status(404).send();
}
});
module.exports = router;
var express = require("express");
var router = express.Router();
const fs = require("fs");
router.get("", async function (req, res) {
let result = [];
let json = fs.readFileSync("./config/bat_info.oemc");
const obj = JSON.parse(json);
obj.rooms.features.forEach((element) =>
result.push({
type: element.properties.room_type,
name: element.properties.room_name,
})
);
res.send(result);
});
module.exports = router;
DB_URL=ignite
DB_USER=ignite
DB_PASSWORD=oemcs2
DEFAULT_USER=admin
DEFAULT_PASSWORD=admin
JWT_SECRET=D94AD7C66DA6FE86FD91D478DF2AC
\ No newline at end of file
const cluster = require("cluster");
const os = require("os");
const runExpressServer = require("./index");
// Check if current process is master.
if (cluster.isMaster) {
// Get total CPU cores.
const cpuCount = os.cpus().length;
// Spawn a worker for every core.
for (let j = 0; j < cpuCount; j++) {
cluster.fork();
}
} else {
// This is not the master process, so we spawn the express server.
runExpressServer();
}
// Cluster API has a variety of events.
// Here we are creating a new process if a worker die.
cluster.on("exit", function (worker) {
console.log(`Worker ${worker.id} died'`);
console.log(`Starting a new one...`);
cluster.fork();
});
{
"meters_per_pixels": 0.04051724110732491,
"scales": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
102.00747,
55.305255
],
[
282.671301,
55.305255
]
]
},
"properties": {
"meters": 7.32
}
}
]
},
"balises": {
"type": "FeatureCollection",
"features": []
},
"doors": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
286.440252,
133.388081
],
[
287.095721,
161.901012
]
]
},
"properties": {
"exit_1": [
262.84334315648533,
146.82520914476987
],
"exit_2": [
315.280917851046,
147.80841367029288
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
240.229639,
184.514716
],
[
265.792957,
184.514716
]
]
},
"properties": {
"exit_1": [
254.64997211046023,
155.01858019079498
],
"exit_2": [
253.66676758493722,
203.19560194142258
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
97.992718,
181.565102
],
[
123.228301,
181.565102
]
]
},
"properties": {
"exit_1": [
109.13570233305438,
151.08576208870292
],
"exit_2": [
110.11890685857739,
197.9518444719665
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
294.633623,
185.825655
],
[
323.474289,
185.825655
]
]
},
"properties": {
"exit_1": [
310.36489522343095,
157.31272408368199
],
"exit_2": [
311.02036490711293,
201.88466257405855
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
281.524229,
184.842451
],
[
281.524229,
222.531958
]
]
},
"properties": {
"exit_1": [
260.2214644217573,
202.86786709958156
],
"exit_2": [
314.297713325523,
206.47295035983262
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
441.131097,
182.876042
],
[
466.36668,
182.876042
]
]
},
"properties": {
"exit_1": [
455.5514301589958,
155.34631503263597
],
"exit_2": [
452.27408174058576,
207.12842004351464
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
473.904581,
184.842451
],
[
496.190551,
185.825655
]
]
},
"properties": {
"exit_1": [
486.03077045020916,
151.08576208870292
],
"exit_2": [
487.9971795012552,
198.93504899748953
]
}
},
{
"type": "Feature",
"geometry": {