0
votes

I'm trying to build an application which uses a database, that allows user to log in as an admin or employee.
Admin has few options:

  • add new employee,
  • list all employees and
  • add TODO Items for selected employee

Employee

  • display TODO items when logged in.

The first problem I've encountered is:
Should I create just one table for all records(employees & admins) and specify their name, username, password, status (admin or employee) or create separate tables for login credentials(username, password) and user data(like name, last name etc) to keep it separated?

Second problem is
I can't figure out how to display list of items for a user that has successfully logged in. How to access the data of the user that is logged in?

2
What database engine? - Rick James
im using sqlite - bengal

2 Answers

0
votes

The first problem I've encountered is:
Should I
1=> create just one table for all records(employees & admins) and specify their name, username, password, status (admin or employee) or
2=> create separate tables for login credentials(username, password) and user data(like name, last name etc) to keep it separated?

Its better to make all user data in one data-set (Table)
No need to separate login credentials in a separate table in your case.

Second problem is I can't figure out how to display list of items for a user that has successfully logged in.
How to access the data of the user that is logged in?

Something like that
Each Item in ITEM table should has a field called say USER_ID
And ONLY managers can update and set this field value
Then your query will be

SELECT *   
FROM ITEM  
WHERE USER_ID = 'logged_user_id'
0
votes

One approach will be to

  1. Create a profile or user table for thr user (employee or admin) and have userid(primary key), userloginname,userfirstname,userlastname,password(encrypted),email,role(ADMIN for admin or EMPLOYEE for employees),hintquestion etc.,.

2.Then create a table for todo tasks with columns like taskid,taskname,taskdescription etc., along with userid column(foriegn key) which will link this table to the primary key of profile table. (This answers your question on how to validate and fetch employee record).After login store user or profile object in session for the duration of the session).

3.When the user logs in validate the credentials against the username(the one user uses for login) and password stored in the profile table and fetch that record.

4.When adding employer, add the user to the profile table.

5.When adding todo tasks, add the todo items in the todo table using the userid fetched from the profile table.

6.When listing the todo items, fetch the record for thr logged in user and using the userid, fetch the todo items for the userid. (This answers your question on how to fetch the todo items)

7.When deleting the employee, delete the record from profile table and using the userid delete thr todo items from the todo items table.

Hope this helps.