This is a web service for order management for an internal team. Tech stack used:-
Nest framework
TypeScript laguage
Jest for testing
Postgresql database
Typeorm Orm
The reason of using a combination of typescript and nestjs is that it provides us to write code in a structural way. It gives us the advantage of using classes, Dtos, interfaces, modules etc. to reduces inconsistencies in the code. It allows us to keep our code well structured and maintainable.
Go to the root directory and run following command.
$ npm install
node version 16
# development
$ npm run start:dev
# unit tests
$ npm run test
The basic assumption behind the problem statement is that there are orders of a product which belong to a unique service type. And other teams should be able to see the order information
After completion of the project there will be a fully functional internal webservice(restful architecture) available to the teams which the can use to access and edit information
- This webservice has 2 models.
- Order : this is considered as a document having details of a general order. Every order will have a unique id.
- Service: this is considered as a service type to which an order can ne mapped.Every service will have a unique name.
# Order Schema
{
id: number; (unique)
dateTime: Date;
totalFee: number;
serviceId: number;
isArchived: boolean;
createdAt: Date;
updatedAt: Date;
}
# Service Schema
{
id: number; (unique)
name: string; (unique)
createdAt: Date;
updatedAt: Date;
}
- In this webservice there are functionalities to add, update, delete, get all and get a single record. These have been implemented to both orders and services.
- Methods used are POST, PUT, GET, DELETE.
- There are in total 10 apis in the webservice 5 each for order and services.
- Following are the functionalities for Orders
addOrder
> to create a new orderupdateOrder
> to update an existing order only of it was created 3 hours before.getAllOrder
> to fetch all the ordersgetOrderById
> to get 1 perticular orderdeleteOrder
> to delete an order
- Following are the functionalities for Service
addService
> to create a new Service checking uniqueness of the service name.updateService
> to update an existing Service checking uniqueness of the service name.getAllService
> to fetch all the ServicesgetServiceById
> to get 1 perticular ServicedeleteService
> to delete a Service
- Since all are internal apis are to be used by internal teams, all the apis are guarded with an
internal api key
which is kept inside .env file. You can change its value according to your convenience it is necessary to passinternal-api-key
inside headers to access the apis. Jest
has been used to write the test cases. to run test runnpm run test
addOrder
- endpoint ->
localhost:3000/order
method POST
curl --location --request POST 'localhost:3000/order' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{ "dateTime":"2022-11-01T11:11:11.111Z", "totalFee":4000, "serviceId":70 }'
- endpoint ->
updateOrder
- endpoint ->
localhost:3000/order/:id
method PUT
curl --location --request PUT 'localhost:3000/order' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{ "dateTime":"2022-11-01T11:11:11.111Z", "totalFee":4000, "serviceId":70 }'
- endpoint ->
getAllOrders
- endpoint ->
localhost:3000/order
method Get
curl --location --request GET 'localhost:3000/order' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
getOrderById
- endpoint ->
localhost:3000/order/:id
method Get
curl --location --request GET 'localhost:3000/order/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
- endpoint ->
deleteService
- endpoint ->
localhost:3000/order/:id
method Deletecurl --location --request DELETE 'localhost:3000/order/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
addService
- endpoint ->
localhost:3000/service
method POST
curl --location --request POST 'localhost:3000/service' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{ "name":"analysis" }'
- endpoint ->
updateService
- endpoint ->
localhost:3000/service/:id
method PUT
curl --location --request PUT 'localhost:3000/service/8' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{ "name":"analysisq" }'
- endpoint ->
getAllServices
- endpoint ->
localhost:3000/service
method Getcurl --location --request GET 'localhost:3000/service' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json
getServiceById
- endpoint ->
localhost:3000/service/:id
method Getcurl --location --request GET 'localhost:3000/service/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
- endpoint ->
deleteService
- endpoint ->
localhost:3000/service/:id
method Deletecurl --location --request DELETE 'localhost:3000/service/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
- endpoint ->
- Env file has been added in the project.
- You will have to add a database named
randomDb
, runnpm i
and the runnpm run start:dev
.