Skip to content

Membership Application: POST /application Route For New Members #6

@ZackHoang

Description

@ZackHoang

Purpose

Inside /api directory, create a /application route that performs a POST request to our database. This route will save new members' information into the database.

Acceptence Criteria

  • This route accept the following JSON schema, for example:
{
  "full_name": "John Doe",
  "email": "johndoe@mail.com",
  "phone_number": "+1 123-456-7890",
  "phone_type": "Home",
  "mailing_address": "123 ABC Street",
  "city": "Vancouver",
  "province": "British Columbia"
  "postal_code": "ABC 123",
  "membership_interests": "[Health, Education]"
  "reason": "I want to become a part of RPRC because ABC reasons"
}
  • Implement server-side validation for the above fields like so:
    • full_name: letters only, at least 2 words, each word's first letter is capitalized
    • email: lowercase letters only, with a valid email domain
    • phone_number: valid North American phone number, automatically attach a +1 country code before the number itself. Numbers only
    • phone_type: accept two values only: either Home or Cell
    • mailing_address: include street number, street's name and optionally, unit number if one lives in an apartment
    • city: valid city name in Canada
    • province: valid province name in Canada
    • postal_code: has a length of 7, including 3 letters at the start, one space in between and 3 digits that follows
    • membership_interests: accepts an array of values. MUST match with these values ONLY: Health, Education, Entertainment, Arts+Culture, Housing, Other
    • reason: perhaps limit the word count to 100-200?
    • Every field: trim white spaces on both side and check if it's empty
  • If all fields are valid, send back this response:
{
 "status": "success",
 "data": null
}

If not:

{
  "status": "fail",
  "data": {
    "full_name": "Full name must consists of at least 2 words",
    "email": "Invalid email domain"
  }
}

When sending a fail response, each field MUST matches with the JSON field that is being sent to database

Additional Comments

  • NextJS API building guide could be a great resource to look at when making your API routes!
  • Check out zod's documentation, this is our validation library
  • JSON responses are based on JSend. This standard is not officially approved for use in this project yet and is only for demonstration for now

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions