Skip to content

Commit

Permalink
Sprint 2
Browse files Browse the repository at this point in the history
Sprint 2
  • Loading branch information
arch-linux committed Feb 18, 2024
1 parent 4149264 commit 246b31e
Showing 1 changed file with 63 additions and 31 deletions.
94 changes: 63 additions & 31 deletions routes/externalRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const File = require(__dirname + "./../models/file.model.js").File;
const DebugAPI = require(__dirname + "./../lib/aircraftLookup.js");
const JSONbig = require('json-bigint');
const jwt = require('jsonwebtoken');
const fs = require('fs');


function authenticateToken(req, res, next) {
Expand Down Expand Up @@ -93,20 +94,6 @@ function startExternalRoutes(app, passport) {
}
})

app.post('/api/user/get/assignedaircraft', authenticateToken, async (req, res) => {
const reqUser = await Users.findOne({
where: {
user_id: req.body.user_id
}
});
if (reqUser === null) {
res.send("NULL");
} else {
res.send(reqUser.planes);
}
})


app.post('/api/user/get/byid', authenticateToken, async (req, res) => {
const reqUser = await Users.findOne({
where: {
Expand All @@ -120,7 +107,8 @@ function startExternalRoutes(app, passport) {
}
})

app.post('/api/user/get/newuser', authenticateToken, async (req, res) => {
//ASSIGNED AIRCRAFT
app.post('/api/user/get/assignedaircraft', authenticateToken, async (req, res) => {
const reqUser = await Users.findOne({
where: {
user_id: req.body.user_id
Expand All @@ -129,23 +117,10 @@ function startExternalRoutes(app, passport) {
if (reqUser === null) {
res.send("NULL");
} else {
res.send(reqUser.is_new_user);
res.send(reqUser.planes);
}
})

app.post('/api/user/update/phonenumber', authenticateToken, async (req, res) => {
const reqUser = await Users.update({
phone_number: req.body.phone_number
}, {
where: {
user_id: req.body.user_id
}
});
res.send(reqUser);
})



app.post('/api/user/update/assignedaircraft', authenticateToken, async (req, res) => {
const reqUser = await Users.update({
planes: req.body.planes
Expand All @@ -157,9 +132,9 @@ function startExternalRoutes(app, passport) {
res.send(reqUser);
})

app.post('/api/user/update/noLongernewuser',authenticateToken, async (req, res) => {
app.post('/api/user/delete/assignedaircraft', authenticateToken, async (req, res) => {
const reqUser = await Users.update({
is_new_user: false
planes: null
}, {
where: {
user_id: req.body.user_id
Expand All @@ -168,6 +143,7 @@ function startExternalRoutes(app, passport) {
res.send(reqUser);
})


app.post('/api/user/get/assignedaircraftformatted', authenticateToken, async (req, res) => {
if (req.body.user_id != null) {
try {
Expand Down Expand Up @@ -203,6 +179,44 @@ function startExternalRoutes(app, passport) {
}
});

//END ASSIGNED AIRCRAFT

//NEW USER
app.post('/api/user/get/newuser', authenticateToken, async (req, res) => {
const reqUser = await Users.findOne({
where: {
user_id: req.body.user_id
}
});
if (reqUser === null) {
res.send("NULL");
} else {
res.send(reqUser.is_new_user);
}
})

app.post('/api/user/update/newuser',authenticateToken, async (req, res) => {
const reqUser = await Users.update({
is_new_user: false
}, {
where: {
user_id: req.body.user_id
}
});
res.send(reqUser);
})
// END NEW USER

app.post('/api/user/update/phonenumber', authenticateToken, async (req, res) => {
const reqUser = await Users.update({
phone_number: req.body.phone_number
}, {
where: {
user_id: req.body.user_id
}
});
res.send(reqUser);
})


//AIRCRAFT
Expand Down Expand Up @@ -247,6 +261,8 @@ function startExternalRoutes(app, passport) {
}
});



//END AIRCRAFT


Expand All @@ -259,6 +275,22 @@ function startExternalRoutes(app, passport) {
});
});

app.post('/api/file/delete/uid', authenticateToken, async (req,res) => {
if(req.body.uid){
File.findOne({ where: { uid: req.body.uid }}).then((data) => {
if(data){
fs.unlinkSync(data.full_location).then((data) => {
res.sendStatus(200);
})
} else {
res.sendStatus(404);
}
})
}
});




/* END FILE MANAGMENT */

Expand Down

0 comments on commit 246b31e

Please sign in to comment.