Subjects.js
722 Bytes
const express = require("express");
const mysql2 = require("mysql2/promise");
const { connectOption } = require("../libs/MySQL");
const subjectsRouter = express.Router();
async function route() {
const connection = await mysql2.createConnection(connectOption);
// (ID) => null | name //unused
subjectsRouter.get("/", async (req, res) => {
console.log("/db/subjects");
try {
const queryString = `
SELECT name FROM subjects sbj
WHERE sbj.ID = ${req.query.ID}`;
const [results] = await connection.query(queryString);
res.send(results.length && results[0].name);
} catch (e) {
console.log(e);
res.end();
}
});
}
route();
module.exports = subjectsRouter;