Routes - sitechtimes/club-attendance-backend-v2 GitHub Wiki

Route

Routes allow for the manipulation of data from the backend. Providing the frontend access to the database. These routes allow for the creation, deletion, and the retrieval of data from the google drive.

All routes for this project can be found here.

For the routes to work properly request from the frontend must match the HTTP Method and must provide the request body if need, most image routes however will require a form-data to send image files. If the HTTP Method or the form-data does not match with what is shown below then the routes may not function properly.

Below is a sample route, and other usable route with their HTTP method, route name, and the request body, with a short description of what each route is supposed to do. Some routes will have a response with data that can be used on the frontend.

Sample Route

[HTTP Method] "/routeName"

req.body 
{
 "uuid": "sampleUuid",
 "clubName": "sampleClubName",
 "year": "sampleYear"
}

Auth Routes

  • OAuth2

GET /oauth2

Redirects the user to Google login, using a link that is generated using the oAuth2client.generateAuthUrl().

  • oAuth2callback

GET /oauth2callback

After the user logs in using Google's oAuth, we receive a verified token and set the oAuth2 client with that token. We receive the user's data from Google. If the user is a new user, we add them to the main user sheet, then we create a cookie called "user_data" that contains the user information.


Club Data Routes

  • Get Club Data

GET /getClubData/:clubName/:year

Replace the params (:clubName and :year) with the club name and the year. Retrieves the club data of the specified club in the clubName param and the year of that club. The route will search through the metadata sheet of the specified year and return data of the club.

Response (Sample)

{
    "clubName": "Anime Club",
    "clubAdivsor": "Callahan",
    "clubAdvisorEmail": "Advisor Email",
    "clubPresident": "Marcus Yuen",
    "clubPresidentEmail": "President Email",
    "nextMeeting": "1/2000/2025",
    "room": "317"
}
  • Get Club Members

GET /getClubMembers/:clubName/:year/:uuid

Provide clubName, year, uuid in the request link. The response will be an array of objects containing the info of the member.

Response (Sample)

[
    {
        "UID": "117630357841785777342",
        "First Name": "JaezRR",
        "Last Name": "",
        "Email": "[email protected]",
        "Position": "Member",
        "Grade": "",
        "Official Class": "",
        "# of Attendances": "3"
    },
 ...
]
  • Get Club Meta

GET /getAllClubMeta/:uuid/:year

Provide uuid and year in the request link. Will provide an array of objects containing the information the meta data of the club.

Respone (Sample)

[
    {
        "Club Name": "3D Printing Club",
        "Advisor Email": "Advisor Email",
        "Club Advisor": "Buro",
        "President Email": "President Email",
        "Club President": "Benjamin Cavallaro & Elizabeth Superfin ",
        "Next Meeting": "1/2000/2025",
        "Room": "237",
        "QR Code": "1okGoCJyjnpqvocp4joLf_CM4mkosXPqQ",
        "Club Folder ID": "1DQz6Z5hA_9Ioke5USAmxt3HDynkqmoij",
        "Club Spreadsheet": "1LQkfJo_80LuXlp_n3KR1hTPY3kb3uRxP_YwN3a6bN8Y",
        "Club Photo Folder ID": "1jSRlKXZZCeR2qRUFnL3K41H0xBm8cYzD",
        "Club Code": "0f5971d0-fc2a-4705-84ce-7ae186d14fce"
    },
 ...
]

Update Attendance

PATCH /updateAttendance

Request Body (Sample)

{
    "year": "2024-2025",
    "clubName": "3D Printing Club",
    "uuid": "117630357841785777342"
}

Update attendance for the specified club and year.


Add/Delete club Meeting

  • Add Club Meeting

POST /addClubMeeting

Request Body (Sample)

{
    "year": "2024-2025",
    "clubName": "3D Printing Club",
    "nextMeeting": "1/2000/2025",
    "uuid": "113380945040354412648"
}

Add a club meeting for the specified club and year.

  • Delete Club Meeting

POST /deleteClubMeeting

Request Body (Sample)

{
    "year": "2024-2025",
    "clubName": "3D Printing Club",
    "uuid": "113380945040354412648"
}

Delete a club meeting for the specified club and year.


Club Image

