Skip to content

Commit

Permalink
1 change in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
nadunchanna98 committed Jul 27, 2023
1 parent fd09347 commit 422da39
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions Backend/routes/Complains.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,99 @@ router.put('/edit/:complaintId', async (req, res) => {
// }
// });

//Assign Complain to Laborers
//assign complain to supervisor
router.put('/batchUpdate', async (req, res) => {
try {
const complainId = req.body.complainID;
const LaborerIDs = req.body.laborerIds;
console.log('LaborerIDs:', LaborerIDs);
console.log('complainId:', complainId);

const complaint = await Complaine_Details.findById(complainId);

if (!complaint) {
return res.status(404).json({ success: false, message: 'Complaint not found' });
}

// Update the complaint with the assigned user ID
complaint.status = 'AssignedL';
complaint.labourerID=LaborerIDs;


await complaint.save();

// Update the status of selected laborers in the database

try {




for (const id in LaborerIDs) {
const Details = await Labour_Details.findOne({ userID: LaborerIDs[id] });;
Details.complains.push(complainId);
Details.Assigned=true;
await Details.save();
console.log("Details: ",Details);

}



} catch (error) {
console.error('Error updating Labour_Details:', error);
throw error;
}}


catch (error) {
console.log(error);
return res.status(500).json({ success: false, message: 'Internal server error' });
}
});


//Release Labourers
router.put('/batchReleaseUpdate/:complainID', async (req, res) => {
try {
const complainId = req.params.complainID;



const complaint = await Complaine_Details.findById(complainId);
const LaborerIDs = complaint.labourerID;

if (!complaint) {
return res.status(404).json({ success: false, message: 'Complaint not found' });
}

// Update the status of selected laborers in the database

try {

for (const id in LaborerIDs) {
const Details = await Labour_Details.findOne({ userID: LaborerIDs[id] });;
Details.Assigned=false;
await Details.save();
console.log("Details: ",Details);

}



} catch (error) {
console.error('Error updating Labour_Details:', error);
throw error;
}}


catch (error) {
console.log(error);
return res.status(500).json({ success: false, message: 'Internal server error' });
}
});

router.put('/complain/:complaintId', async (req, res) => {
const { complaintId } = req.params;
const updateFields = req.body;
Expand Down

0 comments on commit 422da39

Please sign in to comment.