main features working, UI and better date generation left
'
This commit is contained in:
+45
-1
@@ -1,6 +1,7 @@
|
||||
import express from "express";
|
||||
import mysql from "mysql2/promise";
|
||||
import { getTopTen } from "./db.js";
|
||||
import { resourceUsage } from "process";
|
||||
|
||||
export const connection = await mysql.createConnection({
|
||||
host: "localhost",
|
||||
@@ -14,7 +15,7 @@ const router = express.Router();
|
||||
|
||||
router.get("/getall", async (req, res) => {
|
||||
let sql =
|
||||
"SELECT u.f_name,u.l_name,u.mail,p.name,t.time,t.date \
|
||||
"SELECT u.f_name,u.l_name,u.mail,p.name,t.time,t.date,t.user \
|
||||
FROM Timelog t \
|
||||
INNER JOIN Project p ON p.id=t.project \
|
||||
INNER JOIN User u ON u.id=t.user ";
|
||||
@@ -127,6 +128,49 @@ router.get("/gettopten", async (req, res) => {
|
||||
|
||||
res.json(results2);
|
||||
});
|
||||
router.get("/reset", async (req, res) => {
|
||||
try {
|
||||
const [results, fields] = await connection.query("CALL InitDb;", []);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
res.status(200).json({ message: "Success" });
|
||||
});
|
||||
router.get("/getUser", async (req, res) => {
|
||||
const userId = req.query.userid;
|
||||
let results, fields;
|
||||
console.log(userId);
|
||||
try {
|
||||
[results, fields] = await connection.query(
|
||||
"SELECT p.name,t.time,t.project \
|
||||
FROM Timelog t \
|
||||
INNER JOIN Project p ON p.id=t.project \
|
||||
INNER JOIN User u ON u.id=t.user \
|
||||
WHERE USER = ? ;",
|
||||
[userId],
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
let projects = {};
|
||||
let projectIdtoName = {};
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
if (results[i].project in projects) {
|
||||
projects[results[i].project] += results[i].time;
|
||||
} else {
|
||||
projects[results[i].project] = results[i].time;
|
||||
projectIdtoName[results[i].project] = results[i].name;
|
||||
}
|
||||
}
|
||||
// map projectIds to project names before sending the data
|
||||
let respData = {};
|
||||
for (let key in projects) {
|
||||
if (projects.hasOwnProperty(key)) {
|
||||
respData[projectIdtoName[key]] = projects[key];
|
||||
}
|
||||
}
|
||||
res.json(respData);
|
||||
});
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
Reference in New Issue
Block a user