All Club Image routes require Multer make sure that it is configured correctly and that the corresponding key-value matches the one that is set for Multer to use to process image. Multer is currently configured to use the key-value 'image' for any image files that are to be uploaded.

  • Show Attendance Photos

GET /showAttendancePhotos

This route needs to be reconfigured do not use Uses ClubName and Year to retrieve the attendance photo (more like profile photo of the club)

  • Upload Image

POST /uploadImage

Allows club presidents to upload image which are then created as a file in the 'Club Image' folder and will need to be approved before the image can be used. Send the data as a 'form-data' and the key-value should be 'image'

Request (Sample in JS)

let formdata = new FormData();

formdata.append("year", "2023-2024");
formdata.append("clubName", "Art Club");
formdata.append("uuid", "113380945040354412648");
formdata.append("image", fileInput.files[0], "postman-cloud:///1eeb484d-d8b2-42f0-94cb-215435d89a81"); //key-value is image and it contains the image file 

Disclaimer: for formdata.append("image", fileInput.files[0], "postman-cloud:///1eeb484d-d8b2-42f0-94cb-215435d89a81"); 'fileInput.files[0]' may not be necessary, this is postman code, so just the key-value and the image file may be all that is needed


Admin Routes

  • Approve Image

PATCH /approveImage

Approves the selected image and moves the image from the 'Club Image' folder to the designated clubs folder. Send the image, uuid, clubName, year as shown below:

var formdata = new FormData();
formdata.append("image", fileInput.files[0], "/C:/Users/aiden.pang/Downloads/3d+rapid+prototyping.jpeg");
formdata.append("uuid", "113383945040353412348");
formdata.append("year", "2023-2024");
formdata.append("clubName", "Art club");
  • Get Unapproved Images

GET /getUnapprovedImages/:uuid

Retrieves all images from the 'Club Image' folder, which are all the unapproved images and returns an array. Replace 'uuid' with the ID of a user with admin level priveleges. Response (Sample)

[
    {
        "link": "https://drive.google.com/uc?export=view&id=12UHPJlCPLfV4NTPsQPXSqtk8gyllHV_I",
        "src": "https://drive.google.com/file/d/12UHPJlCPLfV4NTPsQPXSqtk8gyllHV_I",
        "fileId": "12UHPJlCPLfV4NTPsQPXSqtk8gyllHV_I",
        "downloadUrl": "https://drive.google.com/uc?id=12UHPJlCPLfV4NTPsQPXSqtk8gyllHV_I&export=download"
    },
 ...
]

Currently this the links don't seem to work, this route may be changed to use google sheet to store the image files instead.

  • Add Club

POST /addClub

Allows for admin to create a new club

Request body (Sample)

{
    "year": "2024-2025",
    "clubName": "klajsdfl; Club",
    "clubAdvisor": "bean",
    "advisorEmail": "[email protected]",
    "clubPresident": "bean",
    "presidentEmail": "[email protected]",
    "room": "01978-234",
    "uuid": "113383945040353412348"
}
  • Delete Club

DELETE /deleteClub

Request body (Sample)

{
    "clubName": "klajsdfl; Club",
    "year": "2024-2025",
    "uuid": "113383945040353412348"
}

Removes club that matches the 'clubName' of within the folder of the specified 'year'

  • Update QR Code

PATCH /updateQRCode

Creates a new QR code for the specifed club and year, removes the old ones and replace with new QR code, also updates the meta data to reflect the change QR code id

this route is iffy don't use, needs to be fixed


Admin + Club President

  • Remove Student from Club

DELETE /removeStudentFromClub

Request body

{
    "year": "2024-2025", 
    "clubName": "3D Printing Club",
    "uuid": "113383945040353412348"
}

Removes the user that matches the uuid from the club of the specified year


Dev

These routes are to help maintain the google drive using postman and to manually create some necessary components

  • Create user Sheet

This Route requires admin authority, uuid must be a user that has admin privileges.

POST /createUserSheet

Request body is not needed, this will create a user sheet within the google drive.

  • Create Club Template

This Route requires admin authority, uuid must be a user that has admin privileges. This routes requires an image folder to store the images, so make sure that their is an image folder within the project or the club images will not be created.

POST /createClubTemplate

To properly create the intended sheets ensure that within the .env file the CLUB_DATA_SPREADSHEET_ID is set to the club data sheet that you intend to create.