const express = require('express'); const sha256 = require("sha256"); const { getConnection, getUser, addUser } = require('../libs/mysql'); const router = express.Router(); router.get('/:id', async (req, res) => { const id = req.params.id; const connection = await getConnection(); const users = await getUser(connection, id); connection.end(); if (users[0]) { res.send(users[0]); } else { res.send('No user found'); } }); router.post('/add', async (req, res) => { const { username, password } = req.body; const connection = await getConnection(); const hash = sha256(password); await addUser(connection, username, hash); connection.end(); res.send({ message: 'User added' }); }); module.exports = router;