Skip to content

Commit

Permalink
First and final
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-sna committed Jan 10, 2018
0 parents commit 4666d03
Show file tree
Hide file tree
Showing 40 changed files with 35,315 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# express-react-webpack-babel-boilerplate
This a boilerplate for MERN stack Applications that provides both developer and production builds.
In order to use the boilerplate, use the following instruction
1. npm install
To install all the dependencies

2. npm start
To start the node server with the Webpack development build.

3. npm run build
To get the production build of the modules. Then run "node index" to statr the server
11 changes: 11 additions & 0 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mysql = require('mysql');

module.exports = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: '',
database: 'employee'
});

module.exports.tableName = 'data';
module.exports.sessionTableName = 'session';
183 changes: 183 additions & 0 deletions database/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
const
mysql = require('mysql'),
db = require('../config/db'),
hashForPass = 'F25900499E177CAEF2344630A93AD1DDF43CF47',
crypto = require('crypto');

function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}

db.connect(function (err) {
if (err) {
if (err.code === 'ECONNREFUSED') return console.error('ERROR: DATABASE IS OFFLINE.');
console.error('ERROR ' + err.stack);
return;
}

console.log('SUCCESS: Connected to the database.');
});

module.exports = {

// SEARCH
search(query, callback) {
// console.log(query);

if (query.key && query.value) {
let statement = `SELECT * FROM ${db.tableName} WHERE ${query.key.toLowerCase()} = ${db.escape(query.value)}`;
db.query(statement, function (error, results, fields) {
if (error) return callback(error, null);
return callback(null, results);
});
}

// from and to should be string
else if (query.key && query.range && query.range.from && query.range.to) {
db.query(`SELECT * FROM ${db.tableName} WHERE bps BETWEEN ${db.escape(query.range.from)} AND ${db.escape(query.range.to)} `, function (error, results, fields) {
if (error) return callback(error, null);
// console.log(results);
return callback(null, results);
});
}

else {
return callback(null, null);
}
},

// GET ALL DATA
getAll(callback) {
db.query(`SELECT * FROM ${db.tableName}`, function (error, results, fields) {
if (error) return callback(error, null);
return callback(null, results);
});
},

// ADD A DATA
add(data, callback) {
// console.log(data.data.name);

db.query(`INSERT INTO ${db.tableName} (name, father, dob, doj, regulardate, bps, designation, department,
qualification, certifications, cnic, cell, email, address, domicile, file,
employeeid, lpromo, ecat)
VALUES (
${ db.escape(data.data.name)},
${ db.escape(data.data.father)},
${ db.escape(data.data.dob)},
${ db.escape(data.data.doj)},
${ db.escape(data.data.regulardate)},
${ db.escape(data.data.bps)},
${ db.escape(data.data.designation)},
${ db.escape(data.data.department)},
${ db.escape(data.data.qualification)},
${ db.escape(data.data.certifications)},
${ db.escape(data.data.cnic)},
${ db.escape(data.data.cell)},
${ db.escape(data.data.email)},
${ db.escape(data.data.address)},
${ db.escape(data.data.domicile)},
${ db.escape(data.data.file)},
${ db.escape(data.data.employeeid)},
${ db.escape(data.data.lpromo)},
${ db.escape(data.data.ecat)}
)`, function (error, results, fields) {
if (error) return callback(error, null);
return callback(null, results);
});
},

bulkInsert(data, callback) {
data.splice(0, 1);

data.map((data, index) => {
let dataObject = {
// serial: data[0],
name: data[1],
father: data[2],
dob: data[3],
doj: data[4],

regulardate: data[5],
bps: data[6],
designation: data[7],
department: data[8],
qualification: data[9],

certifications: data[10],
cnic: data[11],
cell: data[12],
email: data[13],
address: data[14],

domicile: data[15],
file: data[16],
employeeid: data[17],
lpromo: data[18],
ecat: data[19]
};

this.add({ data : dataObject }, (err) => {
if (err) return callback(err, null);
});

if (index % 50 === 0) sleep(5000);
});

return callback(null, 'SUCCESS');
},

// UPDATE A DATA
update(data, callback) {
// console.log(data);
if(!(data.serial && data.field && data.value)) return callback('NODATA', null);

let statement = `UPDATE ${db.tableName} SET ${ data.field } = ${ db.escape(data.value) } WHERE employeeid = ${ db.escape(data.serial)}`;

// console.log(statement);

db.query(statement, function (error, results, fields) {
if (error) return callback(error, null);
return callback(null, results);
});
},

// REMOVE A DATA
remove(data, callback) {
if(!data) return callback('NODATA', null);
let statement = `DELETE FROM ${db.tableName} WHERE employeeid = ${db.escape(data.serial)}`;
db.query(statement, function (error, results, fields) {
if (error) return callback(error, null);
return callback(null, results);
});
},

authenticate(username, password, callback) {

let statement = `SELECT password FROM ${db.sessionTableName} WHERE username = ${db.escape(username)}`;

db.query(statement, (error, results, fields) => {
if (error || results.length === 0) return callback('FAIL');

const hash = crypto.createHmac('sha256', hashForPass).update(password).digest('hex');

if (hash === results[0].password) {

return callback(null, 'SUCCESS');
}
else return callback('FAIL', null);

});
}
}
116 changes: 116 additions & 0 deletions employee.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-- phpMyAdmin SQL Dump
-- version 4.7.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 08, 2018 at 05:36 PM
-- Server version: 10.1.29-MariaDB
-- PHP Version: 7.2.0

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `employee`
--

-- --------------------------------------------------------

