kneric / server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ParcelPintar API

Codeship Status for ParcelPintar/server-parcel

Users Routes

Path Method Description
/users/register POST create new user account
/users/login POST login with existing account
/users/:id GET Get user by ID
/users/:id PATCH Update user by ID
/users/:id DELETE Delete user by ID

Register

Create new user account.

URL : /users/register

Method : POST

Auth required : No

Permissions required : None

Data constraints : { name: String, password : String, email: String (Unique) }

Success Responses


Condition : User Account successfully created.

Code : 201 OK

Content : { message : "User Successfully created", data:{} }

Error Responses


Condition : The requirements for creating new user account is not fullfilled.

Code : 500 Error

Content :

{
    message : <Error message depending on the data error>,
    data:{
        <Error data if in development, in production mode it's empty>
    }
}

Login

Login with existing account.

URL : /users/login

Method : POST

Auth required : No

Permissions required : None

Data constraints : { password : String, email: String }

Success Responses


Condition : User Successfully logged in.

Code : 200 OK

Content : { token: "<token generated by server>" }

Error Responses


Condition : Error when logging in, either wrong password or email

Code : 400 Not found

Content :

{
    message : "Wrong password or email",
    data:{}
}

Show User by ID

Show user by ID

URL : /users/:id

Method : GET

Auth required : YES

Permissions required : YES

Data constraints : {}

Success Responses


Condition : User found with such ID.

Code : 200 OK

Content :

{
    message: "User found",
    data:{
        name:"<user name>",
        orders:["<List of orders done by user>"],
        receive:["<List of received packets>"],
        email:"<user's email>"
    }
}

Error Responses


Condition : User not found

Code : 400 Not found

Content :

{
    message : "User not found",
    data:{}
}

Update User by ID

Update user by ID

URL : /users/:id

Method : PATCH

Auth required : YES

Permissions required : YES

Data constraints : { name:"<user's new name>", password:"<user's new password>", }

Success Responses


Condition : User found with such ID.

Code : 200 OK

Content :

{
    message: "User Modified",
    data:{
      <user's data after modification>
    }
}

Error Responses


Condition : User not found

Code : 400 Not found

Content :

{
    message : "User not found",
    data:{}
}

Delete User by ID

Delete user by ID

URL : /users/:id

Method : DELETE

Auth required : YES

Permissions required : YES

Data constraints : {}

Success Responses


Condition : User found with such ID.

Code : 200 OK

Content :

{
    message: "User successfully deleted",
    data:{
      <user's data that was deleted>
    }
}

Error Responses


Condition : User not found

Code : 400 Not found

Content :

{
    message : "User not found",
    data:{}
}

Parcels Routes

Path Method Description
/parcels POST Create new Parcel
/parcels GET Get all parcels
/parcels/:id GET Get parcel by ID
/parcels/:id PATCH Update parcel by ID
/parcels/:id DELETE Delete parcel by ID

Create new Parcel

Create new Parcel entity.

URL : /parcels

Method : POST

Auth required : Yes

Permissions required : Yes

Data constraints : { deviceID: String, gyro : String, gps: String }

Success Responses


Condition : Parcel successfully created.

Code : 201 OK

Content : { message : "Parcel Successfully created", data:{} }

Error Responses


Condition : The requirements for creating new parcel is not fullfilled.

Code : 500 Error

Content :

{
    message : <Error message depending on the data error>,
    data:{
        <Error data if in development, in production mode it's empty>
    }
}

Show Parcel by ID

Show parcel by ID

URL : /parcels/:id

Method : GET

Auth required : YES

Permissions required : YES

Data constraints : {}

Success Responses


Condition : Parcel found with such ID.

Code : 200 OK

Content :

{
    message: "Parcel found",
    data:{
        _id:"<parcel id>",
        gyro:{
			threshold:<boolean>
		},
        gps: {
			location:{
				long:<number>
				lat:<number>
			}
		}
    }
}

Error Responses


Condition : Parcel not found

Code : 400 Not found

Content :

{
    message : "Parcel not found",
    data:{}
}

Update Parcel by ID

Update Parcel by ID

URL : /parcels/:id

Method : PATCH

Auth required : YES

Permissions required : YES

Data constraints :

{
    long: number,
    lat: number,
	threshold: boolean
}

Success Responses


