├── .gitignore ├── README.md ├── api ├── controllers │ ├── messages.controller.js │ ├── stats.controller.js │ └── user.controller.js ├── models │ ├── messages.model.js │ ├── stats.model.js │ └── user.model.js ├── routes │ ├── messages.route.js │ ├── stats.route.js │ └── user.route.js └── services │ ├── message.service.js │ ├── stats.service.js │ └── user.service.js ├── config.js ├── package.json └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![OpenAdmin Dashboard Banner](https://neuethemes.net/wp-content/uploads/github-slide-02.jpg "OpenAdmin Banner") 2 | 3 | # OpenAdmin Dashboard NodeJS Server 4 | Free OpenAdmin server based on NodeJS. 5 | 6 | ## See the Live Preview 7 | http://openadmin.neuethemes.net/client/html/ 8 | 9 | ![divider](https://neuethemes.net/wp-content/uploads/transparent-30.png "divider") 10 | 11 | ## Overview 12 | 13 | **OpenAdmin Dashboard** is the simple lightweight and fully-featured Multi-framework web dashboard application based on latest Bootstrap4, HTML5/CSS3 and uses all it's powerful features. All components included in this dashboard template has been developed to bring all the potential of HTML5 and Bootstrap plus a set of new features (JS and CSS) ideal for your next dashboard admin theme or admin web app project. 14 | 15 | **OpenAdmin Dashboard** was developed for all type of web applications: Single Page Application (SPA), project management system, ecommerce admin dashboard, CMS, CRM, SAAS, help desk; for personal and business purposes. It comes with lot of ready-to-use components (widgets, forms, etc). It is 100% responsive and easy customizable theme. It gives a possibility to any developer to create modern and quality web app quickly without a hassle. 16 | 17 | ![divider](https://neuethemes.net/wp-content/uploads/transparent-30.png "divider") 18 | 19 | ## See also 20 | 21 | #### [OpenAdmin Dashboard Project Main Github Page](https://github.com/Neuethemes/OpenAdmin) 22 | 23 | ![divider](https://neuethemes.net/wp-content/uploads/transparent-20.png "divider") 24 | 25 | ### OpenAdmin Client versions 26 | 27 | #### [Free HTML5 Bootstrap4 OpenAdmin Dashboard](https://github.com/Neuethemes/OpenAdmin-client-Html) 28 | #### [Free Angular OpenAdmin Dashboard](https://github.com/Neuethemes/OpenAdmin-client-Angular) 29 | #### [Free React OpenAdmin Dashboard](https://github.com/Neuethemes/OpenAdmin-client-React) 30 | #### [Free VueJS OpenAdmin Dashboard (Coming Soon)](https://github.com/Neuethemes/OpenAdmin-client-VueJS) 31 | 32 | ![divider](https://neuethemes.net/wp-content/uploads/transparent-20.png "divider") 33 | 34 | ### Available Servers 35 | 36 | #### [Free NodeJS OpenAdmin Server](https://github.com/Neuethemes/OpenAdmin-server-NodeJS) 37 | #### [Free Python OpenAdmin Server](https://github.com/Neuethemes/OpenAdmin-server-Python) 38 | #### [Free PHP OpenAdmin Server (Coming Soon)](https://github.com/Neuethemes/OpenAdmin-server-PHP) 39 | 40 | ![divider](https://neuethemes.net/wp-content/uploads/transparent-30.png "divider") 41 | 42 | ### Main Dashboard Screenshot 43 | 44 | ![OpenAdmin Dashboard](https://neuethemes.net/wp-content/uploads/01-openadmin-screen-01.jpg "OpenAdmin Dashboard") 45 | 46 | ![divider](https://neuethemes.net/wp-content/uploads/transparent-30.png "divider") 47 | -------------------------------------------------------------------------------- /api/controllers/messages.controller.js: -------------------------------------------------------------------------------- 1 | const MessagesService = require('../services/message.service'); 2 | 3 | // Async Controller function to get the User List 4 | 5 | exports.getAll = async function(req, res, next) { 6 | try { 7 | let messages = await MessagesService.getAll(); 8 | // Return the users list with the appropriate HTTP Status Code and Message. 9 | return res.status(200).json({status: 200, data: messages, message: "Successfully Messages Received"}); 10 | } catch(e) { 11 | //Return an Error Response Message with Code and the Error Message. 12 | return res.status(400).json({status: 400, message: e.message}); 13 | } 14 | }; -------------------------------------------------------------------------------- /api/controllers/stats.controller.js: -------------------------------------------------------------------------------- 1 | const StatsService = require('../services/stats.service'); 2 | 3 | // Async Controller function to get the User List 4 | 5 | exports.getMonitoring = async function(req, res, next) { 6 | try { 7 | let monitoring = await StatsService.getMonitoring(); 8 | // Return the users list with the appropriate HTTP Status Code and Message. 9 | return res.status(200).json({status: 200, data: monitoring, message: "Successfully Monitoring Received"}); 10 | } catch(e) { 11 | //Return an Error Response Message with Code and the Error Message. 12 | return res.status(400).json({status: 400, message: e.message}); 13 | } 14 | }; 15 | 16 | exports.getSales = async function(req, res, next) { 17 | try { 18 | let sales = await StatsService.getSales(); 19 | // Return the users list with the appropriate HTTP Status Code and Message. 20 | return res.status(200).json({status: 200, data: sales.data, message: "Successfully Monitoring Received"}); 21 | } catch(e) { 22 | //Return an Error Response Message with Code and the Error Message. 23 | return res.status(400).json({status: 400, message: e.message}); 24 | } 25 | }; 26 | 27 | exports.getSummary = async function(req, res, next) { 28 | try { 29 | let summary = await StatsService.getSummary(); 30 | // Return the users list with the appropriate HTTP Status Code and Message. 31 | return res.status(200).json({status: 200, data: summary.data[0], message: "Successfully Summary Received"}); 32 | } catch(e) { 33 | //Return an Error Response Message with Code and the Error Message. 34 | return res.status(400).json({status: 400, message: e.message}); 35 | } 36 | }; 37 | 38 | exports.getCharts = async function(req, res, next) { 39 | try { 40 | let charts = await StatsService.getCharts(); 41 | // Return the users list with the appropriate HTTP Status Code and Message. 42 | return res.status(200).json({status: 200, data: charts.data[0], message: "Successfully Charts Received"}); 43 | } catch(e) { 44 | //Return an Error Response Message with Code and the Error Message. 45 | return res.status(400).json({status: 400, message: e.message}); 46 | } 47 | }; 48 | 49 | exports.updateStats = async function(req, res, next) { 50 | try { 51 | StatsService.updateStats(); 52 | // Return the users list with the appropriate HTTP Status Code and Message. 53 | return res.status(200).json({status: 200, data: '', message: "Successfully"}); 54 | } catch(e) { 55 | //Return an Error Response Message with Code and the Error Message. 56 | return res.status(400).json({status: 400, message: e.message}); 57 | } 58 | }; -------------------------------------------------------------------------------- /api/controllers/user.controller.js: -------------------------------------------------------------------------------- 1 | const UserService = require('../services/user.service'); 2 | 3 | // Async Controller function to get the User List 4 | 5 | exports.authenticate = async function(req, res, next) { 6 | 7 | console.log(req.body); 8 | 9 | try { 10 | 11 | let user = await UserService.authenticate(req.body.email, req.body.password); 12 | 13 | // Return the users list with the appropriate HTTP Status Code and Message. 14 | 15 | return res.status(200).json({status: 200, data: user, message: "Authenticate successfully"}); 16 | 17 | } catch(e) { 18 | 19 | //Return an Error Response Message with Code and the Error Message. 20 | 21 | return res.status(400).json({status: 400, message: e.message}); 22 | 23 | } 24 | 25 | }; 26 | 27 | 28 | exports.getUsers = async function(req, res, next) { 29 | 30 | // Check the existence of the query parameters, If the exists doesn't exists assign a default value 31 | let page = req.query.page ? req.query.page : 1; 32 | let limit = req.query.limit ? req.query.limit : 10; 33 | 34 | try { 35 | 36 | let users = await UserService.getUsers({}, page, limit); 37 | 38 | // Return the users list with the appropriate HTTP Status Code and Message. 39 | 40 | return res.status(200).json({status: 200, data: users, message: "Successfully Users Received"}); 41 | 42 | } catch(e) { 43 | 44 | //Return an Error Response Message with Code and the Error Message. 45 | 46 | return res.status(400).json({status: 400, message: e.message}); 47 | 48 | } 49 | }; 50 | 51 | exports.createUser = async function(req, res, next) { 52 | 53 | // Req.Body contains the form submit values. 54 | 55 | let user = { 56 | email: req.body.email, 57 | password: req.body.password, 58 | firstName: req.body.firstName, 59 | lastName: req.body.lastName, 60 | }; 61 | 62 | console.log(user); 63 | 64 | try { 65 | 66 | // Calling the Service function with the new object from the Request Body 67 | 68 | let createdUser = await UserService.createUser(user); 69 | return res.status(201).json({status: 201, data: createdUser, message: "Successfully Created User"}) 70 | }catch(e){ 71 | 72 | //Return an Error Response Message with Code and the Error Message. 73 | 74 | return res.status(400).json({status: 400, message: "User Creation was Unsuccessfully"}) 75 | } 76 | }; 77 | 78 | exports.updateUser = async function(req, res, next) { 79 | 80 | // Id is necessary for the update 81 | 82 | if (!req.body._id){ 83 | return res.status(400).json({status: 400, message: "Id must be present"}) 84 | } 85 | 86 | let id = req.body._id; 87 | 88 | let user = { 89 | id, 90 | firstName: req.body.firstName || null, 91 | lastName: req.body.lastName || null, 92 | avatar: req.body.avatar || null 93 | }; 94 | 95 | console.log(user); 96 | 97 | try { 98 | let updatedUser = await UserService.updateUser(user); 99 | return res.status(200).json({status: 200, data: updatedUser, message: "Successfully Updated User"}) 100 | } catch(e) { 101 | return res.status(400).json({status: 400, message: e.message}) 102 | } 103 | }; 104 | 105 | exports.removeUser = async function(req, res, next) { 106 | 107 | let id = req.params.id; 108 | 109 | try { 110 | let deleted = await UserService.deleteUser(id); 111 | return res.status(204).json({status:204, message: "Successfully User Deleted"}) 112 | } catch(e) { 113 | return res.status(400).json({status: 400, message: e.message}) 114 | } 115 | 116 | }; -------------------------------------------------------------------------------- /api/models/messages.model.js: -------------------------------------------------------------------------------- 1 | const { mongoose } = require('../../config'); 2 | 3 | let MessagesSchema = new mongoose.Schema({ 4 | avatar: String, 5 | name: String, 6 | date: String, 7 | header: String, 8 | content: String 9 | }); 10 | 11 | const Messages = mongoose.model('Messages', MessagesSchema); 12 | 13 | module.exports = Messages; -------------------------------------------------------------------------------- /api/models/stats.model.js: -------------------------------------------------------------------------------- 1 | const { mongoose } = require('../../config'); 2 | 3 | let StatsSchema = new mongoose.Schema({ 4 | type: String, 5 | data: Array 6 | }); 7 | 8 | const Stats = mongoose.model('Stats', StatsSchema); 9 | 10 | module.exports = Stats; -------------------------------------------------------------------------------- /api/models/user.model.js: -------------------------------------------------------------------------------- 1 | const { mongoose } = require('../../config'); 2 | const mongoosePaginate = require('mongoose-paginate'); 3 | 4 | let UserSchema = new mongoose.Schema({ 5 | username: String, 6 | password: String, 7 | email: String, 8 | avatar: String, 9 | firstName: String, 10 | lastName: String 11 | }); 12 | 13 | UserSchema.plugin(mongoosePaginate); 14 | const User = mongoose.model('User', UserSchema); 15 | 16 | module.exports = User; -------------------------------------------------------------------------------- /api/routes/messages.route.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | // Getting the User Controller 5 | 6 | const MessagesController = require('../controllers/messages.controller'); 7 | 8 | // Map each API to the Controller Functions 9 | 10 | router.get('/', MessagesController.getAll); 11 | 12 | // Export the Router 13 | module.exports = router; -------------------------------------------------------------------------------- /api/routes/stats.route.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | // Getting the User Controller 5 | 6 | const StatsController = require('../controllers/stats.controller'); 7 | 8 | // Map each API to the Controller Functions 9 | 10 | router.get('/monitoring', StatsController.getMonitoring); 11 | router.get('/sales', StatsController.getSales); 12 | router.get('/summary', StatsController.getSummary); 13 | router.get('/charts', StatsController.getCharts); 14 | 15 | router.get('/update', StatsController.updateStats); 16 | 17 | // Export the Router 18 | module.exports = router; -------------------------------------------------------------------------------- /api/routes/user.route.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | // Getting the User Controller 5 | 6 | const UserController = require('../controllers/user.controller'); 7 | 8 | // Map each API to the Controller Functions 9 | 10 | router.post('/authenticate', UserController.authenticate); 11 | router.post('/register', UserController.createUser); 12 | 13 | router.get('/', UserController.getUsers); 14 | router.put('/', UserController.updateUser); 15 | router.delete('/:id', UserController.removeUser); 16 | 17 | // Export the Router 18 | module.exports = router; -------------------------------------------------------------------------------- /api/services/message.service.js: -------------------------------------------------------------------------------- 1 | const Messages = require('../models/messages.model'); 2 | 3 | exports.getAll = async function() { 4 | // Try Catch the awaited promise to handle the error 5 | try { 6 | let messages = await Messages.find(); 7 | // Return the stats list that was returned by the mongoose promise 8 | return messages; 9 | } catch (e) { 10 | // return a Error message describing the reason 11 | throw Error('Error while Paginating Stats'); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /api/services/stats.service.js: -------------------------------------------------------------------------------- 1 | const Stats = require('../models/stats.model'); 2 | 3 | exports.getMonitoring = async function() { 4 | // Try Catch the awaited promise to handle the error 5 | try { 6 | let monitoring = await Stats.findOne({type: 'monitoring'}); 7 | // Return the stats list that was returned by the mongoose promise 8 | return monitoring; 9 | } catch (e) { 10 | // return a Error message describing the reason 11 | throw Error('Error while Paginating Stats'); 12 | } 13 | }; 14 | 15 | exports.getSales = async function() { 16 | // Try Catch the awaited promise to handle the error 17 | try { 18 | let sales = await Stats.findOne({type: 'sales'}); 19 | // Return the stats list that was returned by the mongoose promise 20 | return sales; 21 | } catch (e) { 22 | // return a Error message describing the reason 23 | throw Error('Error while Paginating Stats'); 24 | } 25 | }; 26 | 27 | exports.getSummary = async function() { 28 | // Try Catch the awaited promise to handle the error 29 | try { 30 | let summary = await Stats.findOne({type: 'summary'}); 31 | // Return the stats list that was returned by the mongoose promise 32 | return summary; 33 | } catch (e) { 34 | // return a Error message describing the reason 35 | throw Error('Error while Paginating Stats'); 36 | } 37 | }; 38 | 39 | exports.getCharts = async function() { 40 | // Try Catch the awaited promise to handle the error 41 | try { 42 | let charts = await Stats.findOne({type: 'charts'}); 43 | // Return the stats list that was returned by the mongoose promise 44 | return charts; 45 | } catch (e) { 46 | // return a Error message describing the reason 47 | throw Error('Error while Paginating Stats'); 48 | } 49 | }; 50 | 51 | exports.updateStats = async function() { 52 | // Creating a new Mongoose Object by using the new keyword 53 | let newStats = new Stats({ 54 | type: 'sales', 55 | data: [ 56 | { title: "745", excerpt: "Total orders trough Marketplaces", type: "warning", val: 25 }, 57 | { title: "6,764", excerpt: "Total Affiliate Sales", type: "primary", val: 65 }, 58 | { title: "12,876", excerpt: "Subscribtion Sales", type: "success", val: 85 }, 59 | ] 60 | }); 61 | 62 | try { 63 | // Saving the User 64 | let savedStats = await newStats.save(); 65 | return savedStats; 66 | } catch(e) { 67 | // return an Error message describing the reason 68 | throw Error("Error while Creating Stats"); 69 | } 70 | }; 71 | 72 | -------------------------------------------------------------------------------- /api/services/user.service.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require('bcryptjs'); 2 | const jwt = require('jsonwebtoken'); 3 | const User = require('../models/user.model'); 4 | 5 | // Async function to get the User List 6 | exports.authenticate = async function(email, password) { 7 | try { 8 | let user = await User.findOne({ 'email': email }); 9 | // Return the authenticated user that was returned by the mongoose promise 10 | 11 | let result = await bcrypt.compare(password, user.password); 12 | 13 | if ( result ) { 14 | return { 15 | _id: user._id, 16 | username: user.username, 17 | firstName: user.firstName, 18 | lastName: user.lastName, 19 | avatar: user.avatar, 20 | token: jwt.sign({ sub: user._id }, 'secretcode_jasndkasjdbajhsbdjhbasjd') 21 | }; 22 | } else { 23 | throw Error(); 24 | } 25 | 26 | } catch (e) { 27 | // return a Error message describing the reason 28 | throw Error('Error while user authenticate'); 29 | } 30 | }; 31 | 32 | exports.getUsers = async function(query, page, limit) { 33 | 34 | // Options setup for the mongoose paginate 35 | let options = { 36 | page, 37 | limit 38 | }; 39 | 40 | // Try Catch the awaited promise to handle the error 41 | try { 42 | let users = await User.paginate(query, options); 43 | // Return the user list that was returned by the mongoose promise 44 | return users; 45 | } catch (e) { 46 | // return a Error message describing the reason 47 | throw Error('Error while Paginating Users'); 48 | } 49 | }; 50 | 51 | exports.createUser = async function(user) { 52 | 53 | // Creating a new Mongoose Object by using the new keyword 54 | let newUser = new User({ 55 | username: user.username, 56 | email: user.email, 57 | avatar: user.avatar, 58 | firstName: user.firstName, 59 | lastName: user.lastName 60 | }); 61 | 62 | newUser.password = await bcrypt.hash(user.password, 10); 63 | 64 | try { 65 | // Saving the User 66 | let savedUser = await newUser.save(); 67 | return savedUser; 68 | } catch(e) { 69 | // return an Error message describing the reason 70 | throw Error("Error while Creating User"); 71 | } 72 | }; 73 | 74 | exports.updateUser = async function(user) { 75 | let id = user.id; 76 | let oldUser; 77 | 78 | try { 79 | //Find the old User Object by the Id 80 | console.log(id); 81 | oldUser = await User.findById(id); 82 | } catch(e) { 83 | throw Error("Error occured while Finding the User"); 84 | } 85 | 86 | // If no old User Object exists return false 87 | if (!oldUser) { 88 | return false; 89 | } 90 | 91 | console.log(oldUser); 92 | 93 | //Edit the User Object 94 | oldUser.firstName = user.firstName || oldUser.firstName; 95 | oldUser.lastName = user.lastName || oldUser.lastName; 96 | oldUser.avatar = user.avatar || oldUser.avatar; 97 | 98 | console.log(oldUser); 99 | 100 | try { 101 | let savedUser = await oldUser.save(); 102 | return savedUser; 103 | } catch(e) { 104 | throw Error("And Error occured while updating the User"); 105 | } 106 | }; 107 | 108 | exports.deleteUser = async function(id) { 109 | 110 | // Delete the User 111 | try { 112 | let deleted = await User.remove({_id: id}); 113 | if (deleted.result.n === 0) { 114 | throw Error("User Could not be deleted"); 115 | } 116 | return deleted; 117 | } catch(e) { 118 | throw Error("Error Occured while Deleting the User") 119 | } 120 | }; -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | const bluebird = require('bluebird'); 2 | const mongoose = require('mongoose'); 3 | 4 | const connectionString = ''; 5 | 6 | mongoose.Promise = bluebird; 7 | mongoose.connect(connectionString, { useMongoClient: true }); 8 | module.exports = { mongoose }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angulator-server", 3 | "version": "1.0.0", 4 | "description": "Server for Angulator", 5 | "license": "GPL", 6 | "main": "server.js", 7 | "scripts": { 8 | "dev": "nodemon server.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://slaving@bitbucket.org/neuethemes/angulator.git" 13 | }, 14 | "dependencies": { 15 | "bcryptjs": "^2.4.3", 16 | "bluebird": "^3.5.1", 17 | "body-parser": "^1.18.2", 18 | "cors": "^2.8.4", 19 | "express": "^4.16.2", 20 | "express-jwt": "^5.3.0", 21 | "jsonwebtoken": "^8.1.0", 22 | "mongoose": "^4.13.0", 23 | "mongoose-paginate": "^5.0.3", 24 | "path": "^0.12.7" 25 | }, 26 | "devDependencies": { 27 | "nodemon": "^1.12.1" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const bodyParser = require('body-parser'); 3 | const path = require('path'); 4 | const cors = require('cors'); 5 | const expressJwt = require('express-jwt'); 6 | const app = express(); 7 | 8 | // Parsers 9 | app.use(cors()); 10 | app.use(bodyParser.json()); 11 | app.use(bodyParser.urlencoded({ extended: false})); 12 | 13 | // Angular DIST output folder 14 | app.use(express.static(path.join(__dirname, 'dist'))); 15 | 16 | // use JWT auth to secure the api, the token can be passed in the authorization header or querystring 17 | app.use(expressJwt({ 18 | secret: 'secretcode_jasndkasjdbajhsbdjhbasjd', 19 | getToken: req => { 20 | if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') { 21 | return req.headers.authorization.split(' ')[1]; 22 | } else if (req.query && req.query.token) { 23 | return req.query.token; 24 | } 25 | return null; 26 | } 27 | }).unless({ path: ['/images/', '/user/authenticate', '/user/register'] })); 28 | 29 | // Routes 30 | app.use('/user', require('./api/routes/user.route')); 31 | app.use('/stats', require('./api/routes/stats.route')); 32 | app.use('/messages', require('./api/routes/messages.route')); 33 | 34 | // Start the server 35 | const port = process.env.PORT || '3003'; 36 | app.listen(port, () => console.log(`Running on localhost:${port}`)); --------------------------------------------------------------------------------