Skip to content
Mena Attia edited this page Oct 8, 2021 · 2 revisions

Overview

app.ts holds all the backend endpoints associated with reviews, apartments and renting companies/ landlords in Firebase

Data Types

Id = {
  readonly id: string;
};

DetailedRating = {
  readonly location: number;
  readonly safety: number;
  readonly value: number;
  readonly maintenance: number;
  readonly communication: number;
  readonly conditions: number;
};

Review = {
  readonly aptId: string | null;
  readonly likes?: number;
  readonly date: Date;
  readonly detailedRatings: DetailedRating;
  readonly landlordId: string;
  readonly overallRating: number;
  readonly photos: readonly string[];
  readonly reviewText: string;
};

ReviewWithId = Review & Id;

Landlord = {
  readonly name: string;
  readonly contact: string | null;
  readonly avgRating: number;
  readonly profilePhoto?: string;
  readonly photos: readonly string[];
  readonly reviews: readonly string[];
  readonly properties: readonly string[];
  readonly address: string | null;
};

LandlordWithId = Landlord & Id;
LandlordWithLabel = LandlordWithId & { readonly label: 'LANDLORD' };

Apartment = {
  readonly name: string;
  readonly address: string;
  readonly landlordId: string | null;
  readonly numBaths: number | null;
  readonly numBeds: number | null;
  readonly photos: readonly string[];
  readonly area: 'COLLEGETOWN' | 'WEST' | 'NORTH' | 'DOWNTOWN' | 'OTHER';
};

ApartmentWithId = Apartment & Id;
ApartmentWithLabel = ApartmentWithId & { readonly label: 'APARTMENT' };

Status Codes

  • 200/201: success
  • 400/401: error

GET requests

/:

  • Description: to get all the FAQ sections in Firebase
  • Return type: Section[]

/review/:idType/:id:

  • Description: to get reviews associated with the id request paramter that is a landlordId or aptId, the two options for the idType request parameter
  • Return type: ReviewWithId[]

/apts/:ids:

  • Desctiption: to get apartments associated with ids supplied as a request parameter, seperated by commas.
  • Return type: ApartmentWithId[]

/landlord/:id:

  • Description: to get a landlord with id specified as a request parameter
  • Return type: Landlord

/buildings/:landlordId:

  • Description: to get all the apartments/ buildings associated with the landlordId request parameter
  • Return type: Apartment[]

/search:

  • Description: to get landlords and apartments that match the query in the query parameter q, using fuzzy search
  • Return type: (LandlordWithLabel | ApartmentWithLabel)[]

/page-data/:page:

  • Description: to get apartments to display on cards with the number of reviews and the company name. Returns three apartments when the page request parameter is home
  • Return type:
{
      buildingData: Apartment;
      numReviews: number;
      company: string;
    }[]

POST requests

/new-review:

  • Description: to allow users to provide reviews
  • Body: Review
  • Return type: doc id of the new review that was added
  • Authentication: required
  • Permissions: Only Cornell users can post reviews

/new-landlord:

  • Description: to add landlords to the database, for internal use
  • Body: Landlord
  • Return type: doc id of the new landlord that was added

/add-like:

  • Description: to allow users to mark reviews as helpful
  • Body: reviewId
  • Return type: { result: 'Success' } or Error
  • Authentication: required
  • Permissions: Only Cornell users can add likes

/remove-like:

  • Description: to allow users to unmark reviews that they marked as helpful
  • Body: reviewId
  • Return type: { result: 'Success' } or Error
  • Authentication: required
  • Permissions: Only Cornell users can remove likes