Condition : Parcel found with such ID.

Code : 200 OK

Content :

{
    message: "Parcel Modified",
    data:{
      <parcel's data after modification>
    }
}

Error Responses


Condition : Parcel not found

Code : 400 Not found

Content :

{
    message : "Parcel not found",
    data:{}
}

Delete Parcel by ID

Delete parcel by ID

URL : /parcels/:id

Method : DELETE

Auth required : YES

Permissions required : YES

Data constraints : {}

Success Responses


Condition : Parcel found with such ID.

Code : 200 OK

Content :

{
    message: "Parcel successfully deleted",
    data:{
      <parcel's data that was deleted>
    }
}

Error Responses


Condition : Parcel not found

Code : 400 Not found

Content :

{
    message : "Parcel not found",
    data:{}
}

Orders Routes

Path Method Description
/orders POST Create new Order
/orders/me/send GET Get order where logged in user is the sender
/orders/me/receive GET Get order where logged in user is the receiver
/orders/:id GET Get order by ID
/orders/:id PATCH Update order by ID
/orders/:id DELETE Delete order by ID

Create new Order

Create new Order entity from where Logged in user is the sender

URL : /orders

Method : POST

Auth required : Yes

Permissions required : No

Data constraints : { deviceID: String, gyro : String, gps: String }

Success Responses


Condition : Order successfully created.

Code : 201 OK

Content : { message : "Order Successfully created", data:{} }

Error Responses


Condition : The requirements for creating new Order is not fullfilled.

Code : 500 Error

Content :

{
    message : <Error message depending on the data error>,
    data:{
        <Error data if in development, in production mode it's empty>
    }
}

Show orders by User logged in

show orders where user's role is sender

URL : /orders/me/send

Method : GET

Auth required : Yes

Permissions required : No

Data constraints : {[]}

Success Responses


Condition : Order successfully Retrived, but no data yet.

Code : 200 OK

Content :

{
    message : "Order found",
    data:[]
}

OR

Condition : Order successfully Retrived with data.

Code : 200 OK

Content :

{
    message : "Order found",
    data:[
            {
                <Order's data>
            },
            {
                <Order's data>
            }
        ]
}

Show receive by User logged in

show orders where user's role is receiver

URL : /orders/me/receive

Method : GET

Auth required : Yes

Permissions required : No

Data constraints : {[]}

Success Responses


Condition : Order successfully Retrived, but no data yet.

Code : 200 OK

Content :

{
    message : "Order found",
    data:[]
}

OR

Condition : Order successfully Retrived with data.

Code : 200 OK

Content :

{
    message : "Order found",
    data:[
            {
                <Order's data>
            },
            {
                <Order's data>
            }
        ]
}

Show Order by ID

Show orders by ID

URL : /orders/:id

Method : GET

Auth required : YES

Permissions required : YES

Data constraints : {}

Success Responses


Condition : Orders found with such ID.

Code : 200 OK

Content :

{
    message: "Orders found",
    data:{
        _id:"<parcel id>",
        status: <status enum>,
        sender: <ref to user>
        receiver: <ref to user>
        destination: "Pondok Indah"
    }
}

Error Responses


Condition : Order not found

Code : 400 Not found

Content :

{
    message : "Order not found",
    data:{}
}

Update Order by ID

Update Order by ID

URL : /orders/:id

Method : PATCH

Auth required : YES

Permissions required : YES

Data constraints :

{
    sender:<new sender id>,
    receiver:<new reciever id>
    status:<new status>,
}

Success Responses


Condition : Order found with such ID and modified.

Code : 200 OK

Content :

{
    message: "Orders Modified",
    data:{
      <order's data after modification>
    }
}

Error Responses


Condition : Order not found

Code : 400 Not found

Content :

{
    message : "Order not found",
    data:{}
}

Delete Order by ID

Delete Order by ID

URL : /orders/:id

Method : DELETE

Auth required : YES

Permissions required : YES

Data constraints : {}

Success Responses


Condition : Order found with such ID.

Code : 200 OK

Content :

{
    message: "Order successfully deleted",
    data:{
      <order's data that was deleted>
    }
}

Error Responses


Condition : Order not found

Code : 400 Not found

Content :

{
    message : "Order not found",
    data:{}
}

About


Languages

Language:JavaScript 91.8%Language:HTML 8.2%