Skip to content
Open

a #8

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f3ae1c3
Merge pull request #4 from advanced-computer-lab/Marwan
Ahmedlokma Nov 7, 2021
965c6b5
Testing and adding links to componets and adding new function in user…
Ahmedlokma Nov 7, 2021
6fb3bd8
Merge pull request #5 from advanced-computer-lab/Lokma
Ahmedlokma Nov 7, 2021
7344810
Sprint_2_intial
Ahmedlokma Nov 23, 2021
ed97c2e
Sprint_2
Ahmedlokma Dec 5, 2021
a2b4049
Merge pull request #6 from advanced-computer-lab/Lokma
Ahmedlokma Dec 5, 2021
fb3b4a1
sprint_2
Ahmedlokma Dec 5, 2021
469ee40
sprint_2\
Ahmedlokma Dec 5, 2021
f83d1fa
Merge pull request #7 from advanced-computer-lab/Lokma
Ahmedlokma Dec 5, 2021
6fa8c11
sprint_3 fist commit
Ahmedlokma Dec 23, 2021
3e63d72
sprint_3 second commit
Ahmedlokma Dec 23, 2021
9ab87ea
sprin_3 third commit
Ahmedlokma Dec 24, 2021
10a347d
sprint_3 4th commit
Ahmedlokma Dec 24, 2021
f4f5a68
sprint3 _ 4th commit
Ahmedlokma Dec 24, 2021
5999f26
sprint 3 5th_commit
Ahmedlokma Dec 24, 2021
c0bdd0c
sprint3_fifthcommit
Ahmedlokma Dec 25, 2021
0ee3d1d
sprin3_6th commit
Ahmedlokma Dec 25, 2021
5d62e07
sprint3 7th commit
Ahmedlokma Dec 25, 2021
55f97f3
sprint3 8th commit
Ahmedlokma Dec 25, 2021
6cf2085
sprint3 8th_commit
Ahmedlokma Dec 25, 2021
f5cc38c
jnkj
Ahmedlokma Dec 25, 2021
9e152f5
sprint3 9th commit
Ahmedlokma Dec 25, 2021
133fe95
sprint3 10th commit
Ahmedlokma Dec 25, 2021
f6c6f93
Merge pull request #10 from advanced-computer-lab/Lokma
Ahmedlokma Dec 25, 2021
a73a51b
jknjknrc
Ahmedlokma Dec 25, 2021
d1e993a
Merge pull request #11 from advanced-computer-lab/Lokma
Ahmedlokma Dec 25, 2021
7f646ca
Add files via upload
Ahmedlokma Dec 25, 2021
08bf76c
sprint3
MarwanBadr2274 Dec 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ACL_Task2
<!-- # ACL_Task2
# Testing
### - After Cloning the repo, open the source directory.
```
Expand All @@ -9,7 +9,9 @@ cd client
```
npm start
```
### In case of any missing libraries.
- please fix and install everything before coming.
### In case of any missing libraries.
- please fix and install everything before coming.

### - Click here to check [Go](http://localhost:3000/)to run
### - Click here to check [Go](http://localhost:3000/)to run -->

Icons
Binary file added Readme (icons).pdf
Binary file not shown.
1,269 changes: 1,269 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@
},
"homepage": "https://github.com/ahmedalaaseif/ACL_Tasks#readme",
"dependencies": {
"@emotion/styled": "^11.6.0",
"@material-ui/core": "^4.12.3",
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"mongoose": "^6.0.11"
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.11",
"nodemailer": "^6.7.1",
"nodemailer-smtp-transport": "^2.7.4",
"react-seat-picker": "^1.5.3",
"react-tooltip": "^4.2.21"
}
}
12 changes: 8 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const express = require("express");
const mongoose = require('mongoose');
const flightRoutes = require('./Routes/flightRoute');
const userRoutes = require('./Routes/userRoute');
const nodemailer = require('nodemailer');
const cors = require('cors')
require('dotenv').config();
const app = express();
const port = process.env.PORT || "8000";
const smtpTransport = require('nodemailer-smtp-transport');


const MongoURI = 'mongodb+srv://test123:[email protected]/AdvancedComputerLab?retryWrites=true&w=majority' ;

const MongoURI = process.env.MONGOLAB_URI ;


mongoose.connect(MongoURI, { useNewUrlParser: true, useUnifiedTopology: true })
Expand All @@ -19,10 +21,12 @@ app.use(cors())




app.use('/user',userRoutes);
app.use('/admin',flightRoutes);




app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
});
236 changes: 180 additions & 56 deletions src/Controller/flightsController.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
const Flights = require('../Models/flights');
//create , serach , edit , delete , show all //
var temp ;

//CREATE FLIGHT //
const flight_create = async (req, res) => {
var temp1 = Number(req.body.Number_of_Economy_Seats)
var temp2 = Number(req.body.Number_of_Business_Class_Seats)
const rows = []
const rows2 = []
var x = []
var x2 = []
var l =0;
var n=0;
var ll =0;
var nn=0;
var j = 1;
var jj=1;

for(var i = 1 ; i <= temp1 ;i++){
n++;
if(l==2){
i--;
x.push(null)
l=0;
continue ;
}

x.push({id:i,number:j,isSelected:false,isReserved:false})


//CREATE FLIGHT //
const flight_create = (req, res) => {
console.log(req.body)
const flights= new Flights({
j++;
l++;
if(n==8){
j=1;
rows.push(x);
x = []
n=0;
l=0;
}
}
if(x.length >0){
rows.push(x);
}
for(var i = 1 ; i <= temp2 ;i++){
nn++;
if(ll==2){
i--;
x2.push(null)
ll=0;
continue ;
}

x2.push({id:i,number:jj,isSelected:false,isReserved:false})


jj++;
ll++;
if(nn==8){
jj=1;
rows2.push(x2);
x2 = []
nn=0;
ll=0;
}
}
if(x2.length >0){
rows2.push(x2);
}


//------------------------------------------------------------------------------------------------------//
const flights = await new Flights({

Flight_number: req.body.Flight_number,
Departure_time: (req.body.Departure_time),
Expand All @@ -17,14 +80,29 @@ const flight_create = (req, res) => {
Arrival_airport: req.body.Arrival_airport,
Departure_airport: req.body.Departure_airport,
Departure_date: Date.parse(req.body.Departure_date),
Arrival_date: Date.parse(req.body.Arrival_date)

Arrival_date: Date.parse(req.body.Arrival_date),
Economy_price :req.body.Economy_price,
Baggage_allowance :req.body.Baggage_allowance,
Bussiness_price :req.body.Bussiness_price,
Availlable_Number_of_Business_Class_Seats: Number(req.body.Number_of_Business_Class_Seats),
Availlable_Number_of_Economy_Seats: Number(req.body.Number_of_Economy_Seats),
flight_duration :'2:30',
Seats_Bussiness:rows2,
Seats_Economy:rows

} )

flights.save()
.then(result => {
res.send(result);


//____________________________________________________________________________________________________________________//




res.send(result)
res.status(200)
})
.catch(err => {
console.log(err);
Expand All @@ -34,79 +112,125 @@ const flight_create = (req, res) => {
});
}




//SEARCH FOR SPECIFIC FLIGHT //
const flight_find = (req, res) => {
Flights.find({ Flight_number: req.body.Flight_number,
Departure_time: (req.params.Departure_time),
Arrival_time:(req.params.Arrival_time),
Arrival_airport: req.body.Arrival_airport ,
Departure_airport: req.body.Departure_time ,
Departure_date: Date.parse(req.params.Departure_date),
Arrival_date: Date.parse(req.params.Arrival_date)
}).then(result => {
// res.send(result)
console.log(result)

if(req.body.Number_of_Business_Class_Seats ==''){
delete req.body.Number_of_Business_Class_Seats
}
if(req.body.Number_of_Economy_Seats ==''){
delete req.body.Number_of_Economy_Seats
}
if(req.body.Flight_number ==''){
delete req.body.Flight_number
}
if(req.body.Arrival_date==''){
delete req.body.Arrival_date
}
if(req.body.Arrival_time==''){
delete req.body.Arrival_time
}
if(req.body.Departure_airport==''){
delete req.body.Departure_airport
}
if(req.body.Arrival_airport==''){
delete req.body.Arrival_airport
}
if(req.body.Departure_time==''){
delete req.body.Departure_time
}
if(req.body.Departure_date==''){
delete req.body.Departure_date
}

Flights.find(req.body)









.then(result => {
res.send(result)
res.status(200)
console.log(result)
console.log(req.body)
temp = result ;
})
.catch(err => {
console.log(err)

});
}
// SHOW ALL AVAILLABLE FLIGHTS//
const flight_findall = (req, res) => {
Flights.find().then(result => {
res.send(result)
res.status(200)
})
.catch(err => {
console.log(err)
});
}



const update_flight = (req, res) => {
try{

Flights.findByIdAndUpdate( req.params.id,req.body).then(result => {

res.send("Your Flight was updated successfully!")
console.log("updated")
})



}
catch(error){
res.send(error);
console.log(error);
}
}
const flight_findall2 = ( req,res) => {

///Delete Flight
const delete_flight = (req, res) => {
try{

Flights.findByIdAndDelete(req.params.id).then(result => {
console.log("deleted")
})

}
catch(error){
res.send(error);
console.log(error);
}
}
res.send(temp);
}


//update flight //
const update_flight = (req,res)=>{
Flights.findByIdAndUpdate(req.params.id,req.body).then(result =>{

// res.send(result)
res.status(200).send("flight updated ");
console.log('The flight is Updated successfully !' );
}).catch(err => {
console.log(err);

});

};

//Deleting an existing flight //
const delete_flight = (req,res)=>{
Flights.findByIdAndRemove(req.params.id).then(result =>{

res.status(200).send("flight Deleted ");
console.log("The flight is deleted successfully !");
}).catch(err => {
console.log(err);
});

};

const flight_info = (req,res) =>{
Flights.findById(req.params.id).then(result =>{
res.send(result)
res.status(200)
}).catch(err =>{
console.log(err);
});
};


module.exports = {
flight_create,
flight_find,

flight_findall,
delete_flight,
update_flight,
delete_flight




flight_info,
flight_findall2
// Adjust_seats

}

Loading