From acb7bb7cb68edd90644ec2278fba6088366a30d6 Mon Sep 17 00:00:00 2001 From: "selina.mail" Date: Fri, 15 Mar 2024 21:04:53 +0100 Subject: [PATCH 1/4] implemented userTable --- backend/controller/users.js | 22 +- backend/models/usersModel.js | 18 +- backend/routes/routes.js | 4 + components/EmployeeSearch.vue | 129 +++ components/server/EmployeeTable.vue | 228 ++++ documentation/.$Datenbankmodell.drawio.bkp | 58 +- documentation/.$Datenbankmodell.drawio.dtmp | 995 ++++++++++++++++++ documentation/Datenbankmodell.drawio | 19 +- layouts/Navigationbar.vue | 13 + pages/employees.vue | 103 ++ plugins/vuex.js | 62 +- server/api/getAllEmployees.ts | 23 + .../getSelectedEmployeesByEmployee/[id].ts | 23 + server/middleware/employees.ts | 271 +++++ 14 files changed, 1925 insertions(+), 43 deletions(-) create mode 100644 components/EmployeeSearch.vue create mode 100644 components/server/EmployeeTable.vue create mode 100644 documentation/.$Datenbankmodell.drawio.dtmp create mode 100644 pages/employees.vue create mode 100644 server/api/getAllEmployees.ts create mode 100644 server/api/getSelectedEmployeesByEmployee/[id].ts create mode 100644 server/middleware/employees.ts diff --git a/backend/controller/users.js b/backend/controller/users.js index 1bd09c4..d903489 100644 --- a/backend/controller/users.js +++ b/backend/controller/users.js @@ -10,6 +10,7 @@ import { getUserById, updateUserById, deleteUserById, + getSelectedUsersByUser, } from "../models/usersModel.js"; //insert user to databased @@ -40,7 +41,7 @@ export const signUp = async (req, res, next) => { minute: '2-digit' }; const dateTimeString = currentTime.toLocaleString('de-DE', options); - const results = ownConn.query(`INSERT INTO users(id, username, password, registered, fullName, email, phonenumber, address, city, postcode, adminBool, technician1Bool, technician2Bool, technicianMonitoringBool, merchantBool, internBool) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + const results = ownConn.query(`INSERT INTO users(id, username, password, registered, fullName, email, phonenumber, address, city, postcode, adminBool, technicianBool, readerBool) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ uuidv4(), req.body.username, @@ -53,11 +54,8 @@ export const signUp = async (req, res, next) => { req.body.city, req.body.postcode, req.body.adminBool, - req.body.technician1Bool, - req.body.technician2Bool, - req.body.technicianMonitoringBool, - req.body.merchantBool, - req.body.internBool, + req.body.technicianBool, + req.body.readerBool, ]); return res.status(201).send({ message: "Registered!", @@ -161,6 +159,18 @@ export const showUserById = (req, res) => { }); }; +//get all selected users by user +export const showSelectedUsersByUser = (req, res) => { + getSelectedUsersByUser(req.params.id, (err, results) => { + if (err) { + res.send(err); + } else { + res.json(results); + } + }); +}; + + // Update user export const updateUser = (req, res) => { const data = req.body; diff --git a/backend/models/usersModel.js b/backend/models/usersModel.js index 88dd055..03f8bf5 100644 --- a/backend/models/usersModel.js +++ b/backend/models/usersModel.js @@ -28,12 +28,26 @@ export const getUserById = async (id, result) => { } }; +//get all selected users by full name +export const getSelectedUsersByUser = async (selected, result) => { + try { + let sql = `SELECT * FROM users WHERE LOWER(fullName) LIKE '%${selected.toLowerCase()}%' ORDER BY fullName ASC`; + const results = await ownConn.execute(sql) + result(null, results); + } + catch (err) { + // Manage Errors + console.log("SQL error : ", err); + result(err, null); + } +}; + // Update user to Database export const updateUserById = async (data, result) => { try { const id = data.id; - let sql = `UPDATE users SET username = ?, password = ?, fullName = ?, email = ?, phonenumber = ?, address = ?, city = ?, postcode = ?, adminBool = ?, technician1Bool = ?, technician2Bool = ?, technicianMonitoringBool = ?, merchantBool = ?, internBool = ? WHERE id = ?`; - const results = await ownConn.query(sql, [data.username, data.password, data.fullName, data.email, data.phonenumber, data.address, data.city, data.postcode, data.adminBool, data.technician1Bool, data.technician2Bool, data.technicianMonitoringBool, data.merchantBool, data.internBool, id]); + let sql = `UPDATE users SET username = ?, password = ?, fullName = ?, email = ?, phonenumber = ?, address = ?, city = ?, postcode = ?, adminBool = ?, technicianBool = ?, readerBool = ? WHERE id = ?`; + const results = await ownConn.query(sql, [data.username, data.password, data.fullName, data.email, data.phonenumber, data.address, data.city, data.postcode, data.adminBool, data.technicianBool,, data.readerBool, id]); result(null, results); } catch (err) { diff --git a/backend/routes/routes.js b/backend/routes/routes.js index 34b52c5..390f470 100644 --- a/backend/routes/routes.js +++ b/backend/routes/routes.js @@ -113,6 +113,7 @@ import { showUserById, updateUser, deleteUser, + showSelectedUsersByUser, } from "../controller/users.js"; import * as userMiddleware from "../middleware/users.js"; @@ -608,6 +609,9 @@ router.post('/login', login); // get all users router.get("/users", showUsers); +// get all users by user +router.get("/selectedUsersByUser/:id", showSelectedUsersByUser) + //get user by id router.get("/user/:id", showUserById); diff --git a/components/EmployeeSearch.vue b/components/EmployeeSearch.vue new file mode 100644 index 0000000..4c0ff57 --- /dev/null +++ b/components/EmployeeSearch.vue @@ -0,0 +1,129 @@ + + + + + + + + \ No newline at end of file diff --git a/components/server/EmployeeTable.vue b/components/server/EmployeeTable.vue new file mode 100644 index 0000000..dc96de2 --- /dev/null +++ b/components/server/EmployeeTable.vue @@ -0,0 +1,228 @@ + + + + + + + + diff --git a/documentation/.$Datenbankmodell.drawio.bkp b/documentation/.$Datenbankmodell.drawio.bkp index 35fa7fe..28b2cf5 100644 --- a/documentation/.$Datenbankmodell.drawio.bkp +++ b/documentation/.$Datenbankmodell.drawio.bkp @@ -1,6 +1,6 @@ - + - + @@ -395,7 +395,7 @@ - + @@ -421,33 +421,63 @@ - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -470,7 +500,7 @@ - + @@ -491,7 +521,7 @@ - + diff --git a/documentation/.$Datenbankmodell.drawio.dtmp b/documentation/.$Datenbankmodell.drawio.dtmp new file mode 100644 index 0000000..78d9294 --- /dev/null +++ b/documentation/.$Datenbankmodell.drawio.dtmp @@ -0,0 +1,995 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/documentation/Datenbankmodell.drawio b/documentation/Datenbankmodell.drawio index 28b2cf5..f60d6d9 100644 --- a/documentation/Datenbankmodell.drawio +++ b/documentation/Datenbankmodell.drawio @@ -1,6 +1,6 @@ - + - + @@ -341,7 +341,7 @@ - + @@ -379,21 +379,12 @@ - + - + - - - - - - - - - diff --git a/layouts/Navigationbar.vue b/layouts/Navigationbar.vue index 2988ba1..321e168 100644 --- a/layouts/Navigationbar.vue +++ b/layouts/Navigationbar.vue @@ -60,6 +60,14 @@
Customers
+ +
+ +
+ +
Employees
+
+
@@ -96,6 +104,11 @@ const defaultIssueSlipPage = () => { store.commit('changeToIssueSliplist') } +const defaultEmployeesPage = () => { + store.commit('resetStore'); + store.commit('changeToEmployeelist') +} + const ToggleSidebar = () => { isExpanded.value = !isExpanded.value; }; diff --git a/pages/employees.vue b/pages/employees.vue new file mode 100644 index 0000000..fca000e --- /dev/null +++ b/pages/employees.vue @@ -0,0 +1,103 @@ + + + + + + + + \ No newline at end of file diff --git a/plugins/vuex.js b/plugins/vuex.js index 8efaf70..67ac762 100644 --- a/plugins/vuex.js +++ b/plugins/vuex.js @@ -128,6 +128,10 @@ const store = createStore({ newAmountII: '', newPropertiesII: '', chosenIssueVariantId: -1, + + onEmployeelist: true, + onEmployee: false, + chosenEmployeeId: -1, }; }, mutations: { @@ -159,10 +163,6 @@ const store = createStore({ state.changedCustomerId = id }, - refresh() { - // - }, - // functions to change the asset pages changeToAssetlist(state) { state.onAssetlist = true @@ -486,6 +486,42 @@ const store = createStore({ state.deleteIcon = true }, + // functions to change the user pages + changeToEmployeelist(state) { + state.onEmployeelist = true + state.onEmployee = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = false + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false + }, + changeToEmployee(state) { + state.onEmployeelist = false + state.onEmployee = true + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = false + state.searchIcon = false + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = true + state.deleteIcon = true + }, + // functions to update the asset updateAssetComponent(state, asset) { state.newAssetName = asset.assetName @@ -556,7 +592,7 @@ const store = createStore({ state.newUserIS = is.user state.newDeliveryAddressIS = is.deliveryAddress }, - + // functions to update the accounting info component updateOrderingInfoComponent(state, o) { state.newOIs = o.ois @@ -623,11 +659,16 @@ const store = createStore({ state.chosenIssueId = id }, - // function to set the chosen issue variant - setChosenIssueVariant(state, id) { + // function to set the chosen issue variant + setChosenIssueVariant(state, id) { state.chosenIssueVariantId = id }, + // function to set the chosen user + setChosenEmployee(state, id) { + state.chosenEmployeeId = id + }, + // function to reset the pages resetStore(state) { state.editable = false @@ -732,6 +773,9 @@ const store = createStore({ state.newStateII = '' state.newAmountII = '' state.newPropertiesII = '' + + // reset the employee page variables + state.chosenEmployeeId = -1 }, // functions to (undo) delete an asset @@ -777,6 +821,10 @@ const store = createStore({ state.onIssueItemList = false state.onIssueItemVariant = false state.onIssueItem = true + + // set the employee variables + state.onEmployeelist = false + state.onEmployee = true }, }, }); diff --git a/server/api/getAllEmployees.ts b/server/api/getAllEmployees.ts new file mode 100644 index 0000000..3d979e0 --- /dev/null +++ b/server/api/getAllEmployees.ts @@ -0,0 +1,23 @@ +import { employees, errorMsg } from "../middleware/employees"; +import { OutgoingMessage } from 'http'; + +export default defineEventHandler(async (event) => { + + const headers: Record[1]> = { + 'Access-Control-Allow-Origin': 'https://tueitapp.tueit.de', + 'Access-Control-Allow-Headers': 'authorization, content-type', + 'Access-Control-Allow-Methods': 'GET,HEAD,PUT,PATCH,POST,DELETE', + 'Access-Control-Allow-Credentials': 'true', + }; + setResponseHeaders(event, headers) + + if (!(errorMsg === '')) { + throw createError({ + statusCode: 400, + statusMessage: errorMsg, + }) + } + + setResponseStatus(event, 200) + return employees +}) diff --git a/server/api/getSelectedEmployeesByEmployee/[id].ts b/server/api/getSelectedEmployeesByEmployee/[id].ts new file mode 100644 index 0000000..c8871ba --- /dev/null +++ b/server/api/getSelectedEmployeesByEmployee/[id].ts @@ -0,0 +1,23 @@ +import { selectedEmployeesByEmployee, errorMsg } from "../../middleware/employees"; +import { OutgoingMessage } from 'http'; + +export default defineEventHandler(async (event) => { + + const headers: Record[1]> = { + 'Access-Control-Allow-Origin': 'https://tueitapp.tueit.de', + 'Access-Control-Allow-Headers': 'authorization, content-type', + 'Access-Control-Allow-Methods': 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE', + 'Access-Control-Allow-Credentials': 'true', + }; + setResponseHeaders(event, headers) + + if (!(errorMsg === '')) { + throw createError({ + statusCode: 400, + statusMessage: errorMsg, + }) + } + + setResponseStatus(event, 200) + return selectedEmployeesByEmployee +}) diff --git a/server/middleware/employees.ts b/server/middleware/employees.ts new file mode 100644 index 0000000..d7fca46 --- /dev/null +++ b/server/middleware/employees.ts @@ -0,0 +1,271 @@ +import axios, { AxiosError } from 'axios'; +import serversideConfig from '../../serversideConfig'; +import https from 'https'; + +let employees = []; +let configItem = {}; +let errorMsg = ''; +let selectedEmployeesByEmployee = []; +let configItemsFromCustomer = []; +let selectedConfigItemsByAsset = []; + +export default defineEventHandler(async (event) => { + + const agent = new https.Agent({ + rejectUnauthorized: false, + }); + + const axiosInstance = axios.create({ + headers: { + 'Content-Type': 'application/json', + Accept: "*", + }, + httpsAgent: agent + }); + + if (event.path.startsWith("/api/getAllEmployees")) { + // get all users object from backend + try { + let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/users`); + employees = res.data; + } catch (err) { + if (axios.isAxiosError(err)) { + const axiosError = err as AxiosError; + + if (axiosError.response) { + // Axios error + console.error(axiosError.response.data.message); + errorMsg = axiosError.response.data.message; + } else if (axiosError.request) { + console.log(err) + // If error was caused by the request + console.error(axiosError.request); + } else { + // Other errors + console.error('Error', axiosError.message); + } + } else { + // No AxiosError + console.error('Error', err); + } + } + } + + // if (event.path.startsWith("/api/getConfigItem")) { + // // get all config items object from backend + // let itemId = null; + // const path = event._path; + // const pathSegments = path.split('/'); + // itemId = pathSegments[pathSegments.length - 1]; + + // try { + // let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/configItem/${itemId}`); + // configItem = res.data; + // } catch (err) { + // if (axios.isAxiosError(err)) { + // const axiosError = err as AxiosError; + + // if (axiosError.response) { + // // Axios error + // console.error(axiosError.response.data.message); + // errorMsg = axiosError.response.data.message; + // } else if (axiosError.request) { + // // If error was caused by the request + // console.error(axiosError.request); + // } else { + // // Other errors + // console.error('Error', axiosError.message); + // } + // } else { + // // No AxiosError + // console.error('Error', err); + // } + // } + // } + + // if (event.path.startsWith("/api/getCIFromCustomer")) { + // // get all config items from a customer from backend + // let itemId = null; + // const path = event._path; + // const pathSegments = path.split('/'); + // itemId = pathSegments[pathSegments.length - 1]; + + // try { + // let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/configItemByCustomerID/${itemId}`); + // configItemsFromCustomer = res.data; + // } catch (err) { + // if (axios.isAxiosError(err)) { + // const axiosError = err as AxiosError; + + // if (axiosError.response) { + // // Axios error + // console.error(axiosError.response.data.message); + // errorMsg = axiosError.response.data.message; + // } else if (axiosError.request) { + // // If error was caused by the request + // console.error(axiosError.request); + // } else { + // // Other errors + // console.error('Error', axiosError.message); + // } + // } else { + // // No AxiosError + // console.error('Error', err); + // } + // } + // } + + // if (event.path.startsWith("/api/updateConfigItem")) { + // const body = await readBody(event) + // // update the config item in the backend + // try { + // let res = await axiosInstance.put(`https://${serversideConfig.url}:${serversideConfig.port}/configItem`, body); + // } catch (err) { + // if (axios.isAxiosError(err)) { + // const axiosError = err as AxiosError; + + // if (axiosError.response) { + // // Axios error + // console.error(axiosError.response.data.message); + // errorMsg = axiosError.response.data.message; + // } else if (axiosError.request) { + // console.log(err) + // // If error was caused by the request + // console.error(axiosError.request); + // } else { + // // Other errors + // console.error('Error', axiosError.message); + // } + // } else { + // // No AxiosError + // console.error('Error', err); + // } + // } + // } + + // if (event.path.startsWith("/api/addConfigItem")) { + // const body = await readBody(event) + // // add the config item in the backend + // try { + // let res = await axiosInstance.post(`https://${serversideConfig.url}:${serversideConfig.port}/configItems`, body); + // } catch (err) { + // if (axios.isAxiosError(err)) { + // const axiosError = err as AxiosError; + + // if (axiosError.response) { + // // Axios error + // console.error(axiosError.response.data.message); + // errorMsg = axiosError.response.data.message; + // } else if (axiosError.request) { + // console.log(err) + // // If error was caused by the request + // console.error(axiosError.request); + // } else { + // // Other errors + // console.error('Error', axiosError.message); + // } + // } else { + // // No AxiosError + // console.error('Error', err); + // } + // } + // } + + // if (event.path.startsWith("/api/deleteConfigItem")) { + // let itemId = null; + // const path = event._path; + // const pathSegments = path.split('/'); + // itemId = pathSegments[pathSegments.length - 1]; + + // // delete the config item in the backend + // try { + // let res = await axiosInstance.delete(`https://${serversideConfig.url}:${serversideConfig.port}/configItems/${itemId}`); + // } catch (err) { + // if (axios.isAxiosError(err)) { + // const axiosError = err as AxiosError; + + // if (axiosError.response) { + // // Axios error + // console.error(axiosError.response.data.message); + // errorMsg = axiosError.response.data.message; + // } else if (axiosError.request) { + // console.log(err) + // // If error was caused by the request + // console.error(axiosError.request); + // } else { + // // Other errors + // console.error('Error', axiosError.message); + // } + // } else { + // // No AxiosError + // console.error('Error', err); + // } + // } + // } + + if (event.path.startsWith("/api/getSelectedEmployeesByEmployee")) { + // get selected employees object by employee from backend + let filteredEmployee = null; + const path = event._path; + const pathSegments = path.split('/'); + filteredEmployee = pathSegments[pathSegments.length - 1]; + + try { + let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/selectedUsersByUser/${filteredEmployee}`); + selectedEmployeesByEmployee = res.data; + } catch (err) { + if (axios.isAxiosError(err)) { + const axiosError = err as AxiosError; + + if (axiosError.response) { + // Axios error + console.error(axiosError.response.data.message); + errorMsg = axiosError.response.data.message; + } else if (axiosError.request) { + // If error was caused by the request + console.error(axiosError.request); + } else { + // Other errors + console.error('Error', axiosError.message); + } + } else { + // No AxiosError + console.error('Error', err); + } + } + } + + // if (event.path.startsWith("/api/getSelectedConfigItemsByAsset")) { + // // get selected config items object by asset from backend + // let filteredAsset = null; + // const path = event._path; + // const pathSegments = path.split('/'); + // filteredAsset = pathSegments[pathSegments.length - 1]; + + // try { + // let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/selectedConfigItemsByAssetName/${filteredAsset}`); + // selectedConfigItemsByAsset = res.data; + // } catch (err) { + // if (axios.isAxiosError(err)) { + // const axiosError = err as AxiosError; + + // if (axiosError.response) { + // // Axios error + // console.error(axiosError.response.data.message); + // errorMsg = axiosError.response.data.message; + // } else if (axiosError.request) { + // // If error was caused by the request + // console.error(axiosError.request); + // } else { + // // Other errors + // console.error('Error', axiosError.message); + // } + // } else { + // // No AxiosError + // console.error('Error', err); + // } + // } + // } +}) + +export { employees, configItem, selectedEmployeesByEmployee, selectedConfigItemsByAsset, configItemsFromCustomer, errorMsg }; \ No newline at end of file -- 2.43.0 From 45a4b58f265e0aa2bee0cd714084dc9ca5c04d0a Mon Sep 17 00:00:00 2001 From: "selina.mail" Date: Sun, 24 Mar 2024 21:02:56 +0100 Subject: [PATCH 2/4] implemented settings and user page (darkmode is still missing) --- backend/controller/users.js | 26 + backend/middleware/users.js | 5 +- backend/models/usersModel.js | 7 +- backend/routes/routes.js | 4 + components/LoginForm.vue | 250 +++-- components/server/Employee.vue | 476 ++++++++++ components/server/EmployeeGroups.vue | 485 ++++++++++ components/server/EmployeeTable.vue | 10 +- components/server/TemplateChecklistMVT.vue | 4 +- components/server/UserAccount.vue | 310 +++++- components/server/UserProfile.vue | 251 ++++- components/server/UserRightsList.vue | 4 +- documentation/.$Datenbankmodell.drawio.dtmp | 995 -------------------- documentation/Datenbankmodell.drawio | 2 +- layouts/Actionbar.vue | 23 +- layouts/PageHeader.vue | 101 +- layouts/empty.vue | 1 - nuxt.config.ts | 2 +- package-lock.json | 19 + package.json | 1 + pages/employees.vue | 6 +- pages/home.vue | 12 +- pages/login.vue | 5 +- pages/maintenanceVisits.vue | 13 +- pages/productionOrders.vue | 29 +- pages/settings.vue | 89 +- plugins/vuex.js | 131 ++- server/api/auth/login.ts | 16 +- server/api/auth/logout.ts | 3 + server/api/deleteEmployee/[id].ts | 23 + server/api/getEmployee/[id].ts | 23 + server/api/login.ts | 16 + server/api/updateEmployee.ts | 14 + server/api/updatePasswordEmployee.ts | 14 + server/middleware/employees.ts | 224 ++--- server/middleware/signUp.ts | 2 +- 36 files changed, 2283 insertions(+), 1313 deletions(-) create mode 100644 components/server/Employee.vue create mode 100644 components/server/EmployeeGroups.vue delete mode 100644 documentation/.$Datenbankmodell.drawio.dtmp create mode 100644 server/api/auth/logout.ts create mode 100644 server/api/deleteEmployee/[id].ts create mode 100644 server/api/getEmployee/[id].ts create mode 100644 server/api/login.ts create mode 100644 server/api/updateEmployee.ts create mode 100644 server/api/updatePasswordEmployee.ts diff --git a/backend/controller/users.js b/backend/controller/users.js index d903489..3614c65 100644 --- a/backend/controller/users.js +++ b/backend/controller/users.js @@ -71,6 +71,32 @@ export const signUp = async (req, res, next) => { } }; +// Update user password to Database +export const updatePasswordById = async (req, res, next) => { + try { + const id = req.body.id; + let sql = `UPDATE users SET password = ? WHERE id = ?`; + bcrypt.hash(req.body.password, 10, async (err, hash) => { + if (err) { + throw err; + return res.status(500).send({ + message: err, + }); + } else { + const results = await ownConn.query(sql, [hash, id]); + return res.status(200).send({ + message: 'Password changed!', + }); + } + }); + } + catch (err) { + // Manage Errors + console.log("SQL error : ", err); + result(err, null); + } +}; + export const login = async (req, res, next) => { try { let sql = `SELECT * FROM users WHERE username = ?`; diff --git a/backend/middleware/users.js b/backend/middleware/users.js index 608006c..fe128c6 100644 --- a/backend/middleware/users.js +++ b/backend/middleware/users.js @@ -38,10 +38,7 @@ export const validateRegister = (req, res, next) => { }); } // password (repeat) must match - if ( - !req.body.password_repeat || - req.body.password != req.body.password_repeat - ) { + if (req.body.password != req.body.password_repeat) { return res.status(400).send({ message: 'Both passwords must match', }); diff --git a/backend/models/usersModel.js b/backend/models/usersModel.js index 03f8bf5..41fd66b 100644 --- a/backend/models/usersModel.js +++ b/backend/models/usersModel.js @@ -46,8 +46,9 @@ export const getSelectedUsersByUser = async (selected, result) => { export const updateUserById = async (data, result) => { try { const id = data.id; - let sql = `UPDATE users SET username = ?, password = ?, fullName = ?, email = ?, phonenumber = ?, address = ?, city = ?, postcode = ?, adminBool = ?, technicianBool = ?, readerBool = ? WHERE id = ?`; - const results = await ownConn.query(sql, [data.username, data.password, data.fullName, data.email, data.phonenumber, data.address, data.city, data.postcode, data.adminBool, data.technicianBool,, data.readerBool, id]); + let sql = `UPDATE users SET username = ?, fullName = ?, email = ?, phonenumber = ?, address = ?, city = ?, postcode = ?, adminBool = ?, technicianBool = ?, readerBool = ? WHERE id = ?`; + const results = await ownConn.query(sql, [data.username, data.fullName, data.email, data.phonenumber, data.address, data.city, data.postcode, data.adminBool, data.technicianBool, data.readerBool, id]); + results.insertId = results.insertId.toString(); result(null, results); } catch (err) { @@ -57,12 +58,12 @@ export const updateUserById = async (data, result) => { } }; - // Delete user to Database export const deleteUserById = async (id, result) => { try { let sql = `DELETE FROM users WHERE id = ?`; const results = await ownConn.query(sql, [id]) + results.insertId = results.insertId.toString(); result(null, results); } catch (err) { diff --git a/backend/routes/routes.js b/backend/routes/routes.js index 390f470..05fbf96 100644 --- a/backend/routes/routes.js +++ b/backend/routes/routes.js @@ -108,6 +108,7 @@ import { import { signUp, + updatePasswordById, login, showUsers, showUserById, @@ -603,6 +604,9 @@ router.delete("/issueVariantsByIssueSlipId/:id", deleteIssueVariantByIssueSlipId // sign-up process router.post('/signUp', userMiddleware.validateRegister, signUp); +// update password process +router.put('/updatePassword', updatePasswordById); + // login process router.post('/login', login); diff --git a/components/LoginForm.vue b/components/LoginForm.vue index a3c7fe2..f54858e 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -26,8 +26,11 @@
Password:
- - + + +
@@ -37,24 +40,42 @@
- - + +
- + + \ No newline at end of file diff --git a/components/server/Employee.vue b/components/server/Employee.vue new file mode 100644 index 0000000..7b38a4a --- /dev/null +++ b/components/server/Employee.vue @@ -0,0 +1,476 @@ + + + + + + + + diff --git a/components/server/EmployeeGroups.vue b/components/server/EmployeeGroups.vue new file mode 100644 index 0000000..6e59e50 --- /dev/null +++ b/components/server/EmployeeGroups.vue @@ -0,0 +1,485 @@ + + + + + + + + + \ No newline at end of file diff --git a/components/server/EmployeeTable.vue b/components/server/EmployeeTable.vue index dc96de2..16f5ce3 100644 --- a/components/server/EmployeeTable.vue +++ b/components/server/EmployeeTable.vue @@ -15,17 +15,17 @@ :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']"> - + @click="goToChosenEmployee(u.id)"> {{ u.fullName }} - + @click="goToChosenEmployee(u.id)"> {{ u.username }} @@ -45,7 +45,7 @@ import { computed } from 'vue'; // get accesss to the store const store = useStore() -const goToChosenAsset = (id) => { +const goToChosenEmployee = (id) => { store.commit('setChosenEmployee', id); store.commit('changeToEmployee'); }; diff --git a/components/server/TemplateChecklistMVT.vue b/components/server/TemplateChecklistMVT.vue index 69b2b33..51cce4b 100644 --- a/components/server/TemplateChecklistMVT.vue +++ b/components/server/TemplateChecklistMVT.vue @@ -45,7 +45,7 @@ {{ todo.commets }} @@ -149,6 +149,8 @@ import Axios from '../axios.config.js'; import clientsideConfig from '../../clientsideConfig.js'; import { useStore } from 'vuex'; import { computed } from 'vue'; +// import VueInputAutowidth from 'vue-input-autowidth'; +// Vue.use(VueInputAutowidth); const store = useStore(); const addBool = computed(() => store.state.new); diff --git a/components/server/UserAccount.vue b/components/server/UserAccount.vue index 05a4caf..37d1888 100644 --- a/components/server/UserAccount.vue +++ b/components/server/UserAccount.vue @@ -2,32 +2,243 @@

Account:

-
-
E-Mail:
-
...
+
+
+
Username:
+
{{ loggedInUserUsername }}
+ +
+
+
Email:
+
{{ loggedInUserEmail }}
+ +
+
-
-
Password:
-
*******
+
+
+
New Password:
+ +
+
+
Repeat:
+ +
+
- - + + - + - - + + + \ No newline at end of file diff --git a/components/server/UserProfile.vue b/components/server/UserProfile.vue index 00a031a..4ac9d6a 100644 --- a/components/server/UserProfile.vue +++ b/components/server/UserProfile.vue @@ -5,28 +5,221 @@
-
-
Username:
-
...
+
+
+
Full name:
+
{{ loggedInUserFullName }}
+ +
+
+
Registered:
+
 {{ loggedInUserRegistered }}
+
+
+
Last login:
+
 {{ loggedInUserLastLogin }}
+
+
+
+
+
+
City:
+
{{ loggedInUserCity }}
+ +
+
+
Phonenumber:
+
{{ loggedInUserPhonenumber }}
+ +
+
+
+
+
Postcode:
+
{{ loggedInUserPostcode }}
+ +
+
+
Address:
+
{{ loggedInUserAddress }}
+ +
+
- - + + - + - - + + + \ No newline at end of file + --> \ No newline at end of file diff --git a/documentation/.$Datenbankmodell.drawio.dtmp b/documentation/.$Datenbankmodell.drawio.dtmp deleted file mode 100644 index 78d9294..0000000 --- a/documentation/.$Datenbankmodell.drawio.dtmp +++ /dev/null @@ -1,995 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/documentation/Datenbankmodell.drawio b/documentation/Datenbankmodell.drawio index f60d6d9..4ecfed3 100644 --- a/documentation/Datenbankmodell.drawio +++ b/documentation/Datenbankmodell.drawio @@ -1,4 +1,4 @@ - + diff --git a/layouts/Actionbar.vue b/layouts/Actionbar.vue index 9258f6d..a6bb37c 100644 --- a/layouts/Actionbar.vue +++ b/layouts/Actionbar.vue @@ -91,9 +91,9 @@
Instance
- -