1
|
SET NAMES utf8mb4;
|
2
|
|
3
|
-- -----------------------------------------------------
|
4
|
-- Table end_user
|
5
|
-- -----------------------------------------------------
|
6
|
DROP TABLE IF EXISTS end_user;
|
7
|
CREATE TABLE end_user (
|
8
|
id BIGINT NOT NULL AUTO_INCREMENT,
|
9
|
first_name VARCHAR(45) NOT NULL,
|
10
|
last_name VARCHAR(45) NOT NULL,
|
11
|
no_vacations FLOAT NOT NULL,
|
12
|
no_sick_days INT,
|
13
|
taken_sick_days INT NOT NULL,
|
14
|
alert DATETIME,
|
15
|
token TEXT NOT NULL,
|
16
|
email VARCHAR(100) NOT NULL,
|
17
|
photo TEXT,
|
18
|
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
19
|
user_role VARCHAR(8) NOT NULL,
|
20
|
status VARCHAR(8) NOT NULL,
|
21
|
PRIMARY KEY (id),
|
22
|
CONSTRAINT check_taken_sick_days CHECK (taken_sick_days >= 0)
|
23
|
);
|
24
|
|
25
|
-- -----------------------------------------------------
|
26
|
-- Table vacation_day
|
27
|
-- -----------------------------------------------------
|
28
|
DROP TABLE IF EXISTS vacation_day;
|
29
|
CREATE TABLE vacation_day (
|
30
|
id BIGINT NOT NULL AUTO_INCREMENT,
|
31
|
vacation_date DATE NOT NULL,
|
32
|
time_from TIME,
|
33
|
time_to TIME,
|
34
|
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
35
|
status VARCHAR(8) NOT NULL,
|
36
|
vacation_type VARCHAR(8) NOT NULL,
|
37
|
user_id BIGINT NOT NULL,
|
38
|
PRIMARY KEY (id),
|
39
|
INDEX fk_vacation_day_end_user (user_id ASC),
|
40
|
CONSTRAINT fk_vacation_day_end_user FOREIGN KEY (user_id)
|
41
|
REFERENCES end_user (id)
|
42
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
43
|
CONSTRAINT check_time CHECK (time_from < time_to)
|
44
|
);
|
45
|
|
46
|
-- -----------------------------------------------------
|
47
|
-- Table Default_Settings
|
48
|
-- -----------------------------------------------------
|
49
|
DROP TABLE IF EXISTS default_settings;
|
50
|
CREATE TABLE default_settings (
|
51
|
id BIGINT NOT NULL AUTO_INCREMENT,
|
52
|
no_sick_days INT NOT NULL,
|
53
|
alert DATETIME NOT NULL,
|
54
|
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
55
|
PRIMARY KEY (id),
|
56
|
CONSTRAINT check_no_sick_days CHECK (no_sick_days >= 0)
|
57
|
);
|
58
|
|
59
|
DELIMITER $$
|
60
|
DROP PROCEDURE IF EXISTS GetUserId $$
|
61
|
CREATE PROCEDURE GetUserId(
|
62
|
IN in_id BIGINT,
|
63
|
OUT out_id BIGINT,
|
64
|
OUT out_first_name VARCHAR(45),
|
65
|
OUT out_last_name VARCHAR(45),
|
66
|
OUT out_no_vacations FLOAT,
|
67
|
OUT out_no_sick_days INT,
|
68
|
OUT out_taken_sick_days INT,
|
69
|
OUT out_alert DATETIME,
|
70
|
OUT out_token TEXT,
|
71
|
OUT out_email VARCHAR(100),
|
72
|
OUT out_photo TEXT,
|
73
|
OUT out_creation_date DATETIME,
|
74
|
OUT out_role VARCHAR(8),
|
75
|
OUT out_status VARCHAR(8))
|
76
|
BEGIN
|
77
|
DECLARE sickDaysCount INT;
|
78
|
DECLARE notification DATETIME;
|
79
|
|
80
|
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1;
|
81
|
SELECT id, first_name, last_name, no_vacations, IFNULL(no_sick_days, sickDaysCount), taken_sick_days, IFNULL(alert, notification), token, email, photo, creation_date, user_role, status
|
82
|
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_sick_days, out_alert, out_token, out_email, out_photo, out_creation_date, out_role, out_status
|
83
|
FROM end_user
|
84
|
WHERE id=in_id;
|
85
|
END $$
|
86
|
|
87
|
DROP PROCEDURE IF EXISTS GetUserToken $$
|
88
|
CREATE PROCEDURE GetUserToken(
|
89
|
IN in_token TEXT,
|
90
|
OUT out_id BIGINT,
|
91
|
OUT out_first_name VARCHAR(45),
|
92
|
OUT out_last_name VARCHAR(45),
|
93
|
OUT out_no_vacations FLOAT,
|
94
|
OUT out_no_sick_days INT,
|
95
|
OUT out_taken_sick_days INT,
|
96
|
OUT out_alert DATETIME,
|
97
|
OUT out_token TEXT,
|
98
|
OUT out_email VARCHAR(100),
|
99
|
OUT out_photo TEXT,
|
100
|
OUT out_creation_date DATETIME,
|
101
|
OUT out_role VARCHAR(8),
|
102
|
OUT out_status VARCHAR(8))
|
103
|
BEGIN
|
104
|
DECLARE sickDaysCount INT;
|
105
|
DECLARE notification DATETIME;
|
106
|
|
107
|
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1;
|
108
|
SELECT id, first_name, last_name, no_vacations, IFNULL(no_sick_days, sickDaysCount), taken_sick_days, IFNULL(alert, notification), token, email, photo, creation_date, user_role, status
|
109
|
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_sick_days, out_alert, out_token, out_email, out_photo, out_creation_date, out_role, out_status
|
110
|
FROM end_user
|
111
|
WHERE token=in_token;
|
112
|
END $$
|
113
|
|
114
|
DELIMITER ;
|
115
|
|
116
|
-- -----------------------------------------------------
|
117
|
-- Insert table end_user
|
118
|
-- -----------------------------------------------------
|
119
|
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('admin', 'admin', 0, NULL, 0, NULL, '', '', 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', 'EMPLOYER', 'ACCEPTED');
|
120
|
|
121
|
-- -----------------------------------------------------
|
122
|
-- Insert table vacation_day
|
123
|
-- -----------------------------------------------------
|
124
|
-- INSERT INTO vacation_day (vacation_date, time_from, time_to, user_id, status_id, type_id) VALUES ();
|
125
|
|
126
|
-- -----------------------------------------------------
|
127
|
-- Insert table default_settings
|
128
|
-- -----------------------------------------------------
|
129
|
INSERT INTO default_settings (no_sick_days, alert) VALUES (5, '2019-12-01 12:00:00.000');
|