Skip to content

Commit d086a1b

Browse files
Additional documentation
1 parent ae1ef03 commit d086a1b

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

frontend/src/components/EmployeeModal/Upload.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,18 @@ const Upload = ({ imageChange, existingPhoto }: UploadProps) => {
6767
};
6868

6969
export default Upload;
70+
71+
/**
72+
* This component, `Upload`, provides an interface for users to upload a profile picture. It accepts
73+
* an image file, validates its size, and previews the selected image. If the file size exceeds the
74+
* pre- specified limit, an error message is displayed. The component supports both drag-and-drop and keyboard
75+
* interactions to trigger the image upload.
76+
*
77+
* Props:
78+
* - `imageChange`: A callback function that is invoked when the image is successfully selected or changed.
79+
* - `existingPhoto` (optional): A URL for an existing profile photo to be displayed as the default.
80+
*
81+
* Features:
82+
* - Displays an image preview after selection.
83+
* - Validates that the selected image is under a defined size limit (500MB).
84+
*/

server/src/router/upload.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import express from 'express';
2-
import {
3-
S3,
4-
PutObjectCommand,
5-
DeleteObjectCommand,
6-
HeadObjectCommand,
7-
} from '@aws-sdk/client-s3';
2+
import { S3 } from '@aws-sdk/client-s3';
83
import * as db from './common';
94
import { Driver } from '../models/driver';
105
import { Admin } from '../models/admin';
@@ -67,3 +62,19 @@ router.post('/', validateUser('User'), (request, response) => {
6762
});
6863

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

0 commit comments

Comments
 (0)