Skip to content

Commit

Permalink
modification
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jul 6, 2020
1 parent 03d7fb8 commit 8c91cee
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 333 deletions.
15 changes: 5 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ const {
allowInsecurePrototypeAccess,
} = require("@handlebars/allow-prototype-access");
const path = require(`path`);
const session = require("express-session");
const flash = require("connect-flash");
const SERVER_PORT = process.env.PORT || 8787;
const project = require(`./routes/project`);
const feature = require(`./routes/feature`);
const admin = require(`./routes/admin`);
const bug = require(`./routes/bug`);
const error = require(`./routes/error`);
const api = require(`./routes/api`);
const session = require("express-session");
const flash = require("connect-flash");
const Project = require(`./models/Project`);
const FeatureStatus = require(`./models/FeatureStatus`);
const StatusProgress = require(`./models/StatusProgress`);
const SERVER_PORT = process.env.PORT || 8787;

app.use(
session({ secret: "keyboardCat", resave: false, saveUninitialized: true })
session({ secret: "trackpath", resave: false, saveUninitialized: true })
);
app.use(flash());
app.use(function (req, res, next) {
app.use((req, res, next) => {
console.log("ACESSANDO MIDDLEWARE...");

res.setHeader("Access-Control-Allow-Origin", "*");
Expand Down Expand Up @@ -59,7 +55,6 @@ app.use(`/project`, project);
app.use(`/feature`, feature);
app.use(`/admin`, admin);
app.use(`/bug`, bug);
app.use(`/error`, error);
app.use(`/api`, api);

app.listen(SERVER_PORT, () => {
Expand Down
68 changes: 36 additions & 32 deletions models/Bug.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
const mysql = require("mysql");
const connection = require("../db/connection");
const mysql = require("mysql");

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}")`;
const create = (bug) => {
return new Promise((resolve, reject) => {
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);
connection.query(sql, (err, result) => {
err ? reject() : resolve(result);
});
});
};

const updateSolveIssue = async function (bug, callback) {
let sql = `update bugs as b
SET b.Summary = "${bug.Summary}", b.StatusID = "${bug.featureStatus}" where b.ID=${bug.bugID}`;
const updateSolveIssue = (bug) => {
return new Promise((resolve, reject) => {
let sql = `update bugs as b
SET b.Summary = "${bug.Summary}", b.StatusID = "${
bug.featureStatus
}" where b.ID=${mysql.escape(bug.bugID)}`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const findByPK = async function (id, callback) {
let sql = `SELECT b.ID, b.Title, b.Summary, b.EstimatedHours,DATE_FORMAT(b.DeliveryDate,'%Y-%m-%d') as DeliveryDate, DATE_FORMAT(b.CreatedAt,'%Y-%m-%d') as CreatedAt,b.ProjectID,b.StatusID,b.SeverityID,b.PriorityID
const findByPK = (id) => {
return new Promise((resolve, reject) => {
let sql = `SELECT b.ID, b.Title, b.Summary, b.EstimatedHours,DATE_FORMAT(b.DeliveryDate,'%Y-%m-%d') as DeliveryDate, DATE_FORMAT(b.CreatedAt,'%Y-%m-%d') as CreatedAt,b.ProjectID,b.StatusID,b.SeverityID,b.PriorityID
FROM bugs as b
where b.ID =${id}`;
where b.ID =${mysql.escape(id)}`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result[0]);
});
});
};

const findAll = async function (callback) {
let sql = `select * from bugs`;
const findAll = () => {
return new Promise((resolve, reject) => {
let sql = `select * from bugs`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const getBugsByProject = (id) => {
return new Promise((resolve, reject) => {
let sql = `select * from bugs where projectid=${mysql.escape(id)}`;
let sql = `select * from bugs where projectid=${mysql.escape(
id
)} order by ID desc`;
connection.query(sql, (err, results) => {
err ? reject(err) : resolve(results);
});
Expand Down
108 changes: 60 additions & 48 deletions models/Feature.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,86 @@
const connection = require("../db/connection");
const mysql = require("mysql");

const create = async function (feature, callback) {
let sql = `insert into Features (TitleFeature, DescriptionFeature, EstimatedTime, DeliveryDate,
CreatedAt, ProjectID, FeatureStatusID, StatusProgressID)
values
("${feature.TitleFeature}", "${feature.DescriptionFeature}", ${feature.EstimatedTime},
STR_TO_DATE('${feature.DeliveryDate}', '%Y-%m-%d'), STR_TO_DATE('${feature.CreatedAt}', '%Y-%m-%d'),
${feature.ProjectID},${feature.FeatureStatusID},${feature.StatusProgressID})`;
const create = (feature) => {
return new Promise((resolve, reject) => {
let sql = `insert into Features (TitleFeature, DescriptionFeature, EstimatedTime, DeliveryDate,
CreatedAt, ProjectID, FeatureStatusID, StatusProgressID)
values
("${feature.TitleFeature}", "${feature.DescriptionFeature}", ${feature.EstimatedTime},
STR_TO_DATE('${feature.DeliveryDate}', '%Y-%m-%d'), STR_TO_DATE('${feature.CreatedAt}', '%Y-%m-%d'),
${feature.ProjectID},${feature.FeatureStatusID},${feature.StatusProgressID})`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback();
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const findFeaturesByProjects = async function (projectID, callback) {
let sql = `select * from features as f
where f.ProjectID = ${projectID} ORDER BY ID DESC`;
const findAll = () => {
return new Promise((resolve, reject) => {
let sql = `select * from features as f`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const findAll = async function (callback) {
let sql = `select * from features as f`;
const findByPK = (id) => {
return new Promise((resolve, reject) => {
let sql = `select f.ID, f.TitleFeature, f.DescriptionFeature, f.EstimatedTime, DATE_FORMAT(f.DeliveryDate,'%Y-%m-%d') as DeliveryDate,
DATE_FORMAT( f.CreatedAt,'%Y-%m-%d') as CreatedAt, f.ProjectID, f.FeatureStatusID,
f.StatusProgressID from features as f where f.ID =${mysql.escape(id)}`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result[0]);
});
});
};

const findByPK = async function (ID, callback) {
let sql = `select f.ID, f.TitleFeature, f.DescriptionFeature, f.EstimatedTime, DATE_FORMAT(f.DeliveryDate,'%Y-%m-%d') as DeliveryDate,
DATE_FORMAT( f.CreatedAt,'%Y-%m-%d') as CreatedAt, f.ProjectID, f.FeatureStatusID,
f.StatusProgressID from features as f where f.ID =${ID}`;
const findFeaturesByProjects = (id) => {
return new Promise((resolve, reject) => {
let sql = `select * from features as f
where f.ProjectID = ${mysql.escape(id)} ORDER BY ID DESC`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const update = async function (ID, callback) {
let sql = `UPDATE features as f
SET f.TitleFeature = '${obj.StartDate}', f.DescriptionFeature = '${obj.StartDate}', f.EstimatedTime = '${obj.StartDate}', f.DeliveryDate = STR_TO_DATE('${obj.StartDate}', '%Y-%m-%d'), f.CreatedAt = STR_TO_DATE('${obj.StartDate}', '%Y-%m-%d'), f.FeatureStatusID = ${obj.StartDate}, f.StatusProgressID = ${obj.StartDate}
WHERE f.ID =${obj.StartDate}`;
const update = (obj) => {
return new Promise((resolve, reject) => {
let sql = `UPDATE features as f
SET f.TitleFeature = '${obj.StartDate}', f.DescriptionFeature = '${
obj.StartDate
}', f.EstimatedTime = '${obj.StartDate}', f.DeliveryDate = STR_TO_DATE('${
obj.StartDate
}', '%Y-%m-%d'), f.CreatedAt = STR_TO_DATE('${
obj.StartDate
}', '%Y-%m-%d'), f.FeatureStatusID = ${
obj.StartDate
}, f.StatusProgressID = ${obj.StartDate}
WHERE f.ID =${mysql.escape(obj.id)}`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const updateSolveIssue = async function (feature, callback) {
let sql = `UPDATE features as f
SET f.DescriptionFeature = '${feature.DescriptionFeature}', f.FeatureStatusID = ${feature.FeatureStatusID}, f.StatusProgressID = ${feature.StatusProgressID}
WHERE f.ID =${feature.ID}`;
const updateSolveIssue = (feature) => {
return new Promise((resolve, reject) => {
let sql = `UPDATE features as f
SET f.DescriptionFeature = '${
feature.DescriptionFeature
}', f.FeatureStatusID = ${feature.FeatureStatusID},
f.StatusProgressID = ${feature.StatusProgressID}
WHERE f.ID =${mysql.escape(feature.ID)}`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

Expand Down
73 changes: 38 additions & 35 deletions models/Project.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
const mysql = require("mysql");
const connection = require("../db/connection");
const mysql = require("mysql");

const create = async function (obj, callback) {
let sql = `INSERT INTO projects (NameProject,StartDate,EndDate,DescriptionProject,StatusID)
VALUES ('${obj.NameProject}',STR_TO_DATE('${obj.StartDate}', '%Y-%m-%d'),STR_TO_DATE('${obj.EndDate}', '%Y-%m-%d'),'${obj.DescriptionProject}',${obj.StatusID})`;
const create = (project) => {
return new Promise((resolve, reject) => {
let sql = `INSERT INTO projects (NameProject,StartDate,EndDate,DescriptionProject,StatusID)
VALUES ('${project.NameProject}',STR_TO_DATE('${project.StartDate}',
'%Y-%m-%d'),STR_TO_DATE('${project.EndDate}', '%Y-%m-%d'),
'${project.DescriptionProject}',${project.StatusID})`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback();
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

const update = async function (obj, callback) {
let sql = `update projects
set NameProject = '${obj.NameProject}' ,
StartDate = STR_TO_DATE('${obj.StartDate}', '%Y-%m-%d'),
EndDate = STR_TO_DATE('${obj.EndDate}', '%Y-%m-%d') ,
DescriptionProject = '${obj.DescriptionProject}', StatusID = ${obj.StatusID}
where ID = ${obj.ID}`;
connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback();
const update = (project) => {
return new Promise((resolve, reject) => {
let sql = `update projects
set NameProject = '${project.NameProject}' ,
StartDate = STR_TO_DATE('${project.StartDate}', '%Y-%m-%d'),
EndDate = STR_TO_DATE('${project.EndDate}', '%Y-%m-%d') ,
DescriptionProject = '${project.DescriptionProject}', StatusID = ${project.StatusID}
where ID = ${project.ID}`;

connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
});
});
};

Expand All @@ -40,28 +43,28 @@ const findAll = () => {
});
};

const findByPK = async function (id, 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
where p.id=${mysql.escape(id)}`;
const findByPK = (id) => {
return new Promise((resolve, reject) => {
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
where p.id=${mysql.escape(id)}`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result[0]);
});
});
};

const remove = async function (id, callback) {
let sql = `delete from projects
const remove = (id) => {
return new Promise((resolve, reject) => {
let sql = `delete from projects
where id=${mysql.escape(id)}`;

connection.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result[0]);
});
});
};

Expand Down
13 changes: 1 addition & 12 deletions models/StatusProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,4 @@ const findAll = () => {
});
};

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

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

module.exports = { findByPK: findByPK, findAll: findAll };
module.exports = { findAll: findAll };
Loading

0 comments on commit 8c91cee

Please sign in to comment.