Files
whatsfreeinmyfree/backend/index.js
2026-03-18 23:52:28 +00:00

72 lines
1.7 KiB
JavaScript

import e from "express";
import cors from "cors";
import bodyParser from "body-parser";
import bcrypt from "bcrypt";
import Database from "better-sqlite3";
const app = e();
const port = 3000;
const db = new Database("./database.db");
app.use(cors());
app.use(e.json());
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.send("Hello World");
});
app.get('/currentRooms', (req, res) => {
// req has no data
// res has all room at current time
});
app.get('/addTimeslot', (req, res) => {
// req has roomid userid starttime and end time
// res has success or faliure
});
app.get('/addRoom', (req, res) => {
// req has userid and roomname
// res has success or faliure
});
app.get('/getRooms', (req, res) => {
// req has no data
// res has success or faliure
});
app.get('/createUser', (req, res) => {
// req has email pass(hashed) and name
// res has success or fail
});
app.post('/login', async (req, res) => {
// req has email and pass(hashed)
// res has success or fail
const body = req.body;
const stmt = db.prepare(`SELECT Pass FROM Users WHERE Email='${body.email}';`);
let storedHash = stmt.get();
if (!storedHash) {
res.status(400).send("problem with email");
return;
}
if (await bcrypt.compare(body.pass, storedHash.Pass)){
res.send(200);
} else {
res.status(400).send("incorrect password");
}
});
app.listen(port, () => {
console.log(`Listening on ${port}`);
// db = openDb();
// console.log("db opened");
});
// async function openDb () {
// return open({
// filename: '/tmp/database.db',
// driver: sqlite3.Database
// })
// }