/Contact-Management

This Utility app will be helpful for managing your contacts.

Primary LanguageJavaScript

Contact-Management

Manage your Contacts on apps you develop with this companion backend.
TOC:

Environment Variables

Varname Definition required
PORT Port on which the backend will be hosted YES
MONGODB_URI URI string to the MongoDB YES
COOKIE_SECRET Sercret used to sign Cookies with YES
TOKEN_SECRET Secret to Sign JWT Token with YES

Routes


~/

Method: GET
Action: Base route\

Response:

{
    "state": "OK",
    "url": "/"
}

~/health

Method: GET
Action: Get some details about the servers health

Response:

{
  "status": "",
  "uptime": ,
  "upSince": "",
  "localTime": "",
  "service": {
    "name": "",
    "version": ""
  },
  "connections": {
    "database": ""
  },
  "env": {
    "nodeVersion": "",
    "processName": "",
    "pid": ,
    "cwd":  ""
  },
  "git": {
    "commitHash": "",
    "branchName": "",
    "tag":
  }
}

~/api/auth/signin

Method: POST
Action: Signs in a user. After a successfull login, token is set into a cookie and sent to client, while also being sent in the Response object

Request:

{
    "email": "",
    "password": ""
}

email: Email for signing in.

password: Password for signing in.

Response:

{
  "success": ,
  "User": {
    "uName": "",
    "fName": "",
    "lName": "",
    "contact": {
      "email": "",
      "phone": ""
    }
  },
  "token": ""
}

~/api/auth/signup

Method:POST
Action: Signs in a user. After a successfull login, token is set into a cookie and sent to client, while also being sent in the Response object

Request:

{
    "fName": "",
    "lName": "",
    "uName": "",
    "email": "",
    "phone": "",
    "password": ""
}

fName: First Name of the User

lName: Last Name of the User

uName: User Name of the User

email: Email for the User

phone: Phone number of the User

password: password for the User Account

Response:

{
    "state": ""
}

~/api/auth/signout

Method:POST
Action: This Routes will remove the Cookies set by express which contains the JWT token


~/api/v1/profile

Needs Auth
Method:POST
Action: Get the profile of the currently logged in user

Response:

{
    "meta": {
        "createdAt": ""
    },
    "contact": {
        "email": "",
        "phone": ""
    },
    "fName": "",
    "lName": "",
    "uName": ""
}

~/api/v1/contacts

Needs Auth
Mehtod: GET
Action: Get a list of contacts, added under a specific user

Response:

[
    .,
    {
        "meta": {
            "createdAt": ""
        },
        "contact": {
            "email": "",
            "phone": ""
        },
        "_id": "",
        "cName": "",
        "cType": ""
    },
    .
    .
    .
]

~/api/v1/contacts/:cid

Needs Auth
Method: GET
Action: If the cid url parameter is provided, returns with the cotact details with _id responing to that cid. If not supplied, returns a list of contacts under that user.

Response:

{
    "meta": {
        "createdAt": ""
    },
    "contact": {
        "email": "",
        "phone": ""
    },
    "_id": "",
    "cName": "",
    "cType": ""
}

~/api/v1/contacts/:cid

Needs Auth
Method: POST
Action: Create a new Contact under the currently signed in user

{
    "cName": "",
    "email": "",
    "phone": "",
    "cType": ""
}

cName: Name of the contact (required)

email: Email address of the contact (required)

phone: Phone number of the contact (required)

cType: Type of contact detail (optional) [defaults: NULL]

Response:

{
    "state": ""
}

~/api/v1/contacts/:cid

Needs Auth
Method: PUT
Action: Updates only one field that has been supplied on the Request body on the database object with _id of cid

Payload:

{
    "key": "",
    "value": ""
}

key: can be one of these (cName, cType, email, phone)

value: new value to replace to old value with

Response:

{
    "state": ""
}

~/api/v1/contacts/:cid

Needs Auth
Method: DELETE
Action: Deletes the Contact related to the given cid url parameter if the contact is created by the currently logged user

Response:

{
    "state": ""
}