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

Added forgot password page #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# About School Fees Tracker

# Getting Started
**We assume you already have Git, Nodejs and npm already installed on your machine.**
**We assume you already have git, nodejs and npm already installed on your machine.**

**Follow the following steps: The symbol '$' that precedes each line means run in terminal.**

Expand All @@ -24,7 +24,7 @@ $ git remote add upstream https://github.com/hnginternship5/feetracker.git

3. Change into the cloned repo and install dependencies
```
$ cd feetracker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually feetracker, not fees-tracker

$ cd Fees-tracker
$ npm install
```

Expand All @@ -40,4 +40,4 @@ $ npm start
— After making changes to the repo, push to master and create pull request, make sure there are no merge conflicts.

— Do not merge pull request, a mentor will.
— If upon fetching upstream, npm start fails, run npm install then try again.
— You if upon fetch upstream to update and npm start can't run, do npm intall then try again.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const mongoose = require('mongoose');
const exphbs = require('express-handlebars');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
// const _ = require('lodash');
const flash = require('connect-flash');
const session = require('express-session');
// const expressOasGenerator = require('express-oas-generator');
Expand Down
7 changes: 3 additions & 4 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Auth = {
};
const { isValid, errors } = validateSchool(newSchool);
if (!isValid)
res.status(400).send({ errors });
res.status(400).send({ errors: errors });
else {
var school = await schoolDb.create(newSchool);
schoolId = school._id;
Expand Down Expand Up @@ -56,8 +56,7 @@ const Auth = {
const user = await userDb.create(newUser); //Create user and return user
user.school.name = school_name;
user.school.address = school_address;
user.school.currency = school_currency;
user.school.id = schoolId;
user.school.currency = school_currency
res.status(201).send(user.toJSON());
}
}
Expand All @@ -79,7 +78,7 @@ const Auth = {
}
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.status(200).send({ user });
return res.status(200).send({ user: user });
});
})(req, res, next);
},
Expand Down
73 changes: 24 additions & 49 deletions controllers/class.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,77 @@
const _ = require('lodash');
const classDb = require('./promise').ClassDb;

const Class = {
async create(req, res) {
const queryText = req.body;
try {
const queryText = _.omit(req.body, ['school_id']);
queryText.school_id = req.user.school.id;
const createdClass = await classDb.create(queryText);
return res.status(201).send({
message: 'Class successfully created',
data: createdClass,
});
return res.status(201).json(createdClass);
} catch (error) {
return res.status(400).send(error);
}
},
async get_all_classes(req, res) {
const queryText = {};
try {
const queryText = { school_id: req.user.school.id };
const foundClasses = await classDb.find(queryText);
return res.status(200).send({
message: 'Classes retrieved successfully',
data: foundClasses,
});
return res.status(200).json(foundClasses);
} catch (error) {
return res.status(400).send(error);
}
},
async get_all_parent_classes(req, res) {
const queryText = {
parent_id: null,
};
try {
const queryText = {
parent_id: null,
school_id: req.user.school.id,
};
const foundClasses = await classDb.find(queryText);
return res.status(200).json(foundClasses);
} catch (error) {
return res.status(400).send(error);
}
},
async get_one_class(req, res) {
const queryText = {
id: req.params.class_id,
};
try {
const queryText = {
_id: req.params.id,
school_id: req.user.school.id,
};
const foundClass = await classDb.findOne(queryText);
if (!foundClass) return res.status(404).send({ message: 'Class not found' });
return res.status(200).send({
message: 'Class retrieved successfully',
data: foundClass,
});
return res.status(200).json(foundClass);
} catch (error) {
return res.status(400).send(error);
}
},
async get_class_arms(req, res) {
const queryText = {
isArm: true,
parent_id: req.params.class_id,
};
try {
const queryText = {
isArm: true,
parent_id: req.params.id,
school_id: req.user.school.id,
};
const foundArms = await classDb.findOne(queryText);
return res.status(200).json(foundArms);
} catch (error) {
return res.status(400).send(error);
}
},
async update_class(req, res) {
const queryText = {
id: req.params.class_id,
};
const updateData = req.body;
try {
const queryText = {
_id: req.params.id,
school_id: req.user.school.id,
};
const updateData = _.omit(req.body, ['school_id']);
const updatedClass = await classDb.findOneAndUpdate(queryText, updateData);
if (!updatedClass) return res.status(404).send({ message: 'Class not found' });
return res.status(200).send({
message: 'Class updated successfully',
data: updatedClass,
});
return res.status(200).json(updatedClass);
} catch (error) {
return res.status(400).send(error);
}
},
async delete_class(req, res) {
const queryText = {
id: req.params.class_id,
};
try {
const queryText = {
_id: req.params.id,
school_id: req.user.school.id,
};
const deletedClass = await classDb.findOneAndDelete(queryText);
if (!deletedClass) return res.status(404).send({ message: 'Class not found' });
return res.status(200).send({
message: 'Class successfully deleted',
data: deletedClass,
});
return res.status(200).json(deletedClass);
} catch (error) {
return res.status(400).send(error);
}
Expand Down
45 changes: 11 additions & 34 deletions controllers/fee.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,54 @@
const _ = require('lodash');
const feeDb = require('./promise').FeeDb;

const Fee = {
async create(req, res) {
const queryText = _.omit(req.body, ['school_id']);
queryText.school_id = req.user.school.id;
const queryText = req.body;
try {
const createdFee = await feeDb.create(queryText);
return res.status(201).send({
message: 'Fee successfully created',
data: createdFee,
});
return res.status(201).json(createdFee);
} catch (error) {
return res.status(400).send(error);
}
},
async get_all_fees(req, res) {
const queryText = { school_id: req.user.school.id };
const queryText = {};
try {
const foundFees = await feeDb.find(queryText);
return res.status(200).send({
message: 'Fees retrieved successfully',
data: foundFees,
});
return res.status(200).json(foundFees);
} catch (error) {
return res.status(400).send(error);
}
},
async get_one_fee(req, res) {
const queryText = {
_id: req.params.id,
school_id: req.user.school.id
_id: req.params.fee_id,
};
try {
const foundFee = await feeDb.findOne(queryText);
if (!foundFee) return res.status(404).send({ message: 'Fee not found' });
return res.status(200).send({
message: 'Fee successfully retrieved',
data: foundFee,
});
return res.status(200).json(foundFee);
} catch (error) {
return res.status(400).send(error);
}
},
async update_fee(req, res) {
const queryText = {
_id: req.params.id,
school_id: req.user.school.id
_id: req.params.fee_id,
};
const updateData = _.omit(req.body, ['school_id']);
const updateData = req.body;
try {
const updatedFee = await feeDb.findOneAndUpdate(queryText, updateData);
if (!updatedFee) return res.status(404).send({ message: 'Fee not found' });
return res.status(200).send({
message: 'Fee successfully updated',
data: updatedFee,
});
return res.status(200).json(updatedFee);
} catch (error) {
return res.status(400).send(error);
}
},
async delete_fee(req, res) {
const queryText = {
_id: req.params.id,
school_id: req.user.school.id
_id: req.params.fee_id,
};
try {
const deletedFee = await feeDb.findOneAndDelete(queryText);
if (!deletedFee) return res.status(404).send({ message: 'Fee not found' });
return res.status(200).send({
message: 'Fee successfully deleted',
data: deletedFee,
});
return res.status(200).json(deletedFee);
} catch (error) {
return res.status(400).send(error);
}
Expand Down
Loading