Index Js (Front)
Index Js (Front)
const {
User,
Company,
College,
Candidate,
SkillTest,
CareerObjective,
CoverLetter,
MockInterview,
Vacancy,
State,
City,
Qualification,
Industry,
Courses
} = require("../../models");
const bcrypt = require("bcryptjs");
const router = express.Router();
const {
bucketName,
accessKeyId,
secretAccessKey,
region,
mimetypes,
bucketURL
} = require("../../../config");
const CompanyExecutive = require("../../models/companyExecutive");
const collegeRepresentative = require("../../models/collegeRepresentative");
const { generatePassword, sendMail } = require("../../../helpers");
const { Translate } = require('@google-cloud/translate').v2;
const { translateProjectId, translateKey } = require('../../../config')
rePath = res.render(`${req.vPath}/front`, {
recentJobs, allQualification, allIndustry, allStates, data,
totalPages, page,
});
} catch (err) {
const ipAddress = req.header('x-forwarded-for') ||
req.socket.remoteAddress;
console.log('======================> 1', ipAddress, req.user?.mobile,
req.user?.name, err)
req.flash("error", err.message || "Something went wrong!");
// return res.redirect("back");
}
});
});
});
rePath = res.render(`${req.vPath}/front/jobsearch`, {
});
});
router.post("/jobsearch", (req, res) => {
const {body}=req.body;
rePath = res.render(`${req.vPath}/front/jobsearch`, {
});
});
router.get("/courses", async (req, res) => {
let filter = { status: true}
const countJobs = await Courses.find(filter).countDocuments()
const perPage = 9;
const p = parseInt(req.query.page);
const page = p || 1;
const totalPages = Math.ceil(countJobs / perPage);
let courses = await Courses.find(filter).sort({ createdAt: -
1 }).skip(perPage * page - perPage).limit(perPage)
rePath = res.render(`${req.vPath}/front/courses`, {
courses,
totalPages,
page
});
});
router.get("/coursedetails/:id", async(req, res) => {
const {id}=req.params
let course=await Courses.findOne({_id:id})
rePath = res.render(`${req.vPath}/front/coursedetails`, {
course
});
});
router.get("/contact", (req, res) => {
rePath = res.render(`${req.vPath}/front/contact`, {
});
});
router.get("/contactt", (req, res) => {
rePath = res.render(`${req.vPath}/front/contactUs`, {
});
});
router.get("/sampleVideoProfile", (req, res) => {
rePath = res.render(`${req.vPath}/front/sampleVideoProfile`, {
});
});
router.get("/coursedetailmore", (req, res) => {
console.log('=========== reached')
rePath = res.render(`${req.vPath}/front/coursedetailmore`, {
});
});
router.get("/jobdetailsmore/:jobId", async(req, res) => {
try{
console.log('=======================> reached here')
let jobId = req.params.jobId
if (jobId && !ObjectId.isValid(jobId)) {
throw req.ykError("Invalid Job Id");
}
const populate = [
{
path: '_company',
select: "name logo stateId cityId mediaGallery
mediaGalaryVideo"
},
{
path: "_industry",
select: "name",
},
{
path: "_jobCategory",
select: "name",
},
{
path: "_qualification",
select: "name",
},
{
path: "state",
select: "name",
},
{
path: "city",
select: "name",
},
{
path: "_techSkills",
select: "name",
},
{
path: "_nonTechSkills",
select: "name",
},
];
const job = await Vacancy.findOne({ _id:
jobId }).populate(populate)
let state = '';
let city = '';
if (job._company?.stateId && job._company?.cityId) {
state = await State.findOne({ _id: job._company.stateId,
status: true })
city = await City.findOne({ _id: job._company.cityId,
status: true, stateId: job._company.stateId })
}
const recentJobs = await Vacancy.find({ status: true, _id: { $ne:
jobId } }).populate([
{
path: '_company',
select: "name logo"
},
{
path: "city",
select: "name",
}]).sort({ createdAt: -1 }).limit(5)
rePath = res.render(`${req.vPath}/front/jobdetailmore`, {
job, recentJobs, state, city
});
}catch(err){
console.log(err,'err>>>>>>>>>>>>')
}
});
router.get("/contact", (req, res) => {
rePath = res.render(`${req.vPath}/front/contact`, {
});
});
router.get("/jobdetails/:jobId", async (req, res) => {
try {
let jobId = req.params.jobId //63d8cb2e421777708eaed0d8
if (jobId && !ObjectId.isValid(jobId)) {
throw req.ykError("Invalid Job Id");
}
const populate = [
{
path: '_company',
select: "name logo stateId cityId mediaGallery
mediaGalaryVideo"
},
{
path: "_industry",
select: "name",
},
{
path: "_jobCategory",
select: "name",
},
{
path: "_qualification",
select: "name",
},
{
path: "state",
select: "name",
},
{
path: "city",
select: "name",
},
{
path: "_techSkills",
select: "name",
},
{
path: "_nonTechSkills",
select: "name",
},
];
const job = await Vacancy.findOne({ _id: jobId }).populate(populate)
let state = '';
let city = '';
if (job._company?.stateId && job._company?.cityId) {
state = await State.findOne({ _id: job._company.stateId, status:
true })
city = await City.findOne({ _id: job._company.cityId, status:
true, stateId: job._company.stateId })
}
const recentJobs = await Vacancy.find({ status: true, _id: { $ne: jobId
} }).populate([
{
path
: '_company',
select: "name logo"
},
{
path: "city",
select: "name",
}]).sort({ createdAt: -1 }).limit(5)
if (!user.validPassword(req.body.password))
throw req.ykError("Enter a valid password");
if (user) {
if (user.role === 10 || user.role === 0) {
let userData = { role: user.role, name: user.name,
_id: user._id, email: user.email }
req.session.user = userData;
return res.redirect("/admin");
}
}
} catch (err) {
req.flash("error", err.message || "Something went wrong!");
return res.redirect("back");
}
});
if (req.body.model == "company") {
const user0 = await CompanyExecutive.updateMany(
{ _company: data._id },
updata
);
}
if (req.body.model == "college") {
// console.log("innn", data);
const user1 = await collegeRepresentative.updateMany(
{
_college: data._id,
},
updata
);
}
//console.log(user1, "seconndddd");
}
return res.send(data);
} catch (err) {
req.flash("error", "Something went wrong!");
return res.redirect("back");
}
});
if (req.body.model == "company") {
// console.log("data.id = ", data._id);
const user3 = await Company.findOneAndDelete({ _id:
req.body.id });
}
if (req.body.model == "candidate") {
// console.log("data.id = ", data._id);
const user3 = await Candidate.findOneAndDelete({ _id: req.body.id
});
}
if (req.body.model == "skillTest") {
// console.log("data.id = ", data._id);
const user3 = await SkillTest.findOneAndDelete({ _id: req.body.id
});
}
if (req.body.model == "careerObjective") {
// console.log("data.id = ", data._id);
const user3 = await CareerObjective.findOneAndDelete({
_id: req.body.id,
});
}
if (req.body.model == "coverLetter") {
// console.log("data.id = ", data._id);
const user3 = await CoverLetter.findOneAndDelete({ _id:
req.body.id });
}
if (req.body.model == "mockInterview") {
// console.log("data.id = ", data._id);
const user3 = await MockInterview.findOneAndDelete({
_id: req.body.id,
});
}
if (req.body.model == "vacancy") {
// console.log("data.id = ", data._id);
const user3 = await Vacancy.findOneAndDelete({ _id:
req.body.id });
}
return res.send(data);
} catch (err) {
req.flash("error", "Something went wrong!");
return res.redirect("back");
}
});
//forget password
router
.route("/admin/forgotpassword")
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/forPass`);
return rePath;
})
.post(async (req, res) => {
try {
const email = req.body.email;
const tempPassword = await generatePassword();
const userData = await User.findOne({ email: email });
if (!userData)
throw req.ykError(
"Invalid email, please enter your registered email"
);
<p style="line-height:32px;font-size:18px!important;font-
family:'Manrope',sans-serif!important">
Hi ${userData.name},<br/><br/>
<p style="line-height:32px;font-size:18px!important;font-
family:'Manrope',sans-serif!important">
Thank you,<br/>
</p>
</td>
</tr>
<tr>
<td style="font-family:
'manrope',sans-serif!important;text-align:left">
<ul style="list-style-
type: none;padding-left: 0px;margin: 20px 50px!important;">
<li style="padding-
top:0px">
<span
style="line-height:32px;font-size:18px!important;font-family:'Manrope',sans-serif!
important">
Sincerely,
<br/> Focalyt Group
</span>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
`;
req.flash(
"success",
"Your new password has been sent to your registered email.
Please check your email."
);
res.redirect("/admin/forgotpassword");
} catch (err) {
req.flash("error", err.message || "Something went wrong!");
return res.redirect("back");
}
});
//change password
router
.route("/admin/changepassword")
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/admin/setting/changePass`, { menu:
'dashboard' });
// rePath = res.render(`${req.vPath}/front/login`);
return rePath;
})
.post(async (req, res) => {
try {
const newpassword = req.body.newpassword;
const oldpassword = req.body.oldpassword;
const confirmpassword = req.body.confirmpassword;
if (!bcrypt.compareSync(oldpassword, userData.password)) {
throw req.ykError("Old password is incorrect!");
}
//edit profile
router
.route("/admin/editprofile")
.get(async (req, res) => {
var user = req.session.user;
rePath = res.render(`${req.vPath}/admin/setting/editProfile`, {
user,
menu: 'dashboard'
});
// rePath = res.render(`${req.vPath}/front/login`);
return rePath;
})
.post(async (req, res) => {
try {
const email = req.body.email;
const name = req.body.name;
var id = req.session.user._id;
router.route('/about')
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/about`, {
});
})
router.route('/about-us')
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/aboutUs`, {
});
})
router.route('/termsandconditions')
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/termsAndConditions`, {
});
})
router.route('/privacy-policy')
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/privacyPolicy`, {
});
})
router.route('/return-and-refund-policy')
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/returnAndRefundPolicy`, {
});
})
router.route('/contact-us')
.get(async (req, res) => {
rePath = res.render(`${req.vPath}/front/contactUs`, {
});
})
router.route('/signs')
.get(async (req, res) => {
res.setHeader('X-FRAME-OPTIONS', 'ALLOW-FROM *');
res.setHeader('Content-Security-Policy', "frame-ancestors *");
rePath = res.render(`${req.vPath}/front/signs`, {
});
})
router.route('/signConverter')
.get(async (req, res) => {
res.setHeader('X-FRAME-OPTIONS', 'ALLOW-FROM *');
res.setHeader('Content-Security-Policy', "frame-ancestors *");
rePath = res.render(`${req.vPath}/front/signConverter`, {
});
})
router.route('/voice')
.get(async (req, res) => {
res.setHeader('X-FRAME-OPTIONS', 'ALLOW-FROM *');
res.setHeader('Content-Security-Policy', "frame-ancestors *");
rePath = res.render(`${req.vPath}/front/voice`, {
});
})
router.route('/translate')
.post(async (req, res) => {
res.setHeader('X-FRAME-OPTIONS', 'ALLOW-FROM *');
res.setHeader('Content-Security-Policy', "frame-ancestors *");
const lang = req.body.lang ? req.body.lang : 'hi'
const message = req.body.message?.toLowerCase();
console.log('I received this message ', message)
const translate = new Translate({ projectId: translateProjectId, key:
translateKey });
})
router.route('/parser')
.get(async (req, res) => {
res.setHeader('X-FRAME-OPTIONS', 'ALLOW-FROM *');
res.setHeader('Content-Security-Policy', "frame-ancestors *");
rePath = res.render(`${req.vPath}/front/parser`, {
});
})
module.exports = router;