Skip to content
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
84 changes: 84 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# FuseBox cache
.fusebox/

#built folder
built/
# package-lock.json file
package-lock.json

#vscode file
.vscode/
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Backend-mongoDB

Backend microservices api demo.
Essential features of login panel: User Registration , User Login, Forgot Password, Update Password; all done in Node.js with Express and MongoDB.

[**Swagger-Ui**](https://swagger.io/) is used to visualize the application.

**User Authentication** enabled using [Passport](http://www.passportjs.org/)

**Role Based Access Control** on the routes and can be configured accroding to need to provide limited access based on the role of user.

## Run
1. Install dependencies ``` npm install ```
2. Configure MongoDB uri in ``` config/development.ts ```
3. Get SendGrid API Key from [SendGrid](https://sendgrid.com) and set it in ``` .env ``` file
4. *(Optional)* Default role is user and you can customize acl in ``` src/app/config/nacl.json ```
5. Run ``` tsc ``` in your terminal to compile the code
6. Run ``` node built/app.js ``` to run the project

[Postman](https://www.getpostman.com/) is recommended to send various requests e.g. GET, POST, etc.

* Register user by ``` http:localhost:9000/api/user/register ``` and you will see the user stored in MongoDB

* Now, you can try various other methods such as Forgot Password, Update Password and play around with other custom routes.

* You can perform authentication using ``` auth/ ``` routes.

* You can also query the stored data in database using ``` api/query/ ``` routes.

### References
* For learning more about ACL library used here: [express-acl](https://www.npmjs.com/package/express-acl)
* Library used for [pagination](https://www.npmjs.com/package/mongoose-paginate)
* Library used for swagger-docs: [swagger-jsdoc](https://www.npmjs.com/package/swagger-jsdoc)



5 changes: 3 additions & 2 deletions built/api/common/common.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ var common_1 = require("../../common/common");
// Get list of things
function get(req, res) {
var col = req.params.collection;
var page = req.query.page;
var Model = mongoose.model(req.params.collection);
Model.find({ $and: [{ $or: [{ is_deleted: false }, { is_deleted: null }] }] }, function (err, annos) {
Model.paginate({ $and: [{ $or: [{ is_deleted: false }, { is_deleted: null }] }] }, { page: page, limit: 2 }, function (err, annos) {
if (err) {
res.send(common_1.send_response(null, true, common_1.parse_error(err)));
}
Expand Down Expand Up @@ -249,7 +250,7 @@ function destroy(req, res) {
if (err) {
return res.send(common_1.send_response(null, true, common_1.parse_error(err)));
}
return res.status(204).send(common_1.send_response({}));
return res.send(common_1.send_response(null, false, "User deleted Successfully!"));
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions built/api/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
var express = require("express");
var controller = require("./common.controller");
var auth = require("../../auth/auth.service");
var acl = require("express-acl");
var router = express.Router();
router.use(acl.authorize);
router.get('/:collection', auth.isAuthenticated(), controller.get);
router.get('/:collection/:id', auth.isAuthenticated(), controller.getById);
router.get('/:collection/getbyuser/:user', auth.isAuthenticated(), controller.getByUser);
Expand Down
33 changes: 21 additions & 12 deletions built/api/user/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
var express = require("express");
var controller = require("./user.controller");
var auth = require("../../auth/auth.service");
var acl = require("express-acl");
var options = {
path: "src/config/",
baseUrl: "/",
defaultRole: "user"
};
acl.config(options);
var router = express.Router();
var multer = require("multer");
var upload = multer({ dest: './public/upload/' });
router.post('/register', controller.register_user);
router.post('/forgotpassword', controller.forgotpassword);
router.post('/register_verify', controller.register_verify);
router.post('/resetPassword', controller.resetPassword);
router.post('/welcome_user', controller.welcome_user);
router.post('/verifytoken', controller.verifytoken);
router.post('/updatepassword', auth.isAuthenticated(), controller.updatePassword);
var upload = multer({ dest: "./public/upload/" });
router.use(acl.authorize);
router.post("/register", controller.register_user);
router.post("/forgotpassword", controller.forgotpassword);
router.post("/register_verify", controller.register_verify);
router.post("/resetPassword", controller.resetPassword);
router.post("/welcome_user", controller.welcome_user);
router.post("/verifytoken", controller.verifytoken);
router.post("/updatepassword", auth.isAuthenticated(), controller.updatePassword);
router.get("/acl-test", function (req, res) {
res.send("acl is working!!!");
});
/* For mobile side */
router.post('/upload/avatar', auth.isAuthenticated(), upload.single('file'), controller.uploadpic);
/* END */
router.post("/upload/avatar", auth.isAuthenticated(), upload.single("file"), controller.uploadpic);
module.exports = router;
Loading