This commit is contained in:
@ -1,7 +1,5 @@
|
||||
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';
|
||||
@ -20,50 +18,50 @@ module.exports = (fastify, opts, done) => {
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/:id', (req, reply) => {
|
||||
fastify.get('/:id', async (req, reply) => {
|
||||
if(req.params.id == undefined){
|
||||
reply.code(400).send({error:"No ID query parameter"});
|
||||
} else {
|
||||
fastify.level.get(req.params.id, (err, val) => {
|
||||
if(err){
|
||||
console.warn(err);
|
||||
reply.send({name:"New Journey", main:[]});
|
||||
} else {
|
||||
reply.send(JSON.parse(val));
|
||||
}
|
||||
});
|
||||
return reply.code(400).send({error:"No ID query parameter"});
|
||||
}
|
||||
|
||||
return fastify.level.db.get(req.params.id, (err, val) => {
|
||||
if(err){
|
||||
console.warn(err);
|
||||
reply.send({name:"New Journey", main:[]});
|
||||
} else {
|
||||
reply.send(JSON.parse(val));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
fastify.post('/:id', (req, reply) => {
|
||||
fastify.post('/:id', async (req, reply) => {
|
||||
if(req.params.id == undefined){
|
||||
reply.code(400).send({error:"No ID query parameter"});
|
||||
} else {
|
||||
fastify.level.put(req.params.id, JSON.stringify(req.body), (err) => {
|
||||
if(err){
|
||||
console.warn(err);
|
||||
reply.code(500).send({error:"Error with DB"});
|
||||
} else {
|
||||
reply.send({content:"ok"});
|
||||
}
|
||||
});
|
||||
return reply.code(400).send({error:"No ID query parameter"});
|
||||
}
|
||||
|
||||
return fastify.level.db.put(req.params.id, JSON.stringify(req.body), (err) => {
|
||||
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 {
|
||||
fastify.level.delete(req.params.id,(err) => {
|
||||
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 {
|
||||
// fastify.level.delete(req.params.id,(err) => {
|
||||
// if(err){
|
||||
// console.warn(err);
|
||||
// reply.code(500).send({error:"Error with DB"});
|
||||
// } else {
|
||||
// reply.send({content:"ok"});
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user