Skip to content

CliJEO/backend

Repository files navigation

Backend Documentation

Running It 🏃

  1. Either install postgres or setup the postgresql docker container(this is what I do)

  2. Create a DB by accessing the psql shell. The default postgres user is postgres.

  3. Replicate the .env.example file as .env. Edit PG_USERNAME, PG_PASSWORD and DB_NAME with what you created.

  4. You can specify MEDIA_DIR (where the media will be stored)

  5. Then the usual drill. npm install and then npm run dev to start a dev instance

Profile Endpoints

Endpoint Description Auth Body Response
POST /user/login Logins a user or creates user if not existing No
{
  idToken: "googleauthidtoken";
}
{
firstLogin: true,
jwt: "jwthere"
}
POST /admin/login Logins an existing admin No
{
  idToken: "googleauthidtoken";
}
{
  jwt: "jwthere";
}
POST /admin/create Allows an existing admin to add another admin Admin
{
email: "somebody@gmail.com",
name: "optional name parameter"
}
{
  ok: true;
}
PUT /user/update Allows a user to edit their details User
{
  name: "some name",
  "age": 10,
  "gender": "male/female/other",
  "phoneNumber": "string",
  "location": "string",
}
all parameters are optional
{
  ok: true;
}
PUT /admin/update Allows an admin to edit their name Admin same as above same as above
GET /admin/userDetails/:id Allows an admin user to view any users details based on their ID Admin none
{
  "id": "108102370237663039357",
  "name": "Joel Mathew",
  "email": "joelmathewcherian@gmail.com",
  "profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp5L-rlPVOVOFhelIaTGDxMWwjbiqESmMBeaqcwL3w=s96-c",
  "age": 21,
  "gender": "male",
  "phoneNumber": "941234801",
  "location": "scscdsvsdvdsv"
}
  • The admin name will be automaticallly set to the name associated to the email if not explicitly provided. The profile picture will be automatically taken from the google account profile pic.

  • An admin can be created on the server side using the npm add-admin script

Query Endpoint

Endpoint Description Auth Body Response
POST /query/create user posts a query User

NOTE: The body here is form/multipart, not json.

{
  title: "string <= 50chars", //~10 words
  content: "string <= 1250 characters", //~ 250 words
  files: [all the files that need to be uploaded(max 4 files of 50 mb each)]
}
ok:true
GET /query/:id get all the details about a query including responses(sorted in order) and media User NA
{
  "id": 3,
  "title": "Bruhtacular the second",
  "content": "i like mayo",
  "closed": false,
  "timestamp": "2022-12-12T08:30:57.834Z",
  "user": {
    "name": "Doubtful Baby",
    "profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp41ujok5WxbmKFWDZOWpmbb9xcXcL_4ixUD8pbfnQ=s96-c",
    "id": "108102370237663039357"
  },
  "media": [
    {
      "filename": "1670490412464.png",
      "filetype": "image/audio/video/document"
    }
  ],
  "responses": [
    {
      "content": "have you tried turning it on and off?",
      "timestamp": "2022-12-12T08:30:57.834Z",
      "admin": {
        "name": "Cliford Joshy",
        "profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp41ujok5WxbmKFWDZOWpmbb9xcXcL_4ixUD8pbfnQ=s96-c"
      }
    },
    {
      "content": "i did try that",
      "timestamp": "2022-12-12T08:30:57.834Z"
    }
  ]
}

the admin responses will have the admin field

GET query/:id/admin same as above but with admin auth Admin none same as above
GET /admin/pending get overview of all open queries sorted by most recent first Admin NA
[
  {
    "id": 5,
    "title": "Bruhtacular the second",
    "timestamp": "2022-12-12T08:30:57.834Z",
    "user": {
      "name": "Cliford Joshy",
      "profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp41ujok5WxbmKFWDZOWpmbb9xcXcL_4ixUD8pbfnQ=s96-c"
    }
  }
]
GET /admin/archived get overview of all closed queries sorted by most recent first Admin NA
[
  {
    "id": 5,
    "title": "Bruhtacular the second",
    "timestamp": "2022-12-12T08:30:57.834Z",
    "user": {
      "name": "Cliford Joshy",
      "profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp41ujok5WxbmKFWDZOWpmbb9xcXcL_4ixUD8pbfnQ=s96-c"
    }
  }
]
GET /user/me get all the details about a user including queries User NA
{
  "id": "109761649576168914913",
  "name": "Cliford Joshy",
  "email": "clifordjo@gmail.com",
  "profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp41ujok5WxbmKFWDZOWpmbb9xcXcL_4ixUD8pbfnQ=s96-c",
  "age": null,
  "gender": null,
  "phoneNumber": null,
  "location": null,
  "queries": [
    {
      "id": 1,
      "title": "Test Query",
      "content": "lorem ipsum dolor set amet",
      "closed": false,
      "timestamp": "2022-12-12T08:30:57.834Z",
      "responseCount": 0
    }
  ]
}
GET /admin/me get all the details about a admin including active/archived queries Admin NA
{
  "email": "joelmathewcherian@gmail.com",
  "name": "Hoel Mathew Cherian",
  "profilePicture": "https://lh3.googleusercontent.com/a/AGNmyxbThtbXk0MCR_qFzKc7eiVuiqAOioOm0lrgnKLFUA=s96-c",
  "activeQueries": [
    {
      "id": 20,
      "title": "cliford hostage, ransom required",
      "timestamp": "2023-01-03T14:00:26.093Z",
      "content": "Dear Sir cliford is held hostage and a random of 10,00,000 is required. Proof is attached below.",
      "user.name": "Joel Mathew",
      "user.profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp5L-rlPVOVOFhelIaTGDxMWwjbiqESmMBeaqcwL3w=s96-c",
      "responseCount": 0
    },
  ],
  "archivedQueries": [
    {
      "id": 29,
      "title": "testing the progress",
      "timestamp": "2023-01-04T15:58:23.777Z",
      "content": "hehe",
      "user.name": "Joel Mathew",
      "user.profilePicture": "https://lh3.googleusercontent.com/a/AEdFTp5L-rlPVOVOFhelIaTGDxMWwjbiqESmMBeaqcwL3w=s96-c",
      "responseCount": 2
    },
  ]
}
POST query/admin/close/:id An admin can close an open query Admin Nothing ok:true
POST /respond/:queryId/admin An admin can respond to an open query Admin
{
  "content": "do you even?"
}
ok:true
POST /respond/:queryId/user A user can respond to an open query User same as above
{
  ok: false/true,
  warning: "warning message if ok is false (when notifying the user fails)"
}

Fetching Media

  • /media/filename with userToken
  • /media/filename/admin with adminToken

Notification Endpoints

Endpoint Description Auth Body Response
POST /fcm-token/save/admin Saves the fcm token for an admin Admin
{
  fcmToken: "fcmTokenHere";
}
ok: true
POST /fcm-token/save/user Saves the fcm token for a user User
{
  fcmToken: "fcmTokenHere";
}
ok: true

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors