Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jun 27, 2020
1 parent 0b4a781 commit 77d64b8
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 189 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const path = require(`path`);
const project = require(`./routes/project`);
const feature = require(`./routes/feature`);
const admin = require(`./routes/admin`);
const bug = require(`./routes/bug`);
const session = require("express-session");
const flash = require("connect-flash");
const StatusProject = require(`./models/StatusProject`);
Expand Down Expand Up @@ -56,6 +57,7 @@ app.use(express.static(path.join(__dirname, `public`)));
app.use(`/project`, project);
app.use(`/feature`, feature);
app.use(`/admin`, admin);
app.use(`/bug`, bug);

app.get("/", function (req, res) {
res.render(`index`);
Expand Down
30 changes: 30 additions & 0 deletions models/Bug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const connection = require("../db/connection");

const create = async function (bug, callback) {
let sql = `INSERT INTO bugs
(Title, Summary, EstimatedHours, DeliveryDate, CreatedAt, ProjectID, StatusID, SeverityID, PriorityID)
VALUES
("${bug.Title}", "${bug.Summary}", "${bug.EstimatedHours}", STR_TO_DATE('${bug.DeliveryDate}', '%Y-%m-%d'),
STR_TO_DATE('${bug.CreatedAt}', '%Y-%m-%d'), "${bug.ProjectID}", "${bug.StatusID}", "${bug.SeverityID}", "${bug.PriorityID}")`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
});
};

const findAll = async function (callback) {
let sql = `select * from bugs`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
});
};

module.exports = {
create: create,
findAll: findAll,
};
6 changes: 0 additions & 6 deletions models/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const create = async function (feature, callback) {

connection.query(sql, function (err, result) {
if (err) throw err;
//con.destroy();
console.log(sql);
return callback();
});
Expand All @@ -23,7 +22,6 @@ const findFeaturesByProjects = async function (projectID, callback) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//con.destroy();
return callback(result);
});
};
Expand All @@ -34,7 +32,6 @@ const findAll = async function (callback) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//con.destroy();
return callback(result);
});
};
Expand All @@ -47,7 +44,6 @@ const findByPK = async function (ID, callback) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//con.destroy();
return callback(result[0]);
});
};
Expand All @@ -60,7 +56,6 @@ const update = async function (ID, callback) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//con.destroy();
return callback(result[0]);
});
};
Expand All @@ -73,7 +68,6 @@ const updateSolveIssue = async function (feature, callback) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//con.destroy();
return callback(result[0]);
});
};
Expand Down
27 changes: 5 additions & 22 deletions models/FeatureStatus.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const mysql = require("mysql");
const HOST = "localhost";
const USER = "root";
const PASSWORD = "123456";
const DATABASE = "trackpath";
const connection = require("../db/connection");
const STATUS = {
OPEN: 1,
IN_PROGRESS: 2,
Expand All @@ -11,25 +7,12 @@ const STATUS = {
};

const findAll = async function (callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password: PASSWORD,
database: DATABASE,
});
let sql = `SELECT * FROM FeatureStatus`;

con.connect(async function (err) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log("Connected!");

let sql = `SELECT * FROM FeatureStatus`;

con.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
con.destroy();
return callback(result);
});
console.log(sql);
return callback(result);
});
};

Expand Down
13 changes: 13 additions & 0 deletions models/Priority.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const connection = require("../db/connection");

const findAll = async function (callback) {
let sql = `SELECT * FROM Priority`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
});
};

module.exports = { findAll: findAll };
9 changes: 2 additions & 7 deletions models/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const create = async function (obj, callback) {

connection.query(sql, function (err, result) {
if (err) throw err;
//connection.end();
console.log(sql);
return callback();
});
Expand All @@ -22,9 +21,7 @@ const update = async function (obj, callback) {
where ID = ${obj.ID}`;
connection.query(sql, function (err, result) {
if (err) throw err;
//con.end();
console.log(sql);
console.log(result);
return callback();
});
};
Expand All @@ -33,11 +30,11 @@ const findAll = async function (callback) {
let sql = `select p.ID as ID, p.NameProject, DATE_FORMAT(p.StartDate,'%Y-%m-%d') as StartDate , DATE_FORMAT(p.EndDate,'%Y-%m-%d') as EndDate, p.DescriptionProject, sp.ID as StatusID, sp.StatusName
from projects as p
inner join statusproject as sp
on p.StatusID = sp.ID`;
on p.StatusID = sp.ID
ORDER BY ID DESC`;
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//connection.end();
return callback(result);
});
};
Expand All @@ -52,7 +49,6 @@ const findByPK = async function (id, callback) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
//con.destroy();
return callback(result[0]);
});
};
Expand All @@ -63,7 +59,6 @@ const remove = async function (id, callback) {

connection.query(sql, async function (err, result) {
if (err) throw err;
//con.destroy();
console.log(sql);
return callback(result[0]);
});
Expand Down
13 changes: 13 additions & 0 deletions models/Severity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const connection = require("../db/connection");

const findAll = async function (callback) {
let sql = `SELECT * FROM Severity`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
});
};

