0% found this document useful (0 votes)
2 views

Function Codes

The document outlines the backend processes for user login, registration, appointment management, and notifications, including SQL query preparations and checks for user types. It details the creation, updating, and deletion of users and appointments, as well as the use of WebSockets for real-time event handling. Additionally, it describes how to manage schedules and notifications dynamically based on user interactions and system conditions.

Uploaded by

maricar lacerna
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Function Codes

The document outlines the backend processes for user login, registration, appointment management, and notifications, including SQL query preparations and checks for user types. It details the creation, updating, and deletion of users and appointments, as well as the use of WebSockets for real-time event handling. Additionally, it describes how to manage schedules and notifications dynamically based on user interactions and system conditions.

Uploaded by

maricar lacerna
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

LOGIN

Login Using Credentials

Backend endpoint for requesting a token to authenticate the user

Login using QRCode


Scanned QRCode will return ID details, In our case we’re only using the School ID.
(e.g. 2021308468 MARIA ISRAEL P. NADELA BSIT)

const schoolId = qrData[0]; is 2021308468


After getting the school ID, we’ll request the backend to check for records who’s school_id is
equal to the school id we got from the qrData. We also added a check if the user is logging in
on a new device, we’ll prompt the user to enter their password to proceed.
REGISTER

Backend endpoint for user registration. Prepare the SQL query by using the data in the base
model request.
Use the data in the base model to set the values of the insert sql query. After that, we
prepared a notification message for the admin. Serialize the prepared notification message so
that the database can accept the json safely.
APPOINTMENT REQUEST/CREATION

For creating an appointment, we added a check if the user type is guest. If the user is a guest,
we will execute a sql query that will create the guest user. We’re creating the guest user so
we can use their user_id as reference for handling their appointments.
UPDATE APPOINTMENT
For updating an appointment, we need to set up an endpoint that can receive multiple values
and dynamically construct a sql query for updating if the request value in the base model is
not empty or None.

We can exclude the empty values by using this line


update_data = updates.model_dump(exclude_unset=True)
SCHEDULE CREATION

Backend endpoint for creating a schedule. First is we need to execute a sql query along with
data in the base model as values. Check if there are appointments to schedule the appointee
who requested the creation of a schedule.
Create a schedule if there are appointments to schedule. We’ll execute an sql query to insert
the schedule and update the appointments added in the schedule.

UPDATE SCHEDULE
Schedule update is a bit different, we added a background task that will run and adjust the
affected appointments details.

BaseModel for update request


We added a check first if the schedule exists. If so, we can proceed and get the schedule
details for that schedule before updating it.

The code snippet above shows how to update the schedule if the requested status update
value is dropped.

If the quantity (number of accommodated attendees changed and it is not equal to the
previous quantity, we’ll execute a sql query to either remove or add an appointment base
from the quantity. (e.g. If the previous quantity is 2 and the new quantity is 1) then remove
the appointment with the greatest appointment_id. If appointments_to_remove
is greater than 0 then we’ll proceed with the removal.
For adding an appointment to the schedule, we can insert the smallest appointment_id first
since it is the first one in the queue.

Finally, update the schedule quantity too.

As mentioned above, we created a background task that will run and adjust the affected
appointment details.

This line of code will call the function and we’ll just pass the necessary props to the
parameter.
background_tasks.add_task(adjust_appointments, schedule_id, updates.schedule_datetime,
updates.quantity, updates.minutes_per_student)
The code snippet above is the background task function, it will update all of the appointments
affected accordingly. (e.g. the appointee adjusted the schedule time from 8:00 AM to 10:00
AM and minutes per appointment is 15 Minutes) We can use the new time to allocate new
time for each appointment.
UPDATE USER

For updating a user, we can use the requested id of the user to determine the record we’re
updating.
DELETE USER

To delete a user, we need to delete first the associated appointments and schedules for that
user so we can proceed with the deletion.
APPROVE/DECLINE USER

Prepare a sql query that will set the status for the requested user reference using the user_id.
GET APPOINTMENTS

Prepare a sql query that matches AppointmentResponse(BaseModel) because that’s the type
of data we’ll be using in the frontend.

We’ll also dynamically structure the select query if the requested values which is in the filters
is not empty.
Finally structure the return data

We can request by using fetch requests.

GET SCHEDULES
For schedules, it's a bit different because we need to also get the appointments associated
with that schedule.
Prepare a sql query that will get our desired return data values.

In this part we iterate and get appointments associated with the current schedule
After iterating the appointments, we can then include it to the return data inside the current
schedule associated with it.

GET NOTIFICATIONS
To get notifications, we need to dynamically create a sql query base from the requested
values like if the status requested is unread then we use the filters.status and use the filter
value.
UPDATE NOTIFICATION STATUS (unread, read)

Prepare sql query that will set the notification record where the notification_id is equal to the
requested notification_id
NOTIFICATION CREATION
e.g. of how notifications created
Prepare a sql query for inserting new notifications and also the notifications message. After
that, proceed with executing the sql query.
AUTO QUEUE LOGIC
Create a notification first before updating the record.

Finally update the appointments if it satisfies the logic we created (e.g. the appointment end
time is 10:59 AM and the time now is 11:01, then we can set appointment status to complete
if the auto manage is on auto_manage = 1.

This function will run every 1 minute, we can modify the interval by setting how many
minutes or hours.

WEBSOCKET
We’re using websocket to listen for events and send the events to the frontend so we update
the states in the frontend accordingly.
e.g. of sending events to the frontend
This is how to get the events in the websocket and with that, we’re setting the currentEvent
inside a redux store so we can check if there are changes.

e.g. in the /admin/live-queue


We’re checking for current events and if it satisfies the condition then proceed with updating
the state of the live queue

You might also like