Skip to content

Commit

Permalink
Additional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwain-Anderson committed Feb 16, 2025
1 parent ae1ef03 commit d086a1b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
15 changes: 15 additions & 0 deletions frontend/src/components/EmployeeModal/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,18 @@ const Upload = ({ imageChange, existingPhoto }: UploadProps) => {
};

export default Upload;

/**
* This component, `Upload`, provides an interface for users to upload a profile picture. It accepts
* an image file, validates its size, and previews the selected image. If the file size exceeds the
* pre- specified limit, an error message is displayed. The component supports both drag-and-drop and keyboard
* interactions to trigger the image upload.
*
* Props:
* - `imageChange`: A callback function that is invoked when the image is successfully selected or changed.
* - `existingPhoto` (optional): A URL for an existing profile photo to be displayed as the default.
*
* Features:
* - Displays an image preview after selection.
* - Validates that the selected image is under a defined size limit (500MB).
*/
23 changes: 17 additions & 6 deletions server/src/router/upload.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import express from 'express';
import {
S3,
PutObjectCommand,
DeleteObjectCommand,
HeadObjectCommand,
} from '@aws-sdk/client-s3';
import { S3 } from '@aws-sdk/client-s3';
import * as db from './common';
import { Driver } from '../models/driver';
import { Admin } from '../models/admin';
Expand Down Expand Up @@ -67,3 +62,19 @@ router.post('/', validateUser('User'), (request, response) => {
});

export default router;

/**
* This file handles image uploads to an S3 bucket.
* The image upload allows for the replacement of an existing image for drivers and admins,
* and updates the corresponding user's photo URL in the database. The uploaded image is
* stored in the 'carriage-images' S3 bucket and is made publicly accessible. The route
* validates the user, checks required fields, uploads the image to S3, and then updates
* the relevant user record with the new image URL in the database.
* This route performs the following actions:
* 1. Validates the user via the `validateUser` middleware.
* 2. Ensures that the `id`, `tableName`, and `fileBuffer` parameters are valid.
* 3. Uploads the image to the S3 bucket using AWS SDK.
* 4. Updates the corresponding driver's or admin's record in the database with the new
* photo URL.
* 5. Handles success and error responses, including S3 upload errors.
*/

0 comments on commit d086a1b

Please sign in to comment.