module.exports = { findAll: findAll };
27 changes: 5 additions & 22 deletions models/StatusProgress.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
const mysql = require("mysql");
const HOST = "localhost";
const USER = "root";
const PASSWORD = "123456";
const DATABASE = "trackpath";
const connection = require("../db/connection");
const StatusProgressValue = {
NOT_STARTED: 6,
DONE: 10,
};

const findAll = async function (callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password: PASSWORD,
database: DATABASE,
});
let sql = `SELECT * FROM StatusProgress`;

con.connect(async function (err) {
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log("Connected!");

let sql = `SELECT * FROM StatusProgress`;

con.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
con.destroy();
return callback(result);
});
console.log(sql);
return callback(result);
});
};

Expand Down
93 changes: 25 additions & 68 deletions models/StatusProject.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,35 @@
const mysql = require("mysql");
const HOST = "localhost"
const USER = "root"
const PASSWORD = "123456"
const DATABASE = "trackpath"


const create = async function(obj, callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password:PASSWORD ,
database: DATABASE,
});

con.connect(async function(err) {
if (err) throw err;
console.log("Connected!");
let sql = `INSERT INTO StatusProject (${obj.field}) VALUES ('${obj.value}')`;
con.query(sql, function(err, result) {
if (err) throw err;
con.destroy();
console.log(sql);
findByPK(result.insertId, function(result) {
return callback(result);
});
});
const connection = require("../db/connection");

const create = async function (obj, callback) {
let sql = `INSERT INTO StatusProject (${obj.field}) VALUES ('${obj.value}')`;
connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
findByPK(result.insertId, function (result) {
return callback(result);
});
});
};

const findAll = async function(callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password:PASSWORD ,
database: DATABASE,
});

con.connect(async function(err) {
if (err) throw err;
console.log("Connected!");

let sql = `SELECT * FROM statusproject`;

con.query(sql, async function(err, result) {
if (err) throw err;
console.log(sql);
con.destroy();
return callback(result);
});
});
const findAll = async function (callback) {
let sql = `SELECT * FROM statusproject`;
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
});
};

const findByPK = async function(id, callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password:PASSWORD ,
database: DATABASE,
});

con.connect(async function(err) {
if (err) throw err;
console.log("Connected!");

let sql = `SELECT * FROM statusproject
const findByPK = async function (id, callback) {
let sql = `SELECT * FROM statusproject
where id=${mysql.escape(id)}`;

con.query(sql, async function(err, result) {
if (err) throw err;
console.log(sql);
con.destroy();
return callback(result[0]);
});
});
connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
});
};

module.exports = { create: create, findByPK: findByPK, findAll: findAll };
module.exports = { create: create, findByPK: findByPK, findAll: findAll };
11 changes: 0 additions & 11 deletions models/db.js

This file was deleted.

24 changes: 7 additions & 17 deletions public/js/lib.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
function w3_open() {
document.getElementById("main").style.marginLeft = "25%";
document.getElementById("mySidebar").style.width = "25%";
document.getElementById("mySidebar").style.display = "block";
document.getElementById("openNav").style.display = 'none';
document.getElementById("main").style.marginLeft = "25%";
document.getElementById("mySidebar").style.width = "25%";
document.getElementById("mySidebar").style.display = "block";
document.getElementById("openNav").style.display = "none";
}

function w3_close() {
document.getElementById("main").style.marginLeft = "0%";
document.getElementById("mySidebar").style.display = "none";
document.getElementById("openNav").style.display = "inline-block";
document.getElementById("main").style.marginLeft = "0%";
document.getElementById("mySidebar").style.display = "none";
document.getElementById("openNav").style.display = "inline-block";
}

// Get the modal
var modal = document.getElementById('id01');

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
Loading

0 comments on commit 77d64b8

Please sign in to comment.