Skip to content

Commit

Permalink
Modified the databse file
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentoti committed Aug 23, 2022
1 parent 3da9219 commit ee6377d
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 85 deletions.
10 changes: 5 additions & 5 deletions api/users/user.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { //We have to import all the controllers in the router
login,
getUsers,
createUsers
} = require('./user.controller');
} = require('./user.controller');

const router = require('express').Router();
const { checkToken } = require('../../auth/token_validation');
Expand All @@ -22,11 +22,11 @@ router.get('/getVisitors', checkToken, getVisitors);
router.get('/getVisitorsByVisitorId:id', checkToken, getVisitorsByVisitorId);
router.patch('/updateVisitors', checkToken, updateVisitors);
router.delete('/deleteVisitors', checkToken, deleteVisitors);
router.get('/getUserByUserId:id',checkToken, getUserByUserId);
router.get('/getUserByUserId:id', checkToken, getUserByUserId);
router.patch('/updateUsers', checkToken, updateUser);
router.delete('/deleteUser', checkToken, deleteUser);
router.post('/login', login); //used for login
router.get('/getUsers', checkToken, getUsers);
router.post('/createUsers', checkToken, createUsers);
router.post('/user/login', login); //used for login
router.get('/user/getUsers', getUsers);
router.post('/user/createUsers', createUsers);

module.exports = router;
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require('dotenv').config();
const express = require('express'); //creating express application
const cors = require("cors");
const app = express();
const app = express();
const corsOptions = {
origin: "http://localhost:3001"
} ;
};
const userRouter = require('./api/users/user.router'); //importing user.router //initializing express application


Expand All @@ -19,7 +19,7 @@ app.use(cors(corsOptions));
// });


app.use('/api/users', userRouter); //if any request comes we pass it to the userRouter route
app.use('/api', userRouter); //if any request comes we pass it to the userRouter route

app.listen(process.env.APP_PORT, () => {
console.log('Server up and running on port: ', process.env.APP_PORT);
Expand Down
10 changes: 5 additions & 5 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { createPool } = require('mysql');

const pool = createPool({
port:process.env.DB_PORT,
host:process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASS,
database:process.env.MYSQL_DB,
port: process.env.DB_PORT,
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.MYSQL_DB,
authKey: process.env.AUTH_KEY,
connectionLimit: 10
});
Expand Down
76 changes: 6 additions & 70 deletions database.sql
Original file line number Diff line number Diff line change
@@ -1,55 +1,7 @@
-- USER TYPE - LOOKUP TABLE
-- USER - BASE TABLE
-- VISITORS - BASE TABLE
-- DEPARTMENT - LOOKUP
-- GENDER - LOOKUP
-- PURPOSE - LOOKUP
-- CLOCKIN - BASE TABLE
------------------------------------

-- USER TYPE
-- ID
-- NAME

-- DEPARTMENT
-- ID
-- NAME

-- GENDER
-- ID
-- NAME

-- PURPOSE
-- ID
-- NAME

-- USER TABLE --
-- USER ID
-- USERRNAME
-- EMAIL
-- FIRST NAME
-- LAST LASTNAME
-- DEPARTMENT [LOOKUP DATA]
-- PHONE NUMBER
-- GENDER [LOOKUP DATA]

-- VISITORS
-- VISITOR ID int(11)
-- FULLNAME varchar(64)
-- WHOM TO SEE [USER ID] int fk from user table
-- PURPOSE [LOOK UP] int fk from purpose table
-- DATE ADDED timestamp
-- ADDRESS text

-- CLOCK IN
-- VISITOR ID [VISITOR TABLE] int fk from visitor table
-- TIME IN timestamp
-- TIME OUT timestamp default '0000-00-00 00:00:00'

DROP DATABASE IF EXISTS VMS;

CREATE DATABASE VMS;
USE VMS;
DROP DATABASE IF EXISTS vms;

CREATE DATABASE vms;
USE vms;

DROP TABLE IF EXISTS user_type;
CREATE TABLE user_type(
Expand Down Expand Up @@ -163,7 +115,7 @@ DROP TABLE IF EXISTS clock_in;
CREATE TABLE clock_in(
visitor_id int not null,
time_in timestamp,-- TIME IN timestamp,
time_out timestamp default '0000-00-00 00:00:00',
time_out timestamp default '1979-01-01 12:00:00',
CONSTRAINT FK_VISITORS PRIMARY KEY(visitor_id, time_in),
CONSTRAINT FK_VISITORS_ID FOREIGN KEY (visitor_id) references visitors(id)
);
Expand All @@ -173,20 +125,4 @@ INSERT INTO clock_in(visitor_id, time_in, time_out) VALUES(2, '2022-08-02', '000
INSERT INTO clock_in(visitor_id, time_in, time_out) VALUES(3, '2022-08-02', '0000-00-00');
INSERT INTO clock_in(visitor_id, time_in, time_out) VALUES(4, '2022-08-02', '0000-00-00');

SELECT * FROM clock_in;



SHOW TABLES;

DROP TABLE IF EXISTS student;

CREATE TABLE student (
student_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
gender VARCHAR(2),
email VARCHAR(25),
password TEXT,
phone_number VARCHAR(16)
);
SELECT * FROM clock_in;
Loading

0 comments on commit ee6377d

Please sign in to comment.