Skip to content

Commit

Permalink
project update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jun 19, 2020
0 parents commit eac5db7
Show file tree
Hide file tree
Showing 56 changed files with 30,841 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const express = require("express");
const app = express();
const handlebars = require("express-handlebars");
const Handlebars = require("handlebars");
const bodyparser = require(`body-parser`);
const {
allowInsecurePrototypeAccess,
} = require("@handlebars/allow-prototype-access");
const path = require(`path`);
const project = require(`./routes/project`);
const feature = require(`./routes/feature`);
const session = require("express-session");
const flash = require("connect-flash");
const StatusProject = require(`./models/StatusProject`);
const Project = require(`./models/Project`);
const FeatureStatus = require(`./models/FeatureStatus`);
const SERVER_PORT = 8787;

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

res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS, PUT, PATCH, DELETE"
);
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
res.setHeader("Access-Control-Allow-Credentials", true);

res.locals.success_msg = req.flash("success_msg");
res.locals.error_msg = req.flash("error_msg");

next();
});

app.engine(
`handlebars`,
handlebars({
defaultLayout: `main`,
handlebars: allowInsecurePrototypeAccess(Handlebars),
})
);
app.set(`view engine`, `handlebars`);
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json());
app.use(express.static(path.join(__dirname, `public`)));
app.use(`/project`, project);
app.use(`/feature`, feature);

app.get("/", function (req, res) {
res.render(`index`);
});

app.get("/css", function (req, res) {
res.render(`teste_css`);
});

app.get(`/api`, (req, res) => {
StatusProject.findAll(async function (results) {
res.send(results);
});
});

app.get(`/api/getActiveProjects`, (req, res) => {
Project.findAll(async function (results) {
res.send(results);
});
});

app.get(`/api/getFeatureStatus`, (req, res) => {
FeatureStatus.findAll(async function (results) {
res.send(results);
});
});

app.listen(SERVER_PORT, function () {
console.log("SERVIDOR STARTED!");
});
Empty file added models/Bug.js
Empty file.
62 changes: 62 additions & 0 deletions models/Feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const mysql = require("mysql");
const HOST = "localhost";
const USER = "root";
const PASSWORD = "123456";
const DATABASE = "trackpath";

const create = async function (feature, 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 Features (TitleFeature, DescriptionFeature, EstimatedTime, DeliveryDate, CreatedAt, ProjectID, FeatureStatusID)
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})`;

console.log(sql);

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

const findFeaturesByProjects = async function (projectID, 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 features as f
where f.ProjectID = ${projectID}`;

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

module.exports = {
create: create,
findFeaturesByProjects: findFeaturesByProjects,
};
31 changes: 31 additions & 0 deletions models/FeatureStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const mysql = require("mysql");
const HOST = "localhost"
const USER = "root"
const PASSWORD = "123456"
const DATABASE = "trackpath"


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 FeatureStatus`;

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

module.exports = {findAll:findAll}
140 changes: 140 additions & 0 deletions models/Project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
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 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})`;
con.query(sql, function(err, result) {
if (err) throw err;
con.destroy();
console.log(sql);
console.log(result);
return callback();
});
});
};

const update = 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 = `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}`;
con.query(sql, function(err, result) {
if (err) throw err;
con.destroy();
console.log(sql);
console.log(result);
return callback();
});
});
};

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 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`;

con.query(sql, async function(err, result) {
if (err) throw err;
console.log(sql);
con.destroy();
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 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)}`;

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

const remove = 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 = `delete from projects
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]);
});
});
};

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

0 comments on commit eac5db7

Please sign in to comment.