Skip to content
Desire Kaleba edited this page Dec 28, 2021 · 5 revisions

Welcome to the busee documentation! This page shows how to play around with the API endpoints.

To start, make sure you have the project up and running. If you have not done so, You can follow the Getting started guide.

All endpoints are prefixed with ${URL_PREFIX} which can be found under your .env. This is completely up to you as it's being fetched from the environment variables but the default one is /api/v1. In that case, I will be intentionally omitting the prefix. Eg. /api/v1/auth/login will be written as /auth/login.

Note: A full URL has the following form ${PROTOCOL}://${HOST}:${PORT}/${URL_PREFIX}/${PATH}. Eg: http://localhost:4000/api/v1/auth/signup will hit the signup endpoint(/auth/signup).

Authentication

Signup user POST /auth/signup

Expected body model

{
  email: string;
  firstName?: string;
  lastName?: string;
  profileImage?: string;
  password: string;
  isAdmin?: boolean;
  isVerified?: boolean;
}

Note: all properties with a ? are optional.

Example

{
	"email": "gloirekaleba6@gmail.com",
	"password": "123456"
}

Will return a 201 with

{
  "status": "success",
  "message": "User created successfully.",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6OCwiaWF0IjoxNjM4Mjg5NjUyLCJleHAiOjE2MzkxNTM2NTJ9.BKIOgk9_0-CLyUQcTURdXhQpRBAz2bMeiuxFOLYWJ8c",
    "email": "gloirekaleba6@gmail.com"
  }
}

Login User POST /auth/signin

Expected body model

{
  email: string;
  password: string;
}

Example

{
	"email": "gloirekaleba2@gmail.com",
	"password": "abcdef"
}

Will return a 200 with

{
  "status": "success",
  "message": "user found.",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwiaWF0IjoxNjM4MjkwMDU1LCJleHAiOjE2MzkxNTQwNTV9.9Xc7T_NarGr-k0-euHyFYCd-UsFTo6hl7-uQIXcSgJo",
    "userId": 4,
    "email": "gloirekaleba2@gmail.com",
    "isAdmin": false
  }
}

Send Verification code POST /auth/sendVerificationCode

Expected body model

{
  to: string;
  channel: string;
}

Channel can either be email for emails verification or sms for sms verification. In the case of SMS simply input the conserned phone number instead the email address.

Example

{
	"to": "gloirekaleba@gmail.com",
	"channel": "email"
}

Will return a 200 with

{
  "status": "success",
  "message": "Verification code sent to gloirekaleba@gmail.com",
  "data": {
    "sid": "VE9ca120f230640d1727905614ecbea804",
    "serviceSid": "VAbdff333a747b3be4e73c992d1648dc11",
    "accountSid": "AC16121e5e804afb13c58f2f165fbd487f",
    "to": "gloirekaleba@gmail.com",
    "channel": "email",
    "status": "pending",
    "valid": false,
    "lookup": {
      "carrier": {
        "mobile_country_code": null,
        "type": null,
        "error_code": null,
        "mobile_network_code": null,
        "name": null
      }
    },
    "amount": null,
    "payee": null,
    "sendCodeAttempts": [
      {
        "attempt_sid": null,
        "channel_id": "azp1uzbNS_GmRNdH3zC6pg",
        "channel": "email",
        "time": "2021-11-29T20:48:48.972Z"
      }
    ],
    "dateCreated": "2021-11-29T20:48:48.000Z",
    "dateUpdated": "2021-11-29T20:48:49.000Z",
    "url": "https://verify.twilio.com/v2/Services/VAbdff333a747b3be4e73c992d1648dc11/Verifications/VE9ca120f230640d1727905614ecbea804"
  }
}

Verify User Account POST /auth/verify

Expected body model

{
  to: string;
  code: string;
}

Example

{
	"to": "gloirekaleba@gmail.com",
	"code": "464234"
}

Will return a 200 with

{
  "status": "success",
  "message": "User updated successfully.",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjM4MjE4NzQ2LCJleHAiOjE2MzkwODI3NDZ9.N0c1FJMtIP0v_ZEouc54HK-1uQ-dNi986Re-Z5Q0R8Q",
    "email": "gloirekaleba@gmail.com",
    "isVerified": true
  }
}

User

Get All GET /user

Example

Will return a 200 with

