Skip to content

Commit

Permalink
allotment application flow completed
Browse files Browse the repository at this point in the history
  • Loading branch information
basil-reji committed May 1, 2023
1 parent 971f9bd commit f1beb4d
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 69 deletions.
Binary file removed app.zip
Binary file not shown.
115 changes: 63 additions & 52 deletions controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ const contact = {

const candidate = {

viewResult: (data) => {
viewCanidate: (data) => {
return new Promise(async (resolve, reject) => {

// let data.lpk_id = data.data.lpk_id;
if(data.lpk_id.startsWith(" ")){
if (data.lpk_id.startsWith(" ")) {
data.lpk_id = data.lpk_id.substring(1);
}
if(data.lpk_id.endsWith(" ")){
if (data.lpk_id.endsWith(" ")) {
data.lpk_id = data.lpk_id.substring(0, 8);
}

if (String(data.lpk_id.length) == 8 && data.lpk_id.includes("LPK1")) {
db.get()
.collection(collections.CANDIDATES)
Expand All @@ -43,26 +43,26 @@ const candidate = {
.then((response) => {
// console.log(response)
if (response) {
if(data.email.startsWith(" ")){
if (data.email.startsWith(" ")) {
data.email = data.email.substring(1);
}
if(data.email.endsWith(" ")){
if (data.email.endsWith(" ")) {
data.email = data.email.substring(0, 8);
}
if(response.email == data.email) {
if (response.email == data.email) {
resolve(response)
}else if(response.other_email.original == data.email){
} else if (response.other_email.original == data.email) {
resolve(response)
}else if(response.other_email.corrected == data.email){
} else if (response.other_email.corrected == data.email) {
resolve(response)
}else if(response.other_email.hackerearth == data.email){
} else if (response.other_email.hackerearth == data.email) {
resolve(response)
}else{
} else {
reject("Please enter the correct email address.")
}
} else {
reject("We regret to inform you that we are unable to proceed with your application to the next round. We wish you all the best for your future endeavors.")
}
}
}).catch((error) => {
reject(error)
})
Expand All @@ -72,57 +72,68 @@ const candidate = {
})
},

view: (data) => {
view: (id) => {
return new Promise(async (resolve, reject) => {

if(data.lpk_id.startsWith(" ")){
data.lpk_id = data.lpk_id.substring(1);
db.get()
.collection(collections.CANDIDATES)
.findOne({
"id": id
})
.then((response) => {
resolve(response)
}).catch((error) => {
reject("Something Went wrong please try again later.")
})
})
}

}

const allotment = {
apply: (id, data) => {
return new Promise(async (resolve, reject) => {
let preference = [];
let options = ['A', 'B', 'C', 'D'];
for (i = 0; i < 4; i++) {
let option = data[`preference_${i+1}`];
if (options.indexOf(option) != -1 && preference.indexOf(option) == -1) {
preference.push(option);
} else {
reject("Please select unique preferences.")
}
}
if(data.lpk_id.endsWith(" ")){
data.lpk_id = data.lpk_id.substring(0, 8);
let allotment = {
applied: true,
preference: preference
}

if (String(data.lpk_id.length) == 8 && data.lpk_id.includes("LPK1")) {
db.get()
.collection(collections.CANDIDATES)
.findOne({
"id": data.lpk_id
})
.then((response) => {
// console.log(response)
if (response) {
if(data.email.startsWith(" ")){
data.email = data.email.substring(1);
}
if(data.email.endsWith(" ")){
data.email = data.email.substring(0, 8);
}
if(response.email == data.email) {
resolve(response)
}else if(response.other_email.original == data.email){
resolve(response)
}else if(response.other_email.corrected == data.email){
resolve(response)
}else if(response.other_email.hackerearth == data.email){
resolve(response)
}else{
reject("Please enter the correct email address.")
}
} else {
reject("We regret to inform you that we are unable to proceed with your application to the next round. We wish you all the best for your future endeavors.")
db.get()
.collection(collections.CANDIDATES)
.update(
{ id: id},
{
$set:
{
"allotment": allotment
}
}
)
.then((response) => {
candidate.view(id).then((candidate) => {
resolve(candidate)
}).catch((error) => {
reject(error)
reject("Something Went wrong please try again later.")
})
} else {
reject("Please enter a valid Launchpad Kerala ID.")
}
}).catch((error) => {
reject(error)
})

})
}

}

module.exports = {
contact,
candidate
candidate,
allotment
}
3 changes: 1 addition & 2 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1643,8 +1643,7 @@ section {
margin: 0.5rem 0rem;
}
.forms form .form-group {
margin: 1rem 0rem;
margin-top: 1.5rem;
margin: 0.5rem 0rem;
color: rgba(21, 21, 21, 0.9);
}
.forms form .form-group input {
Expand Down
82 changes: 74 additions & 8 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ router.get('/results/view', function (req, res, next) {
});

router.post('/results/view', function (req, res, next) {
controller.candidate.view(req.body)
controller.candidate.viewCanidate(req.body)
.then((candidate) => {
res.render('pages/view_result',
{
Expand Down Expand Up @@ -140,13 +140,79 @@ router.get('/allotment/apply', function (req, res, next) {
});

router.post('/allotment/apply', function (req, res, next) {
res.render('pages/allotment/apply',
{
title: `Allotment Application | ${app_name}`,
page_head: 'Allotment',
page_nav_name: 'Allotment',
allotment_page: true
});
controller.candidate.viewCanidate(req.body)
.then((candidate) => {
if (candidate.allotment.applied) {
req.session.candidate = null;
res.render('pages/allotment/success',
{
title: `Allotment Application | ${app_name}`,
page_head: 'Allotment',
page_nav_name: 'Allotment',
allotment_page: true,
success_message: 'You have already applied for allotment',
candidate
});
} else {
req.session.candidate = candidate;
console.log(req.session.candidate);
res.render('pages/allotment/application',
{
title: `Allotment Application | ${app_name}`,
page_head: 'Allotment',
page_nav_name: 'Allotment',
allotment_page: true,
candidate
});
}
})
.catch((error) => {
res.redirect('/allotment/apply');
})
});

router.get('/allotment/application/complete/', function (req, res, next) {
let candidate = req.session.candidate;
let message = req.flash('message');
if (candidate) {
res.render('pages/allotment/application',
{
title: `Allotment Application | ${app_name}`,
page_head: 'Allotment',
page_nav_name: 'Allotment',
allotment_page: true,
candidate,
message
});
} else {
req.session.candidate = null;
req.flash('message', 'Please fill the application form');
res.redirect('/allotment/apply');
}
});

router.post('/allotment/application/submit/', function (req, res, next) {
let candidate = req.session.candidate;
if (candidate) {
controller.allotment.apply(candidate.id, req.body)
.then((candidate) => {
req.session.candidate = null;
res.render('pages/allotment/success',
{
title: `Allotment Application | ${app_name}`,
page_head: 'Allotment',
page_nav_name: 'Allotment',
allotment_page: true,
success_message: 'Your application has been submitted successfully',
candidate
});
})
.catch((error) => {
res.redirect('/allotment/application/complete/');
})
} else {
res.redirect('/allotment/application/complete/');
}
});

router.get('/allotment/recruiters', function (req, res, next) {
Expand Down
4 changes: 2 additions & 2 deletions scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ section {
form {
margin: 0.5rem 0rem;
.form-group {
margin: 1rem 0rem;
margin-top: 1.5rem;
margin: 0.5rem 0rem;
// margin-top: 1.5rem;
color: rgba($color: $color_4, $alpha: 0.9);


Expand Down
Loading

0 comments on commit f1beb4d

Please sign in to comment.