Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaS7 committed Jan 8, 2024
1 parent b6258e9 commit d857ff2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
31 changes: 14 additions & 17 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const pool = require("./dbConfig");
const dotenv = require("dotenv");
dotenv.config({ path: "./env.default" });
const express = require("express");
const path = require('path');
const cors = require("cors");
import { query } from "./dbConfig";
import { config } from "dotenv";
config({ path: "./env.default" });
import express, { json, urlencoded } from "express";
import { join } from 'path';
import cors from "cors";

const app = express();

app.use(cors({ origin: '*' }));

app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(join(__dirname, 'public')));
app.get("/", (req, res) => {
// Redirect to the login.html page
console.log("Redirecting to login.html");
res.redirect("/login.html");
});

app.use(express.json()); // For parsing application/json
app.use(express.urlencoded({ extended: true })); // For parsing application/x-www-form-urlencoded
app.use(json()); // For parsing application/json
app.use(urlencoded({ extended: true })); // For parsing application/x-www-form-urlencoded
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ error: "Internal Server Error", message: err.message });
Expand All @@ -39,7 +39,7 @@ app.get("/api/database/search", async (req, res) => {
OR instrument LIKE ?
OR status LIKE ?
OR notes LIKE ?`;
const [search] = pool.query(searchSql, [`%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`]);
const [search] = query(searchSql, [`%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`]);

res.status(200).json({ search });
} catch (error) {
Expand All @@ -57,7 +57,7 @@ app.post("/api/database/new", async (req,res) => {
`SELECT * FROM prints
WHERE catalog_number LIKE ?`;

[check] = pool.query(checkExistingRecord, [catalog_number]);
[check] = query(checkExistingRecord, [catalog_number]);

if (check.length > 0) {
res.status(400).json({ message: "This is a Duplicate Entry" })
Expand All @@ -67,7 +67,7 @@ app.post("/api/database/new", async (req,res) => {
`INSERT INTO prints (catalog_number, artist, image, year, location, size, instrument, status, notes, date_sold)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;

pool.query(insertRecord, [
query(insertRecord, [
catalog_number,
artist,
image,
Expand Down Expand Up @@ -108,7 +108,7 @@ app.put("/api/database/update/:id", async (req, res) => {
date_sold = ?
WHERE idprints = ?`;

pool.query(updateRecord, [catalog_number, artist, image, year, location, size, instrument, status, notes, date_sold, printId]);
query(updateRecord, [catalog_number, artist, image, year, location, size, instrument, status, notes, date_sold, printId]);

res.status(200).json({ message: "Record updated!" });
} catch (error) {
Expand All @@ -118,11 +118,8 @@ app.put("/api/database/update/:id", async (req, res) => {
});





// Start the server
const PORT = process.env.PORT || 3000;
const PORT = process.env.PORT || 5501;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Expand Down
10 changes: 6 additions & 4 deletions server/dbConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const mysql = require('promise-mysql2');
require('dotenv').config();
import { createPool } from 'promise-mysql2';
import { config } from 'dotenv';

config({ path: './env.default' });

const dbConfig = {
host: process.env.DB_HOST,
Expand All @@ -13,6 +15,6 @@ const dbConfig = {
insecureAuth: false
};

const pool = mysql.createPool(dbConfig);
const pool = createPool(dbConfig);

module.exports = pool;
export default pool;

0 comments on commit d857ff2

Please sign in to comment.