Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b11ebb3
Read requests update
WijesekaraDNM Jun 18, 2024
24209fe
Modifications in request page
WijesekaraDNM Jun 18, 2024
2b7ca7d
Media File Upload Creation in News Page
WijesekaraDNM Jun 20, 2024
b77ec08
Merge branch 'RPrashan99:main' into main
WijesekaraDNM Jun 23, 2024
8ff181d
Request page and News pages are updated
WijesekaraDNM Jun 23, 2024
4cb1bf3
Merge branch 'main' of https://github.com/WijesekaraDNM/Disaster_Mana…
WijesekaraDNM Jun 23, 2024
fbcfbb6
Merge branch 'RPrashan99:main' into main
WijesekaraDNM Jun 23, 2024
252448e
request router minor change
RPrashan99 Jun 25, 2024
7d0082d
disaster report add request
RPrashan99 Jun 25, 2024
a11e5cd
requestWindow is updated
WijesekaraDNM Jun 25, 2024
5afa853
Merge branch 'main' into main
RPrashan99 Jun 25, 2024
489bb81
Merge pull request #16 from WijesekaraDNM/main
RPrashan99 Jun 25, 2024
be2c1ad
Merge branch 'authentication_test' into main
RPrashan99 Jun 25, 2024
1b5393e
check unverify requests
RPrashan99 Jun 25, 2024
ba8fd82
Merge branch 'main' of https://github.com/RPrashan99/Disaster_Managem…
RPrashan99 Jun 25, 2024
6a25f26
get province and new report count show change
RPrashan99 Jun 25, 2024
f90782f
edit report finish
RPrashan99 Jun 25, 2024
e45e883
shelter add form mino changes
RPrashan99 Jun 26, 2024
ff5baa9
minor changes
RPrashan99 Jun 26, 2024
b48f8d4
user count change
RPrashan99 Jun 26, 2024
e94a942
request post change
RPrashan99 Jun 26, 2024
87294c5
request router id change
RPrashan99 Jun 26, 2024
98e2496
email send service
RPrashan99 Jun 26, 2024
2aab481
minor changes
RPrashan99 Jun 26, 2024
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
8 changes: 4 additions & 4 deletions Backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"moment": "^2.30.1",
"mongoose": "^8.0.2",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.9.13"
"nodemailer": "^6.9.14"
},
"devDependencies": {
"nodemon": "^3.0.2"
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/config/database.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const dbconnect = async () => {
console.log('Connected successfully!');

// Watch for changes only after seeding is done
await watchUsers();
//await watchUsers();
} catch (error) {
console.log(error);
}
Expand Down
3 changes: 2 additions & 1 deletion Backend/src/models/disasterRequest.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const DisasterRequestSchema = new Schema(
}
],
default: []},
affectedCount: {type: Number, required: true},
image: {type:[{type:String}], required:false},
affectedCount: {type: String, required: true},
medicalNeed: {type: Boolean, default: false},
otherNeeds: {type: String, required: false},
requestTime: {type: String, required: true},
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/models/news.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const NewsSchema = new Schema(
author: {type: String, required: true},
createdDate: {type: String, required: true},
createdTime: {type: String, required: true},
image: {data: Buffer , contentType: String},
image: {type:String , default:false},
newsBody: {type: String, required: true},
show: {type: Boolean, default:false} //if and only if show is true news are displayed in the user's side
},
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const UserSchema = new Schema(
address: {type: String, default: "none"},
accessLevel: {type: Number, default: 1},
department: {type: String, default: "None"},
telephoneNumber: {type: String, required: true},
telephoneNumber: {type: String, required: false},
lastLogged: {type: Date, default: "2023/10/12"}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Backend/src/routers/maps.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ router.post('/getGeoCode', handler(async(req,res) => {

router.post ('/getProvince',handler( async(req,res) => {
const {location} = req.body;
const apiKey = 'AIzaSyCqnhZFna6jPPizSKO88sNgdYLc3SHAGhk';
const apiKey = process.env.GOOGLEMAP_API;
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(location)},Sri%20Lanka&key=${apiKey}`;

try {
Expand Down
28 changes: 6 additions & 22 deletions Backend/src/routers/news.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const router = Router();
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });

router.post('/createNews', upload.single('image'), handler(async (req, res) => {
router.post('/createNews', handler(async (req, res) => {

const {heading, author, newsBody} = req.body;
const {heading, author, newsBody, image} = req.body;
const currentDateTime = new Date(); //real time
const createdDate = currentDateTime.toDateString();
const createdTime = currentDateTime.toTimeString();
Expand All @@ -24,22 +24,13 @@ router.post('/createNews', upload.single('image'), handler(async (req, res) => {
return res.status(BAD_REQUEST).send("Missing required fields");
}
const newID = await generateNewsId(heading);

let imageData;
let contentType;
if (req.file) {
imageData = req.file.buffer; // Convert image buffer to base64 string
contentType = req.file.mimetype;
}

try {
const newNews = await NewsModel.create({
newsId: newID,
heading,
author,

image : { data: imageData, contentType: contentType },

image,
newsBody,
createdDate,
createdTime,
Expand All @@ -54,24 +45,17 @@ router.post('/createNews', upload.single('image'), handler(async (req, res) => {

}));

router.patch('/updateNews/:newsId', upload.single('image'), handler(async (req, res) => {
router.patch('/updateNews/:newsId', handler(async (req, res) => {
const { newsId } = req.params;
const {heading, author, newsBody, show} = req.body;
const {heading, author, newsBody, show, image} = req.body;
const currentDateTime = new Date(); //real time
const createdDate = currentDateTime.toDateString();
const createdTime = currentDateTime.toTimeString();
// Validate required fields
if (!heading || !author || !newsBody ) {
return res.status(BAD_REQUEST).send("Missing required fields");
}
let updateData = { heading, author, newsBody, show, createdDate, createdTime};

if (req.file) {
updateData.image = {
data: req.file.buffer,
contentType: req.file.mimetype
};
}
let updateData = { heading, author, newsBody, show, createdDate, createdTime, image};
try{
const updatedNews = await NewsModel.findOneAndUpdate(
{ newsId: newsId },
Expand Down
2 changes: 2 additions & 0 deletions Backend/src/routers/report.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ router.post('/addReport', handler(async (req,res) => {
const {disasterType,
severity,
disasterLocation,
disasterRequests,
affectedCount,
affectedLocations,
finished
Expand All @@ -28,6 +29,7 @@ router.post('/addReport', handler(async (req,res) => {
disasterLocation,
affectedCount,
affectedLocations,
disasterRequests,
createdDate: currentDate,
updatedDate: currentDate,
finished: isFinished
Expand Down
47 changes: 30 additions & 17 deletions Backend/src/routers/request.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Router } from "express";
import { BAD_REQUEST, INTERNAL_SERVER_ERROR } from "../constants/httpStatus.js";
import handler from 'express-async-handler';
import { DisasterRequestModel } from "../models/disasterRequest.model.js";
import { DisasterReportModel } from "../models/disasterReport.model.js";

const router = Router();

router.get('/request',handler(async (req,res) => {
router.post('/request',handler(async (req,res) => {

const {
disasterType,
Expand All @@ -16,13 +17,14 @@ router.get('/request',handler(async (req,res) => {
otherNeeds,
disasterLocationLatLan,
read,
requestProvince} = req.body;
image} = req.body;

const currentDateTime = new Date();
const requestDate = currentDateTime.toDateString();
const requestTime = currentDateTime.toTimeString();

const newID = await generateRequestID(disasterType);
const requestProvince = await getRequestProvince(disasterLocationLatLan);

const newRequest = {
requestID: newID,
Expand All @@ -36,7 +38,8 @@ router.get('/request',handler(async (req,res) => {
requestTime,
requestDate,
read,
requestProvince
image,
requestProvince: requestProvince
};

const result = await DisasterRequestModel.create(newRequest);
Expand Down Expand Up @@ -88,9 +91,9 @@ router.put('/updateRequest/:requestID', handler(async (req, res) => {
{ read: true },
{ new: true } // Return the updated document
);
return res.status(INTERNAL_SERVER_ERROR).send(request);
res.status(200).send(request);

} catch (error) {
console.error(error);
return res.status(INTERNAL_SERVER_ERROR).send("Internal server error");
}
}));
Expand Down Expand Up @@ -132,7 +135,6 @@ router.post('/showUnverify', handler(async (req, res) =>{

//not finished
const sendingResponds = async(requests) =>{

try{
const sendTo = "engerrev897@gmail.com";
const sendFrom = process.env.Email_USER;
Expand Down Expand Up @@ -161,26 +163,36 @@ const generateRequestID = async(disasterType) => {

const disasterCode = disasterType.substring(0, 2);
const min = 0;
const max = 100;
const requestNumber = Math.floor(Math.random() * (max - min + 1)) + min;
const max = 1000;
let requestNumber = Math.floor(Math.random() * (max - min + 1)) + min;

const newID = disasterCode + requestNumber.toString();
console.log("ID",newID);
let newID = disasterCode + requestNumber.toString();

try{
while(await DisasterRequestModel.findOne({requestID: newID})){
requestNumber++;
newID = disasterCode + requestNumber.toString();
}
console.log("ID",newID);
return newID;
}catch(error){
console.log("ID generate error");
}

return newID;

};

const getRequestProvince = async (lat, lng) => {
const getRequestProvince = async (locationLat) => {
try{
const url = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${process.env.GOOGLEMAP_API}`;
const url = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${locationLat[0]},${locationLat[1]}&key=${process.env.GOOGLEMAP_API}`;

const response = await axios.get(url);
const results = response.data.results;
const response = await fetch(url);
const data = await response.json();

if (results.length > 0) {
if (data.results.length > 0) {
// Loop through the address components to find the province
for (const component of results[0].address_components) {
for (const component of data.results[0].address_components) {
if (component.types.includes("administrative_area_level_1")) {
return component.long_name; // Return the province name
}
Expand All @@ -191,4 +203,5 @@ const getRequestProvince = async (lat, lng) => {
}
}

export default router
export default router

1 change: 0 additions & 1 deletion Backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dbconnect();

const app = express();


app.use(express.json());

app.use(cors({
Expand Down
Loading