Skip to content

Commit

Permalink
Big yama! changes a lot of things.
Browse files Browse the repository at this point in the history
  • Loading branch information
EnginKARATAS committed Oct 5, 2021
1 parent 45aa813 commit 9218345
Show file tree
Hide file tree
Showing 314 changed files with 16,725 additions and 17,789 deletions.
97 changes: 88 additions & 9 deletions backend-weekly-report/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const crypto = require("crypto");
var jwt = require("jsonwebtoken");
const checkAuth = require("./src/middleware/checkAuth");
let origin = "http://10.41.150.82";
// let origin = "http://localhost:4200";
let host = "req.headers.host";

app.use(
Expand All @@ -33,6 +34,7 @@ const reportWorkerRouter = require("./src/route/reportWorker.route");
const reportRouter = require("./src/route/report.route");
const rowRouter = require("./src/route/row.route");
const templates = require("./src/mailTemplates/templates");
const checkGmAuth = require("./src/middleware/checkGmAuth");

app.use("/api/reports", reportRouter);
app.use("/api/rows", checkAuth, rowRouter);
Expand All @@ -42,6 +44,44 @@ app.use("/api/reports/worker", checkAuth, reportWorkerRouter);

server.listen(port, () => {});

app.post("/api/reports", checkAuth, function (req, res) {
const newReport = req.body
let checkData = [newReport.worker_id, newReport.week_id];
let data = [
newReport.is_report_sended,
newReport.week_id,
newReport.worker_id,
2,// newReport.claimant_id,
newReport.report_commit_date,
newReport.report_edit_date,
];
console.log("🚀 ~ file: app.js ~ line 51 ~ data", data)

let checkSql = "select * from reports where worker_id = ? AND week_id = ?";
let sql =
"INSERT INTO `reports` (`is_report_sended`, `week_id`, `worker_id`, `claimant_id`, `report_commit_date`, `report_edit_date`) VALUES (?, ?, ?, ?, ?, ?)";

con.query(checkSql, checkData, (err, rows, fields) => {
if (rows.length > 0) {
res.json({
message: "Haftalık raporunuz sistemde mevcuttur. Haftalık rapor, haftada bir kere oluşturulabilir",
resCode: 300,
});
} else {
con.query(sql, data, (err, row, fields) => {
console.log(row);
if (err) res.json(err, null);

res.json({
message: "Haftalık raporunuz eklenmiştir.",
resCode: 200,
data: row
});
});
}
});
});

app.delete("/deletereportbyid", checkAuth, (req, res) => {
sql = "";
});
Expand Down Expand Up @@ -116,11 +156,12 @@ app.post("/sendResetEmail", (req, res) => {
res.json(err);
} else {
let resetPasswordLink = `${origin}/#/set-password/${token}`;
let isimsoyisim = worker_name + " " + worker_surname
let html = templates.getHtmlResetPassword(isimsoyisim, resetPasswordLink);

let isimsoyisim = worker_name + " " + worker_surname;
let html = templates.getHtmlResetPassword(
isimsoyisim,
resetPasswordLink
);


mailer.sendMailToWorker(
email,
`${worker_name} ${worker_surname} Şifre sıfırlama talebi`,
Expand Down Expand Up @@ -224,7 +265,10 @@ app.post("/api/workers", checkAuth, function (req, res) {
let worker_email = req.body.worker_email;
let job_title = req.body.job_title;
let username = req.body.worker_email;
console.log("🚀 ~ file: app.js ~ line 227 ~ crypto.randomBytes ~ username", username)
console.log(
"🚀 ~ file: app.js ~ line 227 ~ crypto.randomBytes ~ username",
username
);
let token = buf.toString("hex");

let date = new Date();
Expand All @@ -236,7 +280,7 @@ app.post("/api/workers", checkAuth, function (req, res) {
let html = templates.getHtmlRegister(username, resetPasswordLink);

// let html = `Değerli çalışanımız, katana reporting uygulamasına davet edildiniz. Dilerseniz aşağıdaki linke tıklayark şifrenizi belirleyebilirsiniz
// <br>Kullanıcı adı: ${username} <br>şifre:belirlemek için bu linke <a href="${resetPasswordLink}">tıklayınız</a>`;
// <br>E-Posta: ${username} <br>şifre:belirlemek için bu linke <a href="${resetPasswordLink}">tıklayınız</a>`;
// // ${req.headers.host}
let data = [
worker_name,
Expand Down Expand Up @@ -290,7 +334,7 @@ app.post("/auth", function (request, response) {
} else {
response.json({
data: null,
message: "Kullanıcı adı veya şifre hatalı",
message: "E-Posta adı veya şifre hatalı",
resCode: 400,
token: "oluşturulmadı",
});
Expand All @@ -300,7 +344,7 @@ app.post("/auth", function (request, response) {
} else {
response.json({
data: null,
message: "Kullanıcı adı veya şifre hatalı",
message: "E-Posta veya şifre hatalı",
resCode: 403,
token: "oluşturulmadı",
});
Expand Down Expand Up @@ -357,13 +401,48 @@ app.get("/api/claimants", checkAuth, (req, res) => {
});
});

app.get("/getSendedReports", checkGmAuth, (req, res) => {
let sql = ` SELECT r.id, r.is_report_sended, w.week_name, w.week_id, concat(wo.worker_name, ' ', wo.worker_surname) as worker FROM reports r INNER JOIN
weeks w ON r.week_id = w.week_id INNER JOIN
workers wo ON r.worker_id = wo.id
where is_report_sended = 1`;

con.query(sql, (err, reports, fields) => {
if (err) res.json(err);

res.json({
message: "Gönderilen raporlar getirildi",
resCode: 200,
data: reports,
});
});
});

app.get("/getNoSendedReports", checkGmAuth, (req, res) => {
let sql = `
SELECT r.id, r.is_report_sended, w.week_name, w.week_id, concat(wo.worker_name, ' ', wo.worker_surname) as worker FROM reports r INNER JOIN
weeks w ON r.week_id = w.week_id INNER JOIN
workers wo ON r.worker_id = wo.id
where is_report_sended = 0`;

con.query(sql, (err, reports, fields) => {
if (err) res.json(err);

res.json({
message: "Gönderilmeyen raporlar getirildi",
resCode: 200,
data: reports,
});
});
});

app.get("/getWorkerByReport/:report_id", (req, res) => {
let report_id = parseInt(req.params.report_id);

let sql = `
select r.id, wee.week_id, w.worker_name, w.worker_surname, w.worker_email from workers w
inner JOIN reports r ON r.worker_id = w.id
Left join weeks wee ON r.week_id = wee.id
Left join weeks wee ON r.week_id = wee.week_id
left JOIN report_row_entries rre ON rre.report_id = r.id where r.id = ?
`;

Expand Down
26 changes: 5 additions & 21 deletions backend-weekly-report/src/controller/report.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,17 @@ let getSystemWeekOfYear = function () {
var week_of_year = Math.ceil((currentdate.getDay() + 1 + numberOfDays) / 7);
return week_of_year;
};
let ResponseModel = function () {
(this.message = ""), (this.resCode = 0);
};

exports.create = function (req, res) {
const newReport = new Report(req.body);
let rpmc = { ...ResponseModel };
if (newReport.week_id != getSystemWeekOfYear()) {
rpmc.message =
"Tarayıcınız ile sistemimizin tarih aralıkları aynı değildir. Lütfen tekrar deneyiniz.";
rpmc.resCode = 401;
res.json(rpmc);
}
// 400 = bad request
else if (req.body.constructor === Object && Object.keys(req.body).length === 0)
{
rpmc.message = "Kabul edilmeyen bir istekte bulunuldu";
rpmc.resCode = 402;
return res.json(rpmc);
res.json({message:"Tarayıcınız ile sistemimizin tarih aralıkları aynı değildir. Lütfen tekrar deneyiniz.", resCode:401});
}
else if (!newReport.week_id || !newReport.worker_id) {
rpmc.message = "Sistem yeni rapor eklerken hata verdi";
rpmc.resCode = 400;
return res.json(rpmc);
}

else {
Report.create(newReport, function (err, row) {
if (err) return res.status(500).send("Kayıt ederken hata meydana geldi");
if (err) return res.json({message:err, resCode:402});

return res.json(row);
});
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions backend-weekly-report/src/mailTemplates/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ function getHtmlRegister(username, resetPasswordLink) {
<tr>
<td class="bg_white email-section">
<div class="heading-section" style="text-align: center; padding: 0 30px;">
<h2>Kullanıcı Adı:</h2>
<h2>E-Posta:</h2>
<h2>${username}</h2>
<p>Şifre Sıfırlamak için aşağıdaki linke tıklayınız:</p>
<p>Şifre belirlemek için aşağıdaki linke tıklayınız:</p>
<a href="${resetPasswordLink}">Buraya tıkla</a>
</div>
<td valign="top" width="50%">
Expand Down
Loading

0 comments on commit 9218345

Please sign in to comment.