Skip to content

Commit

Permalink
Resolved conflits
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawan-Kushwah committed Oct 11, 2024
2 parents 4a0c1e1 + e9ab9c5 commit 97aa9f3
Show file tree
Hide file tree
Showing 25 changed files with 1,327 additions and 950 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Greetings

on: [pull_request_target, issues]

jobs:
greeting:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: "👋 Thank you @${{ github.actor }} for raising an issue! We appreciate your effort in helping us improve. Our team will review it shortly. Stay tuned!"
pr-message: " 🎉 Thank you @${{ github.actor }} for your contribution! Your pull request has been submitted successfully. A maintainer will review it as soon as possible. We appreciate your support in making this project better"
189 changes: 189 additions & 0 deletions hiring-portal/Backend/controllers/applicationController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
const Job = require("../models/Job");
const User = require("../models/User");
const Application = require("../models/Application");




exports.deleteApplication= async (req, res) => {
const applicationId = req.params.id;

try {
const deletedApplication = await Application.findByIdAndDelete(
applicationId
);

if (!deletedApplication) {
return res.status(404).json({ message: "Application not found" });
}
console.log("appplication deleted");
res.status(200).json({ message: "Application deleted successfully" });
} catch (error) {
console.error("Error deleting application:", error);
res.status(500).json({ message: "Server error" });
}
};

exports.postApplication=async (req, res) => {
console.log("Got request");

try {
const {
resume,
cv,
mobileNumber,
email,
firstName,
lastName,
gender,
instituteName,
course,
graduatingYear,
courseDuration,
countryOfResidence,
education,
experience,
skills,
jobId,
emailcurrent,
} = req.body;

if (
!resume ||
!mobileNumber ||
!email ||
!firstName ||
!gender ||
!instituteName ||
!course ||
!graduatingYear ||
!courseDuration ||
!countryOfResidence
) {
return res
.status(400)
.json({ message: "Please fill all required fields." });
}

console.log(emailcurrent);
const applicant = await User.findOne({ email: emailcurrent });

if (!applicant) {
return res.status(404).json({ message: "Applicant not found." });
}

const applicantId = applicant._id;

const newApplication = new Application({
resume,
cv,
mobileNumber,
email,
firstName,
lastName,
gender,
instituteName,
course,
graduatingYear,
courseDuration,
countryOfResidence,
education,
experience,
skills,
jobId,
applicantId,
});

const savedApplication = await newApplication.save();

// Setup email transport
const transporter = nodemailer.createTransport({
service: "gmail", // Updated to use 'gmail' service instead of 'host'
auth: {
user: "[email protected]",
pass: "frtkmvbebchjfile",
},
});

const job = await Job.findById(jobId);
const jobTitle = job.title;

const mailOptions = {
from: "[email protected]",
to: emailcurrent,
subject: "Job Application Confirmation",
text: `Dear ${firstName} ${lastName},\n\nYour application for the job "${jobTitle}" has been successfully submitted.\n\nThank you for applying!\n\nBest regards,\nYour Company Name`,
};

// Send email and handle response accordingly
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error("Error sending email:", error);
// Even though email fails, the application is already saved, so you might want to notify the client but still return success for the application submission
return res.status(201).json({
message:
"Application submitted successfully, but failed to send confirmation email.",
application: savedApplication,
emailError: error.message,
});
} else {
console.log("Email sent: " + info.response);
return res.status(201).json({
message:
"Application submitted successfully and confirmation email sent.",
application: savedApplication,
});
}
});
} catch (error) {
console.error("Error submitting application:", error);
return res
.status(500)
.json({ message: "Failed to submit application.", error });
}
};

exports.getSingleApplication=async (req, res) => {
const { jobId } = req.params;

try {
const applications = await Application.find({ jobId }).populate(
"applicantId",
"name email profileDetails"
);

if (!applications || applications.length === 0) {
return res
.status(404)
.json({ message: "No applications found for this job" });
}

res.json(applications);
} catch (error) {
console.error("Error fetching applications:", error);
res.status(500).json({ message: "Server error" });
}
};

exports.getApplicant=async (req, res) => {
try {
const { applicantId } = req.params;
console.log(applicantId);
const applications = await Application.find({ applicantId })
.populate("jobId")
.exec();
console.log(applications);
if (applications && applications.length > 0) {
res.status(200).json(applications);
} else {
res.status(200).json([]);
}
} catch (error) {
console.error(error);
res.status(500).json({ message: "Server error" });
}
};