{
  "status": "success",
  "message": "Found 4 user(s).",
  "data": [
    {
      "id": 4,
      "email": "gloirekaleba6@gmail.com",
      "firstName": null,
      "lastName": null,
      "profileImage": null,
      "isAdmin": false,
      "isVerified": false,
      "createdOn": "2021-11-30T16:27:32.135Z",
      "updatedOn": "2021-11-30T16:27:32.135Z"
    },
    {
      "id": 3,
      "email": "gloirekaleba5@gmail.com",
      "firstName": null,
      "lastName": null,
      "profileImage": null,
      "isAdmin": false,
      "isVerified": false,
      "createdOn": "2021-11-30T16:27:28.352Z",
      "updatedOn": "2021-11-30T16:27:28.352Z"
    },
    {
      "id": 2,
      "email": "gloirekaleba3@gmail.com",
      "firstName": null,
      "lastName": null,
      "profileImage": null,
      "isAdmin": false,
      "isVerified": false,
      "createdOn": "2021-11-30T16:27:21.320Z",
      "updatedOn": "2021-11-30T16:27:21.320Z"
    },
    {
      "id": 1,
      "email": "gloirekaleba@gmail.com",
      "firstName": null,
      "lastName": null,
      "profileImage": null,
      "isAdmin": false,
      "isVerified": true,
      "createdOn": "2021-11-30T16:26:45.347Z",
      "updatedOn": "2021-11-30T16:26:45.347Z"
    }
  ]
}

Get Current User(user with current session) GET /user/me

This expects a valid bearer token.

Example

If set the token header to eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NiwiaWF0IjoxNjM4Mjg5NzIwLCJleHAiOjE2MzkxNTM3MjB9.I0E7HaXJQQ3fkA3eAm917IUtSI7kW-3zOxQEY3F6Qks Will return a 200 with

{
  "status": "success",
  "message": "user found.",
  "data": {
    "id": 6,
    "email": "gloirekaleba4@gmail.com",
    "firstName": null,
    "lastName": null,
    "profileImage": null,
    "isAdmin": false,
    "isVerified": false,
    "createdOn": "2021-11-30T16:27:25.159Z"
  }
}

Get user by ID GET /user/:id/getById

Example /user/4/getById Will return a 200 with

{
  "status": "success",
  "message": "user found.",
  "data": {
    "id": 4,
    "email": "gloirekaleba6@gmail.com",
    "firstName": null,
    "lastName": null,
    "profileImage": null,
    "isAdmin": false,
    "isVerified": false,
    "createdOn": "2021-11-30T16:27:16.919Z"
  }
}

Get user by email POST /user/getByEmail

Expected body model

{
  email: string;
}

Example

{
	"email": "gloirekaleba2@gmail.com"
}

Will return a 200 with

{
  "status": "success",
  "message": "user found.",
  "data": {
    "id": 4,
    "email": "gloirekaleba2@gmail.com",
    "firstName": null,
    "lastName": null,
    "profileImage": null,
    "isAdmin": false,
    "isVerified": false,
    "createdOn": "2021-11-30T16:27:16.919Z"
  }
}

Update user by ID PUT /user/:id

This expects a token to make sure a user updates his/her own account.

Expected body model

{
  email?: string;
  firstName?: string;
  lastName?: string;
  profileImage?: string;
  password?: string;
  isAdmin?: boolean;
  isVerified?: boolean;
}

Example PUT /user/1 with

{
	"isAdmin": true
}

Will return a 200 with

{
	"status": "success",
	"message": "User updated.",
	"data": {
		"id": 1,
		"email": "gloirekaleba@gmail.com",
		"firstName": null,
		"lastName": null,
		"profileImage": null,
		"isAdmin": true,
		"isVerified": false,
		"createdOn": "2021-12-27T12:02:38.437Z",
		"updatedOn": "2021-12-27T12:03:43.000Z"
	}
}

Delete user by ID DELETE /user/:id

This expects a token to make sure a user deletes his/her own account.

Example DELETE /user/1

Will return a 200 with

{
	"status": "success",
	"message": "User deleted successfully.",
	"data": {
		"email": "gloirekaleba@gmail.com",
		"firstName": null,
		"lastName": null,
		"profileImage": null,
		"isAdmin": true,
		"isVerified": false,
		"createdOn": "2021-12-27T12:02:38.437Z"
	}
}

Currency

Create currency POST /currency

Expected body model

{
  name: string;
  initials: string;
}

Example

{
	"name": "us dollars",
	"initials": "USD"
}

Will return a 201 with

{
	"status": "success",
	"message": "Currency created successfully.",
	"data": {
		"name": "us dollars",
		"initials": "USD",
		"id": 1
	}
}

Get currencies GET /currency

Example response: 200 with

{
	"status": "success",
	"message": "Found 1 currency(ies).",
	"data": [
		{
			"id": 1,
			"name": "us dollars",
			"initials": "USD"
		}
	]
}