diff --git a/api/users/user.controller.js b/api/users/user.controller.js index aa8cb1d..2f8e2a2 100644 --- a/api/users/user.controller.js +++ b/api/users/user.controller.js @@ -14,8 +14,10 @@ const { createUsers, getVisitorPurpose, getAllVisitors, - getVisitorByFullname, - updateVisitorClockout + getVisitorByFullname, + updateVisitorClockout, + signedInVisitors, + clockoutTagNumber } = require('./user.service'); //we called the service @@ -98,7 +100,7 @@ module.exports = { }); }); }, -updateVisitorClockout: (req, res) => { + updateVisitorClockout: (req, res) => { const body = req.body; updateVisitorClockout(body, (err, results) => { if (err) { @@ -117,6 +119,25 @@ updateVisitorClockout: (req, res) => { }); }); }, + clockoutTagNumber: (req, res) => { + const body = req.body; + clockoutTagNumber(body, (err, results) => { + if (err) { + console.log(err); + return; + } + if(!results){ + return res.json({ + success: 0, + message: 'Invalid Tag Number' + }); + } + return res.json({ + success: 1, + message: 'updated successfully' + }); + }); + }, deleteVisitors: (req, res) => { const data = req.body; deleteVisitors(data, (err, results) =>{ @@ -167,7 +188,7 @@ updateVisitorClockout: (req, res) => { }); }); }, - getAllVisitors: (req, res) => { + getAllVisitors: (req, res) => { getAllVisitors((err, results) => { if (err) { console.log(err); @@ -178,7 +199,7 @@ updateVisitorClockout: (req, res) => { data: results }); }); -}, + }, getVisitorPurpose: (req, res) => { getVisitorPurpose((err, results) => { if (err) { @@ -192,7 +213,7 @@ updateVisitorClockout: (req, res) => { }); }, getVisitorsByVisitorId: (req, res) => { - const id = req.params.id; + const id = req.query.id; getVisitorsByVisitorId(id, (err, results) => { if (err) { console.log(err); @@ -305,7 +326,23 @@ updateVisitorClockout: (req, res) => { }); } //Now we are calling this service }); - } + }, + signedInVisitors: (req, res) => { + const fullname = req.query.fullname; + signedInVisitors(fullname, (err, results) => { + if (err) { + console.log(err); + return; + } + return res.json({ + success: 1, + data: results + }); + }); +}, +geTagNumber: (req, res) => { + +} }; //We have definded all the controllers, now it's time to define the route \ No newline at end of file diff --git a/api/users/user.router.js b/api/users/user.router.js index f402f6c..9e153b3 100644 --- a/api/users/user.router.js +++ b/api/users/user.router.js @@ -13,7 +13,9 @@ const { //We have to import all the controllers in the router getVisitorPurpose, getAllVisitors, getVisitorByFullname, - updateVisitorClockout + updateVisitorClockout, + signedInVisitors, + clockoutTagNumber } = require('./user.controller'); const router = require('express').Router(); @@ -24,8 +26,8 @@ const { checkToken } = require('../../auth/token_validation'); router.post('/visitor/createVisitors', checkToken, createVisitors); //we are passing the request to 'creatUser' in the user.controller router.get('/visitor/getVisitors', checkToken, getVisitors); //router.get('/visitor/getVisitors', checkToken, getVisitors); -router.get('/visitor/getAllVisitors', checkToken, getAllVisitors); -router.get('/visitor/getVisitorsByVisitorId:id', checkToken, getVisitorsByVisitorId); +router.get('/visitor/getAllVisitors', getAllVisitors); +router.get('/visitor/getVisitorsByVisitorId', getVisitorsByVisitorId); router.patch('/visitor/updateVisitors', checkToken, updateVisitors); router.delete('/visitor/deleteVisitors', checkToken, deleteVisitors); router.get('/user/getUserByUserId:id', checkToken, getUserByUserId); @@ -33,10 +35,14 @@ router.patch('/user/updateUsers', checkToken, updateUser); router.delete('/user/deleteUser', checkToken, deleteUser); router.post('/user/login', login); //used for login router.get('/user/getUsers', getUsers); -router.post('/user/createUsers', checkToken, createUsers); +router.post('/user/createUsers', createUsers); router.get('/visitor/getVisitorPurpose', getVisitorPurpose); router.get('/visitor/getVisitorByFullname', getVisitorByFullname); router.patch('/visitor/updateVisitorClockout', updateVisitorClockout); +router.get('/visitor/getVisitorByFullname', getVisitorByFullname); +router.get('/visitor/signedInVisitors', signedInVisitors); +router.patch('/visitor/clockoutTagNumber', clockoutTagNumber); + diff --git a/api/users/user.service.js b/api/users/user.service.js index 22e13cb..5478d07 100644 --- a/api/users/user.service.js +++ b/api/users/user.service.js @@ -52,6 +52,8 @@ module.exports = { return callBack(error); } signInVisitor(results); + addVisitorTag(results.insertId); + updateVisitorStatusFalse(); return callBack(null, results); } @@ -62,10 +64,11 @@ module.exports = { pool.query( ` select v.id as id, v.fullname as fullname, v.purpose_id as purpose, v.date_added as date_added, v.address as address, v.phone_number as phone_number, - c.time_in as time_in, c.time_out as time_out,u.first_name as first_name, u.last_name as last_name + c.time_in as time_in, c.time_out as time_out,u.first_name as first_name, u.last_name as last_name, t.tag as tag from clock_in c join visitors v on v.id = c.visitor_id join users u on u.id = v.user_id + join visitor_tag t on t.visitor_id = c.visitor_id where date(c.time_in) = current_date order by id desc `, @@ -155,13 +158,20 @@ module.exports = { }, getVisitorsByVisitorId: (id, callBack) => { pool.query( - `select fullname, user_id, purpose_id, date_added, address, phone_number from visitors where id=?`, + `select v.id as id, v.fullname as fullname, v.purpose_id as purpose, v.date_added as date_added, v.address as address, v.phone_number as phone_number, + c.time_in as time_in, c.time_out as time_out,u.first_name as first_name, u.last_name as last_name, t.tag as tag + from visitors v + join visitor_tag t on t.visitor_id = v.id + join clock_in c on v.id = c.visitor_id + join users u on u.id = v.user_id + where v.id like'%${id}%' + `, [id], (error, results, fields) => { if (error) { callBack(error); } - return callBack(null, results[0]); + return callBack(null, results); } ); }, @@ -205,6 +215,7 @@ module.exports = { ); }, updateVisitorClockout: (data, callBack) => { + updateVisitorStatusTrue(data) pool.query( `update clock_in set time_out = now() where visitor_id=? and time_out=?`, [ @@ -219,6 +230,30 @@ module.exports = { } ); }, + clockoutTagNumber: (data,callBack) => { + if (data.tag === data.tag_no) { + updateVisitorStatusTrue(data); + pool.query( + `update clock_in set time_out = now() where visitor_id=? and time_out=?`, + [ + data.id, + '2000-08-02 00:00:00' + ], + (error, results, fields) =>{ + if (error) { + callBack(error); + } + return callBack(null, results); + + } + ); + }else{ + const test = (error, results) =>{ + return callBack(null, results); + } + test(); + } + }, deleteVisitors: (data, callBack) => { pool.query( `delete from visitors where id = ?`, @@ -242,7 +277,28 @@ module.exports = { return callBack(null, results[0]); } ); - } + }, + signedInVisitors: (fullname, callBack) => { + pool.query( + ` + select v.id as id, v.fullname as fullname, v.purpose_id as purpose, v.date_added as date_added, v.address as address, v.phone_number as phone_number, + c.time_in as time_in, c.time_out as time_out,u.first_name as first_name, u.last_name as last_name + from clock_in c + join visitors v on v.id = c.visitor_id + join users u on u.id = v.user_id + where date(c.time_out) != current_date and date(c.time_in) = current_date and v.fullname like '%${fullname}%' + order by id desc + `, + [fullname], + (error, results, fields) => { + if (error) { + return callBack(error); + } + return callBack(null, results); + } + ); + }, + }; @@ -254,11 +310,60 @@ signInVisitor = (results) => { ], (error, results, fields) => { if (error) { - console.log(error); return error; } - console.log(results); return results; } ) -} \ No newline at end of file +} + +const addVisitorTag = (visitorId) =>{ + pool.query( + `SELECT tag_number FROM tag WHERE tag_status IS TRUE LIMIT 1`, + [], + (error, results, fields) => { + if (error) { + return error; + } + const tagNumb = JSON.parse(JSON.stringify(results)); + numb = tagNumb[0].tag_number; + const val = visitorId + " " + numb; + console.log(val); + pool.query( + `insert into visitor_tag(visitor_id,tag) values(?,?)`, + [visitorId,numb] + ) + } + ) +} + +const updateVisitorStatusFalse = () =>{ + pool.query( + `SELECT tag_number FROM tag WHERE tag_status IS TRUE LIMIT 1`, + [], + (error, results, fields) => { + if (error) { + return error; + } + const tagNumb = JSON.parse(JSON.stringify(results)); + numb = tagNumb[0].tag_number; + pool.query( + `update tag set tag_status = false where tag_number = ${numb}`, + [] + ) + } + ) +} +const updateVisitorStatusTrue = (data) =>{ + const tag = data.tag + pool.query( + `update tag set tag_status = true where tag_number = ${tag}`, + [], + (error, results, fields) => { + if (error) { + return error; + } + } + ) +} + diff --git a/database.sql b/database.sql index 69dd168..9157c81 100644 --- a/database.sql +++ b/database.sql @@ -1,124 +1,437 @@ +-- MariaDB dump 10.19 Distrib 10.4.24-MariaDB, for Win64 (AMD64) +-- +-- Host: localhost Database: vms +-- ------------------------------------------------------ +-- Server version 8.0.30 -DROP DATABASE IF EXISTS vms; - -CREATE DATABASE vms; -USE vms; - -DROP TABLE IF EXISTS user_type; -CREATE TABLE user_type( - id int not null primary key auto_increment, - `type` varchar(16) not null -); - -INSERT INTO user_type(type) VALUES('Admin'); -INSERT INTO user_type(type) VALUES('Staff'); -INSERT INTO user_type(type) VALUES('Visitor'); - - -SELECT * FROM user_type; - - -DROP TABLE IF EXISTS department; -CREATE TABLE department( - id int not null primary key auto_increment, - department varchar(16) not null -); - -INSERT INTO department(department) VALUES('BlackSentry'); -INSERT INTO department(department) VALUES('Cloud Unit'); -INSERT INTO department(department) VALUES('Customer Support'); -INSERT INTO department(department) VALUES('Procurement'); -INSERT INTO department(department) VALUES('Infrastructure'); -INSERT INTO department(department) VALUES('Engineering'); -INSERT INTO department(department) VALUES('IT Support'); -INSERT INTO department(department) VALUES('Product Unit'); - -SELECT * FROM department; - - - -DROP TABLE IF EXISTS gender; -CREATE TABLE gender( - id int not null primary key auto_increment, - gender varchar(16) not null -); - -INSERT INTO gender(gender) VALUES('M'); -INSERT INTO gender(gender) VALUES('F'); - -SELECT * FROM gender; - - -DROP TABLE IF EXISTS purpose; -CREATE TABLE purpose( - id int not null primary key auto_increment, - purpose varchar(16) not null -); - -INSERT INTO purpose(purpose) VALUES('enquiry'); -INSERT INTO purpose(purpose) VALUES('Job Application'); -INSERT INTO purpose(purpose) VALUES('Visiting'); -INSERT INTO purpose(purpose) VALUES('Appointment'); -INSERT INTO purpose(purpose) VALUES('Work'); - -SELECT * FROM purpose; - -DROP TABLE IF EXISTS users; -CREATE TABLE users( - id int not null primary key auto_increment, - username varchar(16) not null, - email varchar(32) not null, - first_name varchar(32) not null, - last_name varchar(32) not null, - phone_number varchar(16), - gender_id int not null, - department_id int not null, - password varchar(255) not null, - CONSTRAINT FK_DEPARTMENT FOREIGN KEY(department_id) REFERENCES department(id), - CONSTRAINT FK_GENDER FOREIGN KEY(gender_id) REFERENCES gender(id) -); - -INSERT INTO users(username, email, first_name, last_name, phone_number, gender_id, department_id, password) VALUES('zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 1, 'Playboy@123'); -INSERT INTO users(username, email, first_name, last_name, phone_number, gender_id, department_id, password) VALUES('Vincento', 'mrvincentito@gmail.com', 'VINCENT', 'ITO', '080467894132', 2, 2, 'Playboy@123'); -INSERT INTO users(username, email, first_name, last_name, phone_number, gender_id, department_id, password) VALUES('davido', 'david03@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 3, 'Playboy@123'); -INSERT INTO users(username, email, first_name, last_name, phone_number, gender_id, department_id, password) VALUES('zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 2, 4, 'Playboy@123'); -INSERT INTO users(username, email, first_name, last_name, phone_number, gender_id, department_id, password) VALUES('zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 1, 'Playboy@123'); -INSERT INTO users(username, email, first_name, last_name, phone_number, gender_id, department_id, password) VALUES('zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 1, 'Playboy@123'); - -SELECT * FROM users; - -DROP TABLE IF EXISTS visitors; -CREATE TABLE visitors( - id int(11) not null primary key auto_increment, - fullname varchar(64) not null, - user_id int null, - purpose_id int null, - date_added TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - address text, - CONSTRAINT FK_WHOM_TO_SEE FOREIGN KEY (user_id) references users(id), - CONSTRAINT FK_PURPOSE FOREIGN KEY(purpose_id) references purpose(id) -); - -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); -INSERT INTO visitors(fullname, user_id, purpose_id, date_added, address) VALUES('Mrs. Diya', 2, 2, '2022-08-02', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja' ); - -SELECT * FROM visitors; - - -DROP TABLE IF EXISTS clock_in; -CREATE TABLE clock_in( - visitor_id int not null, - time_in timestamp DEFAULT CURRENT_TIMESTAMP,-- TIME IN timestamp, - time_out timestamp default '2000-08-02 00:00:00', - CONSTRAINT FK_VISITORS PRIMARY KEY(visitor_id, time_in), - CONSTRAINT FK_VISITORS_ID FOREIGN KEY (visitor_id) references visitors(id) -); - - -SHOW TABLES; +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +-- +-- Table structure for table `clock_in` +-- + +DROP TABLE IF EXISTS `clock_in`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `clock_in` +( + `visitor_id` int NOT NULL, + `time_in` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `time_out` timestamp NULL DEFAULT '2000-08-01 23:00:00', + `tag` varchar +(3) DEFAULT NULL, + PRIMARY KEY +(`visitor_id`,`time_in`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `clock_in` +-- + +LOCK TABLES `clock_in` WRITE; +/*!40000 ALTER TABLE `clock_in` DISABLE KEYS */; +INSERT INTO ` +clock_in` +VALUES + (2, '2022-09-06 15:36:30', '2022-09-06 16:57:52', NULL), + (3, '2022-09-06 15:37:11', '2022-09-06 15:38:34', NULL), + (4, '2022-09-07 08:29:05', '2022-09-07 10:43:24', NULL), + (5, '2022-09-07 08:29:35', '2022-09-07 08:30:19', NULL), + (6, '2022-09-07 10:50:42', '2022-09-07 10:57:43', NULL), + (7, '2022-09-07 11:14:09', '2022-09-07 11:20:41', NULL), + (8, '2022-09-07 11:41:52', '2022-09-07 12:02:39', NULL), + (9, '2022-09-07 12:03:27', '2022-09-07 12:08:35', NULL); +/*!40000 ALTER TABLE `clock_in` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `department` +-- + +DROP TABLE IF EXISTS `department`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `department` +( + `id` int NOT NULL AUTO_INCREMENT, + `department` varchar +(16) NOT NULL, + PRIMARY KEY +(`id`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `department` +-- + +LOCK TABLES `department` WRITE; +/*!40000 ALTER TABLE `department` DISABLE KEYS */; +INSERT INTO ` +department` +VALUES + (1, 'BlackSentry'), + (2, 'Cloud Unit'), + (3, 'Customer Support'), + (4, 'Procurement'), + (5, 'Infrastructure'), + (6, 'Engineering'), + (7, 'IT Support'), + (8, 'Product Unit'); +/*!40000 ALTER TABLE `department` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `gender` +-- + +DROP TABLE IF EXISTS `gender`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `gender` +( + `id` int NOT NULL AUTO_INCREMENT, + `gender` varchar +(16) NOT NULL, + PRIMARY KEY +(`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `gender` +-- + +LOCK TABLES `gender` WRITE; +/*!40000 ALTER TABLE `gender` DISABLE KEYS */; +INSERT INTO ` +gender` +VALUES + (1, 'M'), + (2, 'F'); +/*!40000 ALTER TABLE `gender` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `purpose` +-- + +DROP TABLE IF EXISTS `purpose`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `purpose` +( + `id` int NOT NULL AUTO_INCREMENT, + `purpose` varchar +(16) NOT NULL, + PRIMARY KEY +(`id`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `purpose` +-- + +LOCK TABLES `purpose` WRITE; +/*!40000 ALTER TABLE `purpose` DISABLE KEYS */; +INSERT INTO ` +purpose` +VALUES + (1, 'enquiry'), + (2, 'Job Application'), + (3, 'Visiting'), + (4, 'Appointment'), + (5, 'Work'); +/*!40000 ALTER TABLE `purpose` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `tag` +-- + +DROP TABLE IF EXISTS `tag`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tag` +( + `tag_number` varchar +(3) NOT NULL, + `tag_status` tinyint +(1) DEFAULT NULL, + PRIMARY KEY +(`tag_number`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tag` +-- + +LOCK TABLES `tag` WRITE; +/*!40000 ALTER TABLE `tag` DISABLE KEYS */; +INSERT INTO ` +tag` +VALUES + ('001', 1), + ('002', 1), + ('003', 1), + ('004', 1), + ('005', 1), + ('006', 1), + ('007', 1), + ('008', 1), + ('009', 1), + ('010', 1), + ('011', 1), + ('012', 1), + ('013', 1), + ('014', 1), + ('015', 1), + ('016', 1), + ('017', 1), + ('018', 1), + ('019', 1), + ('020', 1), + ('021', 1), + ('022', 1), + ('023', 1), + ('024', 1), + ('025', 1), + ('026', 1), + ('027', 1), + ('028', 1), + ('029', 1), + ('030', 1), + ('031', 1), + ('032', 1), + ('033', 1), + ('034', 1), + ('035', 1), + ('036', 1), + ('037', 1), + ('038', 1), + ('039', 1), + ('040', 1), + ('041', 1), + ('042', 1), + ('043', 1), + ('044', 1), + ('045', 1), + ('046', 1), + ('047', 1), + ('048', 1), + ('049', 1), + ('050', 1); +/*!40000 ALTER TABLE `tag` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user_type` +-- + +DROP TABLE IF EXISTS `user_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user_type` +( + `id` int NOT NULL AUTO_INCREMENT, + `type` varchar +(16) NOT NULL, + PRIMARY KEY +(`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user_type` +-- + +LOCK TABLES `user_type` WRITE; +/*!40000 ALTER TABLE `user_type` DISABLE KEYS */; +INSERT INTO ` +user_type` +VALUES + (1, 'Admin'), + (2, 'Staff'), + (3, 'Visitor'); +/*!40000 ALTER TABLE `user_type` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `users` +-- + +DROP TABLE IF EXISTS `users`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `users` +( + `id` int NOT NULL AUTO_INCREMENT, + `username` varchar +(16) NOT NULL, + `email` varchar +(32) NOT NULL, + `first_name` varchar +(32) NOT NULL, + `last_name` varchar +(32) NOT NULL, + `phone_number` varchar +(16) DEFAULT NULL, + `gender_id` int NOT NULL, + `department_id` int NOT NULL, + `password` varchar +(255) NOT NULL, + PRIMARY KEY +(`id`), + KEY `FK_DEPARTMENT` +(`department_id`), + KEY `FK_GENDER` +(`gender_id`), + CONSTRAINT `FK_DEPARTMENT` FOREIGN KEY +(`department_id`) REFERENCES `department` +(`id`), + CONSTRAINT `FK_GENDER` FOREIGN KEY +(`gender_id`) REFERENCES `gender` +(`id`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `users` +-- + +LOCK TABLES `users` WRITE; +/*!40000 ALTER TABLE `users` DISABLE KEYS */; +INSERT INTO ` +users` +VALUES + (1, 'zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 1, 'Playboy@123'), + (2, 'Vincento', 'mrvincentito@gmail.com', 'VINCENT', 'ITO', '080467894132', 2, 2, 'Playboy@123'), + (3, 'davido', 'david03@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 3, 'Playboy@123'), + (4, 'zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 2, 4, 'Playboy@123'), + (5, 'zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 1, 'Playboy@123'), + (6, 'zach', 'civirzach@gmail.com', 'CIVIR-TER', 'ZACH-UKOH', '08130402087', 1, 1, 'Playboy@123'), + (7, 'alaba', 'alaba@gmail.com', 'david', 'David', '0841454545', 1, 1, '$2b$10$87jIxJAi7oyLzZaFAtIkTeIheQu1JSDXC2gYIKB0KZ/LAaAJzNJfa'); +/*!40000 ALTER TABLE `users` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `visitor_tag` +-- + +DROP TABLE IF EXISTS `visitor_tag`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `visitor_tag` +( + `visitor_id` int NOT NULL, + `tag` varchar +(3) DEFAULT NULL, + KEY `FK_VISITORS_ID` +(`visitor_id`), + KEY `FK_TAG_NUMBER` +(`tag`), + CONSTRAINT `FK_TAG_NUMBER` FOREIGN KEY +(`tag`) REFERENCES `tag` +(`tag_number`), + CONSTRAINT `FK_VISITORS_ID` FOREIGN KEY +(`visitor_id`) REFERENCES `visitors` +(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `visitor_tag` +-- + +LOCK TABLES `visitor_tag` WRITE; +/*!40000 ALTER TABLE `visitor_tag` DISABLE KEYS */; +INSERT INTO ` +visitor_tag` +VALUES + (2, '001'), + (3, '002'), + (4, '001'), + (5, '002'), + (6, '001'), + (7, '001'), + (8, '001'), + (9, '001'); +/*!40000 ALTER TABLE `visitor_tag` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `visitors` +-- + +DROP TABLE IF EXISTS `visitors`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `visitors` +( + `id` int NOT NULL AUTO_INCREMENT, + `fullname` varchar +(64) NOT NULL, + `user_id` int DEFAULT NULL, + `purpose_id` int DEFAULT NULL, + `date_added` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `address` text, + `phone_number` varchar +(16) DEFAULT NULL, + PRIMARY KEY +(`id`), + KEY `FK_WHOM_TO_SEE` +(`user_id`), + KEY `FK_PURPOSE` +(`purpose_id`), + CONSTRAINT `FK_PURPOSE` FOREIGN KEY +(`purpose_id`) REFERENCES `purpose` +(`id`), + CONSTRAINT `FK_WHOM_TO_SEE` FOREIGN KEY +(`user_id`) REFERENCES `users` +(`id`) +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `visitors` +-- + +LOCK TABLES `visitors` WRITE; +/*!40000 ALTER TABLE `visitors` DISABLE KEYS */; +INSERT INTO ` +visitors` +VALUES + (1, 'Mrs. Diya', 2, 2, '2022-08-01 23:00:00', 'Zone 4, 5th Floor, IGI House, 3, Gwani Street, Off IBB Way, Wuse 900281, Abuja', '08050917923'), + (2, 'Ben Aflek', 4, 2, '2022-09-06 15:36:30', '546 South Glendale St. Waukegan, IL 60085', '549889987987'), + (3, 'Dave Johnson', 2, 3, '2022-09-06 15:37:11', '981 Grand Drive Staten Island, NY 10301', '468484894'), + (4, 'Jack Harrison', 2, 3, '2022-09-07 08:29:05', 'No.1 Emmanuel Villa Close', '08130402087'), + (5, 'Ben Davis', 4, 3, '2022-09-07 08:29:35', 'kufuydiudiuf', '646+476+46'), + (6, 'James Foster', 1, 2, '2022-09-07 10:50:42', '3511 Blue Wing Dr Dickinson, Texas(TX), 77539', '54488987'), + (7, 'Jamie Foster', 3, 4, '2022-09-07 11:14:09', 'jksbvsioanvionsviobf', '056346546+5'), + (8, 'David Abah', 3, 2, '2022-09-07 11:41:52', 'Aso Rock', '658948998'), + (9, 'Zack the Coder', 4, 1, '2022-09-07 12:03:27', 'Layer 3', '345678i'); +/*!40000 ALTER TABLE `visitors` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2022-09-07 16:31:54