--
-- Table structure for table `data`
--

CREATE TABLE `data` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`father` varchar(50) NOT NULL,
`dob` varchar(10) NOT NULL,
`doj` varchar(10) NOT NULL,
`regulardate` varchar(10) NOT NULL,
`bps` int(11) NOT NULL,
`designation` varchar(200) NOT NULL,
`department` varchar(100) NOT NULL,
`qualification` varchar(200) DEFAULT NULL,
`certifications` varchar(200) DEFAULT NULL,
`cnic` varchar(20) DEFAULT NULL,
`cell` varchar(15) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`address` varchar(200) DEFAULT NULL,
`domicile` varchar(50) DEFAULT NULL,
`file` varchar(10) DEFAULT NULL,
`employeeid` varchar(10) DEFAULT NULL,
`lpromo` varchar(200) DEFAULT NULL,
`ecat` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `data`
--

INSERT INTO `data` (`id`, `name`, `father`, `dob`, `doj`, `regulardate`, `bps`, `designation`, `department`, `qualification`, `certifications`, `cnic`, `cell`, `email`, `address`, `domicile`, `file`, `employeeid`, `lpromo`, `ecat`) VALUES
(1, 'Test Subject', 'dsads', '01-01-0001', '01-01-0001', '01-01-0001', 17, 'test', 'department of test', 'test degree', 'test certified', '12345-1234567-1', '1234-1234567', '[email protected]', 'Home sweet Home', '1', '000', '000', '01-01-0001', 'Test'),
(2, '', '', '', '', '', 0, '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(3, '', '', '', '', '', 0, '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(4, '', '', '', '', '', 0, '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(5, 'alpha', 'alpha', '1', '1', '1', 7, 'dsds', 'dsdsdsds', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(6, 'alpha', 'alpha', '1', '1', '1', 7, 'dsds', 'dsdsdsds', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(7, 'alpha', 'alpha', '1', '1', '1', 7, 'dsds', 'dsdsdsds', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(8, 'dsddsddsd', 'dsds', 'dsd', 'dsds', 'dsd', 7, 'dsdsdd', 'Director ORIC', 'dsdsds', 'dsd', 'dsd', 'sds', 'sdsd', 'sdsds', 'ds', 'dsdsd', 'sdsd', 'sdd', 'Contract');

-- --------------------------------------------------------

--
-- Table structure for table `session`
--

CREATE TABLE `session` (
`username` varchar(10) NOT NULL,
`password` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `session`
--

INSERT INTO `session` (`username`, `password`) VALUES
('admin', '8831c4271e2356d8aca19c8d0d8b66fdde48b0c759a5e84d3743b4b011f21080'),
('user', '5bee08aa20b56684abc6811657597da96dcb8d6634d73d149db8248c3cd900fb');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `data`
--
ALTER TABLE `data`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `session`
--
ALTER TABLE `session`
ADD PRIMARY KEY (`username`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `data`
--
ALTER TABLE `data`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Empty file added employee_info/src/index.jsx
Empty file.
8 changes: 8 additions & 0 deletions import.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
S. No.,Name,Father Name,DOB,Date of Join,Regular Date,BPS,Designation,Department,Qualification,Certifications,CNIC,Cell,Email,Address,Domicile,File,Employee ID,Last Promotion,Employee Category
1,Test Subject,Father Test Subject,01-01-0001,01-01-0001,01-01-0001,17,test,department of test,test degree,test certified,12345-1234567-1,1234-1234567,[email protected],Home sweet Home,1,000,000,01-01-0001,Test
2,munna,baby,01-01-0002,01-01-0002,01-01-0002,15,dhakkan,cs,ass,dsdasd,sad,dsa,d,sad,sads,a,,,
3,bhai,doll,01-01-0003,01-01-0003,01-01-0003,12,pateela,es,ass,dsad,dsa,dsa,sa,d,dsa,,dsad,sad,sd
4,mbbs,sone,01-01-0004,01-01-0004,01-01-0004,4,bottle,ds,sa,sad,dsa,dsa,sad,sad,dsa,d,dsad,dsa,dsa
5,dhinkchak ,di,01-01-0005,01-01-0005,01-01-0005,8,chappal,ds,sa,sad,dsa,sad,ad,ds,dsa,sad,dsad,sad,dsa
6,pooja,ye ,01-01-0006,01-01-0006,01-01-0006,6,mia,ds,dsad,sad,dsa,sads,ad,sad,sads,sad,,,dsa
7,selfie,dunya,01-01-0007,01-01-0007,01-01-0007,4,khalifa,as,sa,da,dsa,sa,sad,d,dsa,a,a,asdsa,ad
44 changes: 44 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Core or NPM Modules
const
express = require('express'),
app = express(),
bodyParser = require('body-parser'),
path = require('path'),
routes = require('./routes/index'),
session = require('express-session');

// Public directory
app.use('/static', express.static('./public'));

// View Configuration
app.set('view engine', 'ejs')

// Middlewares
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(session({
secret: 'keyboard cat',
cookie: { maxAge: 60000 },
saveUninitialized: false,
resave: false
}));

// Routes
app.use(routes);

app.get(['/', '/dock', '/admin'], (req, res) => {
res.render('index.ejs');
});

app.get('*', (req, res) => {
res.send(req.session.user);
});

app.get('/test', (req, res) => {
res.render('test.ejs');
});

// Server
app.listen(process.env.PORT || 3000, () => {
console.log('Server listening at port: ', process.env.PORT || 3000);
});
Loading

0 comments on commit 4666d03

Please sign in to comment.