2021-07-16 09:12:30 +02:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = (fastify, opts, done) => {
|
|
|
|
fastify.get('/flight/:id', async (req,reply) => {
|
|
|
|
const ENDPOINT = 'https://www.flightradar24.com/v1/search/web/find';
|
|
|
|
const FORMAT = '-';
|
|
|
|
if(req.params.id){
|
|
|
|
axios.get(ENDPOINT,{
|
|
|
|
params: {
|
|
|
|
format: FORMAT,
|
|
|
|
query: req.params.id,
|
|
|
|
limit:16,
|
|
|
|
type: 'schedule'
|
|
|
|
}
|
|
|
|
}).then(res=>{reply.send(res.data)});
|
|
|
|
}else{
|
|
|
|
reply.send([]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.get('/:id', (req, reply) => {
|
|
|
|
if(req.params.id == undefined){
|
|
|
|
reply.code(400).send({error:"No ID query parameter"});
|
|
|
|
} else {
|
2021-07-16 11:58:43 +02:00
|
|
|
fastify.level.get(req.params.id, (err, val) => {
|
2021-07-16 09:12:30 +02:00
|
|
|
if(err){
|
|
|
|
console.warn(err);
|
|
|
|
reply.send({name:"New Journey", main:[]});
|
|
|
|
} else {
|
|
|
|
reply.send(JSON.parse(val));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.post('/:id', (req, reply) => {
|
|
|
|
if(req.params.id == undefined){
|
|
|
|
reply.code(400).send({error:"No ID query parameter"});
|
|
|
|
} else {
|
2021-07-16 11:58:43 +02:00
|
|
|
fastify.level.put(req.params.id, JSON.stringify(req.body), (err) => {
|
2021-07-16 09:12:30 +02:00
|
|
|
if(err){
|
|
|
|
console.warn(err);
|
|
|
|
reply.code(500).send({error:"Error with DB"});
|
|
|
|
} else {
|
|
|
|
reply.send({content:"ok"});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.delete('/:id',(req, reply) => {
|
|
|
|
if(req.params.id == undefined){
|
|
|
|
reply.code(400).send({error:"No ID query parameter"});
|
|
|
|
} else {
|
2021-07-16 11:58:43 +02:00
|
|
|
fastify.level.delete(req.params.id,(err) => {
|
2021-07-16 09:12:30 +02:00
|
|
|
if(err){
|
|
|
|
console.warn(err);
|
|
|
|
reply.code(500).send({error:"Error with DB"});
|
|
|
|
} else {
|
|
|
|
reply.send({content:"ok"});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
};
|