Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dhaura/pharmacy testing #129

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"host": "localhost",
"user": "root",
"password": "",
"host": "remotemysql.com",
"user": "Kkq09TT7JY",
"password": "UV24WrmAIM",
"port": 3306,
"database": "pharmacy-finder",
"database": "Kkq09TT7JY",
"session_secret": "session_cookie_secret"
}
8 changes: 4 additions & 4 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"host": "localhost",
"user": "root",
"password": "",
"host": "remotemysql.com",
"user": "Kkq09TT7JY",
"password": "UV24WrmAIM",
"port": 3306,
"database": "pharmacy-finder",
"database": "Kkq09TT7JY",
"session_secret": "session_cookie_secret"
}
10 changes: 5 additions & 5 deletions controllers/customer/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ const loginCustomer = async (request, response) => {

if (error) {
var err_msg = "Customer Login error validation " + error.message;
return response.status(400).render('customer/login_error', { err_data: err_msg });
return response.render('customer/login_error', { err_data: err_msg });
}

try {
const result = await Customer.getCustomerInfoByEmail(request.body.email);
if (!result[0]) {
var err_msg = "Email is not registered";
return response.status(400).render('customer/login_error', { err_data: err_msg });
return response.render('customer/login_error', { err_data: err_msg });
}

const hashedPassword = result[0].password;
const passwordCorrect = await bcrypt.compare(request.body.password, hashedPassword);
if (!passwordCorrect) {
var err_msg = "Invalid email or password";
return response.status(400).render('customer/login_error', { err_data: err_msg });
return response.render('customer/login_error', { err_data: err_msg });
}
request.session.user = {};
request.session.user.email = result[0].email;
request.session.user.id = result[0].customer_id;
request.session.user.class = 2;
}
catch (error) {
return response.status(500).render('500', {
return response.render('500', {
err_data: "Internal server error " + error.message
});
}

return response.status(200).redirect('/customer/home');
return response.redirect('/customer/home');

}

Expand Down
24 changes: 13 additions & 11 deletions controllers/customer/pharmacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const viewPharmacyInformation = async(req, res) => {
const {error} = validatePharmacyName({pharmacyName:pharmacyName});

if (error) {
return res.status(400).render('400', {
return res.render('400', {
err_data: "Invalid pharmacy name provided",
redirect_to: "/customer/pharmacy",
button_message: "Try Again",
Expand All @@ -37,25 +37,26 @@ const viewPharmacyInformation = async(req, res) => {
try {
const pharmacyInformation = await Customer.getPharmacyInformation(pharmacyName);
if(pharmacyInformation.length === 0){
return res.status(404).render('404');
return res.render('404');
}

// send data to front end

return res.status(200).render('customer/view_pharmacy',{
return res.render('customer/view_pharmacy',{
pharmacyInformation: pharmacyInformation[0],
pageTitle: 'Pharmacy Information'
});
}
catch (error) {
return res.status(500).render('500', {
err_data: "Internal server error " + error.message
var err_msg = "Internal server error " + error.message;
return res.render('500', {
err_data: err_msg
});
}
}
const getCustomerSearchPharmacy = async (req,res)=>{

res.status(200).render('customer/search_pharmacy',{
res.render('customer/search_pharmacy',{
pageTitle: "Search Pharmacy",
pharmacyInformation: [],
hasErrors: false
Expand All @@ -67,7 +68,7 @@ const postCustomerSearchPharmacy = async(req,res)=>{
const pharmacyName = req.body.pharmacyName;
const {error} = validatePharmacyName({pharmacyName:pharmacyName});
if (error){
return res.status(400).render('customer/search_pharmacy', {
return res.render('customer/search_pharmacy', {
pageTitle: "Search Pharmacy",
pharmacyInformation: [],
hasErrors: true,
Expand All @@ -77,22 +78,23 @@ const postCustomerSearchPharmacy = async(req,res)=>{
try{
pharmacyInformation = await Customer.getPharmacyInformation(pharmacyName);
if (pharmacyInformation.length===0){
return res.status(404).render('customer/search_pharmacy',{
return res.render('customer/search_pharmacy',{
pageTitle: "Search Pharmacy",
pharmacyInformation: [],
hasErrors: true,
errors: "Pharmacy not registered"
});
}
return res.status(200).render('customer/view_pharmacy',{
return res.render('customer/view_pharmacy',{
pageTitle: "Search Pharmacy",
pharmacyInformation: pharmacyInformation[0],
hasErrors: false
});
}
catch (error) {
return res.status(500).render('500', {
err_data: "Internal server error " + error.message
var err_msg = "Internal server error " + error.message;
return response.render('500', {
err_data: err_msg
});
}
}
Expand Down
31 changes: 18 additions & 13 deletions controllers/customer/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const viewProfileInformation = async (req, res) => {
const {error} = validateCustomerId({customerId:customerId});

if (error) {
return res.status(400).render("400", {
return res.render("400", {
err_data: "Invalid customer ID",
redirect_to: "/customer/home",
button_message: "Try Again",
Expand All @@ -35,16 +35,17 @@ const viewProfileInformation = async (req, res) => {
{
const result = await Customer.getProfileDetails(customerId);
if (result.length === 0) {
return res.status(404).render('404');
return res.render('404');
}
return res.status(200).render('customer/view_profile',{
return res.render('customer/view_profile',{
res_profile_info:result,
pageTitle: 'My profile'
});
}
catch (error) {
return res.status(500).render('500', {
err_data: "Internal server error " + error.message
var err_msg = "Internal server error " + error.message;
return response.render('500', {
err_data: err_msg
});
}
}
Expand Down Expand Up @@ -80,7 +81,7 @@ const editProfileInformation = async (request, response) => {
));

if (error) {
return response.status(400).render("400", {
return response.render("400", {
err_data: error.message,
redirect_to: "/customer/home",
button_message: "Try Again",
Expand All @@ -103,12 +104,14 @@ const editProfileInformation = async (request, response) => {
"contact_no"
]
));
return response.status(200).redirect('/customer/profile/view');
console.log(result);
return response.redirect('/customer/profile/view');

}
catch (error) {
return response.status(500).render('500', {
err_data: "Internal server error " + error.message
var err_msg = "Internal server error " + error.message;
return response.render('500', {
err_data: err_msg
});
}
}
Expand All @@ -118,7 +121,7 @@ const loadEditProfile = async (request, response) => {
const {error} = validateCustomerId({customerId:customerId});

if (error) {
return response.status(400).render("400", {
return response.render("400", {
err_data: "Invalid customer ID",
redirect_to: "/customer/home",
button_message: "Try Again",
Expand All @@ -129,20 +132,22 @@ const loadEditProfile = async (request, response) => {
{
const result = await Customer.getProfileDetails(customerId);
if (result.length === 0) {
return response.status(404).render('404');
return response.render('404');
}

return response.status(200).render('customer/edit_profile',{
return response.render('customer/edit_profile',{
customerId:customerId,
profile:result

});
}
catch (error) {
return response.status(500).render('500', {
return response.render('500', {
err_data: "Internal server error " + error.message
});

}

}

exports.editProfileInformation = editProfileInformation;
Expand Down
4 changes: 2 additions & 2 deletions controllers/customer/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const reportPharmacy = async (req, res) => {
const reasons = req.body.reasons;
const customer_id = req.session.user.id;
const result = await Customer.reportPharmacy(pharmacy_id, customer_id, reasons);
return res.status(200).redirect('/customer/home');
return res.redirect('/customer/home');

}
catch (error) {
return res.status(400).render('400', {
return res.render('400', {
err_data: "Pharmacy report unsuccessful",
redirect_to: "/customer/pharmacy/search",
button_message: "Try Again",
Expand Down
49 changes: 33 additions & 16 deletions controllers/customer/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getBroadcastForm = async (request, response) => {
const drug_types = await SystemAdmin.getAllDrugTypes();
const branded_drugs = await SystemAdmin.getAllDrugs();

return response.status(200).render('customer/broadcastForm', {
return response.render('customer/broadcastForm', {
pageTitle: "Broadcast Form",
drug_types: drug_types,
branded_drugs: branded_drugs,
Expand Down Expand Up @@ -46,7 +46,7 @@ const createBroadcastRequest = async (request, response) => {
}
if (tempDrugTypesBeforeProcessing.length == 0 && tempBrandedDrugsBeforeProcessing.length == 0) {
{
return response.status(400).render('400', {
return response.render('400', {
err_data: "You have not selected any drugs. Please select at least one brand/drug type",
redirect_to: "/customer/request/broadcast",
button_message: "Try Again",
Expand Down Expand Up @@ -87,7 +87,7 @@ const createBroadcastRequest = async (request, response) => {
{
const pharmacies = await Lookup.lookupPharmacies(left, right, up, down, pharmaciesToLookUp); //returns pharmacies within the 30 km range
if (!pharmacies || pharmacies.length == 0) {
return response.status(400).render('400', {
return response.render('400', {
err_data: "There are no approved pharmacies within 30km of your location that sell the medicine you require. Consider editing your location under your profile to get better search results",
redirect_to: "/customer/request/broadcast",
button_message: "Try Again",
Expand Down Expand Up @@ -123,17 +123,19 @@ const createBroadcastRequest = async (request, response) => {
{
const id3 = await Customer.enterBrandedDrugs(brandedDrugs);
}
return response.status(200).redirect('/customer/home');
return response.redirect('/customer/home');

}
catch (error) {
return response.status(500).render('500', {
err_data: "Internal server error " + error.message
var err_msg = "Internal server error " + error.message;

return response.render('500', {
err_data: err_msg
});
}
}
else {
return response.status(400).render('400', {
return response.render('400', {
err_data: "No pharmacies have the available drugs",
redirect_to: "/customer/home",
button_message: "Return to home page",
Expand Down Expand Up @@ -168,7 +170,7 @@ const viewBroadcastedRequests = async(req, res) => {
const {error} = validateRequestId({requestId:requestID});

if (error) {
return res.status(400).render('400', {
return res.render('400', {
err_data: "Invalid Request",
redirect_to: "/customer/home",
button_message: "Return to home page",
Expand All @@ -181,18 +183,18 @@ const viewBroadcastedRequests = async(req, res) => {

try{
if(drug_types.length === 0 && branded_drugs.length===0){
return res.status(404).render('404');
return res.render('404');
}
if (responded_pharmacies.length === 0) {
return res.status(400).render('customer/view_requests', {
return res.render('customer/view_requests', {
drug_types: drug_types,
branded_drugs: branded_drugs,
hasPharmacies:false,
pageTitle: 'Request Details'
});
}
else {
return res.status(200).render('customer/view_requests', {
return res.render('customer/view_requests', {
drug_types: drug_types,
branded_drugs: branded_drugs,
hasPharmacies: true,
Expand All @@ -202,14 +204,28 @@ const viewBroadcastedRequests = async(req, res) => {
}
}
catch(error){
return res.status(500).render('500', {
return res.render('500', {
err_data: "Internal server error " + error.message
});
}
}

// ====================================================END OF USE CASE======================================================//
// ======================================USE CASE: VIEW ALL REQUESTS==================================================//
/**
*
* @param {number} customerId
*/
function validateCustomerId(customerId){

// schema to validate
const schema = Joi.object({
"customerId" : Joi.number().integer().min(10001).required(),
});

// return valid or not
return schema.validate(customerId)
}

const viewAllRequests = async(req, res) => {

Expand All @@ -218,15 +234,16 @@ const viewAllRequests = async(req, res) => {

try {
let result = await Customer.getAllRequests(customerId);
return res.status(200).render('customer/home',{
return res.render('customer/home',{
all_requests: result,
pageTitle: 'Requests'
});
}
catch(error){
var err_msg = "Internal server error " + error.message;

return response.status(500).render('500', {
err_data: "Internal server error " + error.message
return response.render('500', {
err_data: err_msg
});
}

Expand All @@ -238,7 +255,7 @@ const viewAllRequests = async(req, res) => {
const deleteBroadcast = async (req, res) => {
const requestID = req.body.requestID;
result = await Customer.deleteRequest(requestID);
res.status(200).redirect('/customer/home');
res.redirect('/customer/home');
}

module.exports.viewBroadcastedRequests = viewBroadcastedRequests;
Expand Down
Loading