88 changes: 88 additions & 0 deletions hiring-portal/Backend/controllers/assessmentController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

const Job = require("../models/Job");
const Assessment = require("../models/Assesment");
const Application = require("../models/Application");

exports.getAssessment=async (req, res) => {
const { jobId } = req.params;
try {
const assessments = await Assessment.find({ jobId });

if (assessments.length === 0) {
return res
.status(404)
.json({ message: "No assessments found for this job" });
}

res.status(200).json(assessments);
} catch (error) {
console.error("Error fetching assessments:", error);
res.status(500).json({ message: "Server error. Please try again later." });
}
};

exports.getSingleAssessment=async (req, res) => {
try {
const assessment = await Assessment.findById(req.params.id);
console.log(assessment);
if (!assessment) {
return res.status(404).json({ message: "Assessment not found" });
}
res.json(assessment);
} catch (error) {
res.status(500).json({ message: "Server Error" });
}
};

exports.postAssessment=async (req, res) => {
const { jobId, assessmentId } = req.body;

try {
const job = await Job.findById(jobId);
const assessment = await Assessment.findById(assessmentId);
const applications = await Application.find({ jobId });

const jobTitle = job.title;
const startTime = new Date(assessment.startTime).toLocaleString();
const endTime = new Date(assessment.endTime).toLocaleString();
const assessmentLink = `http://localhost:3000/code/${assessmentId}`;

for (const application of applications) {
const email = application.email;
console.log("Email:", email);
console.log("Job Title:", jobTitle);
console.log("Start Time:", startTime);
console.log("End Time:", endTime);
console.log("Assessment Link:", assessmentLink);
const mailOptions = {
from: "[email protected]",
to: email,
subject: `Assessment for ${jobTitle} - ${startTime} to ${endTime}`,
text: `Dear Applicant,\n\nYou have an assessment scheduled for the job "${jobTitle}" from ${startTime} to ${endTime}.\n\nPlease complete the assessment using the following link: ${assessmentLink}\n\nBest regards,\nYour Company Name`,
};

await transporter.sendMail(mailOptions);
}
console.log("sended email");
res.status(200).json({ message: "Assessment emails sent successfully." });
} catch (error) {
console.error("Error sending emails:", error);
res
.status(500)
.json({ message: "Error sending emails", error: error.message });
}
};


exports.getAsses=async (req, res) => {
try {
const assessment = await Assessment.findById(req.params.id);
console.log(assessment);
if (!assessment) {
return res.status(404).json({ message: "Assessment not found" });
}
res.json(assessment);
} catch (error) {
res.status(500).json({ message: "Server Error" });
}
};
92 changes: 92 additions & 0 deletions hiring-portal/Backend/controllers/companyController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const User = require("../models/User");
const Company = require("../models/Company");



exports.postCompany=async (req, res) => {
try {
console.log("Received request body:", req.body);

const {
name,
description,
industry,
location,
website,
email,
phone,
establishedYear,
employeesCount,
linkedin,
facebook,
twitter,
ownerEmail,
logo,
} = req.body;

if (!ownerEmail) {
return res.status(400).json({ error: "Owner email is required" });
}

const user = await User.findOneAndUpdate(
{ email: ownerEmail },
{ role: "owner" },
{ new: true }
);

if (!user) {
return res.status(404).json({ error: "User not found" });
}

const newCompany = new Company({
name,
description,
industry,
location,
website,
email,
phone,
logo,
establishedYear,
employeesCount,
socialMediaLinks: {
linkedin,
facebook,
twitter,
},
owner: ownerEmail,
});

const result = await newCompany.save();
console.log("Company saved:", result);

res
.status(201)
.json({ message: "Company registered successfully", company: result });
} catch (error) {
console.error("Error saving company:", error);
res.status(500).json({ message: "Error registering company", error });
}
};

exports.getCompany=async (req, res) => {
try {
const companies = await Company.find();
res.status(200).json(companies);
} catch (error) {
res.status(500).json({ message: "Error fetching companies", error });
}
};

exports.getCompanies=async (req, res) => {
try {
const company = await Company.findById(req.params.id);
if (!company) {
return res.status(404).json({ error: "Company not found" });
}
res.json(company);
} catch (error) {
console.error("Error fetching company:", error);
res.status(500).json({ error: "Server error" });
}
};
Loading

0 comments on commit 97aa9f3

Please sign in to comment.