Skip to content

Backend Functions

Sweekar Burji edited this page Oct 31, 2024 · 1 revision

1. applications.js

GET /: Fetches the application details for the authenticated user. It retrieves the user ID from the request header, finds the user in the database, and returns their applications. POST /: Adds a new job application for the authenticated user. It validates the input, creates a new application object, and saves it to the user's applications array. If an interview date is provided, it also adds the event to Google Calendar. PUT /:applicationId: Updates an existing job application for the user. It finds the application by ID, merges the request data with the existing application, and saves the changes. DELETE /:applicationId: Deletes a specified job application for the user. It finds the application by ID, removes it from the user's applications array, and saves the updated user document.

2. googlecalender.js

addToGoogleCalendar(interviewDate, companyName): Adds an event to the user's Google Calendar. It authenticates using a service account, constructs an event object with the interview details, and inserts it into the primary calendar.

3. index.js

Main Application Setup: Initializes the Express application, connects to the database, and sets up middleware for JSON parsing and CORS. It defines routes for user signup, login, profile, and applications, and starts the server on a specified port.

4. authorization.js

authmiddleware(req, res, next): Middleware function that checks for user authorization tokens. It verifies the token from the request header, checks its validity against the database, and ensures it hasn't expired. If valid, it allows the request to proceed; otherwise, it returns an unauthorized error.

5. login.js

File Path: application-tracking-system/new_backend/routes/login.js Functions: POST /: Handles user login. It validates the input, finds the user by username, compares the provided password with the stored hashed password, generates a new token, and updates the user's authentication tokens. It returns the user's profile information along with the token and its expiry.

6. connect.js

connectDB(): Connects to the MongoDB database using Mongoose. It logs the connection status and handles any connection errors. These descriptions provide a clear overview of the functionality within each file, which can be useful for documentation in your GitHub wiki.

Clone this wiki locally