Ticket Booking REST API made using Node.js, Express and MongoDB.
express
mongoose
cors
node-cron
dotenv
chai
mocha
supertest
mockgoose$ npm i$ node app.jsUnit testing has been done on the individual routes using mocha, an extensive javascript testing for Node.js, paired with chai, an assertion library.
$ npm run test-
Marks tickets as expired if there is a difference of 8 hours between ticket time and current time. Runs every minute asynchronously. -
Deletes tickets from the database if they are expired. Runs every hour asynchronously.
Has ticket and customer routes.
Tested using Postwoman/Hoppscotch API client. Screenshots here.
-
URL :
/ticket/all
Method :GET
URL Params : None
Data Params : None
Success Response :Status 200[ { "_id" : ObjectId, "booked" : Boolean, "expired" : Boolean, "time" : Date, "customer" : ObjectId } ... ] -
URL :
/ticket/:time
Method :GET
URL Params :time = [YYYY-MM-DDTHH:MM]
Data Params : None
Success Response :Status 200[ { "_id" : ObjectId, "booked" : Boolean, "expired" : Boolean, "time" : Date, "customer" : ObjectId } ... ]Error Response :
Status 404{ "err": "No tickets found for that time." } -
URL :
/ticket/add
Method :POST
URL Params : None
Data Params : time{ "time": "YYYY-MM-DDTHH:MM" //Required }Success Response :
Status 201{ "success": "Ticket with ID : {id} created for time {time}" }Error Response :
Status 400{ "err": "20 Tickets already exist for time {time}. Cannot create more than 20 tickets." } -
URL :
/ticket/update
Method :PUT
URL Params : None
Data Params :idtime{ "id": ObjectID, //Required "time": "YYYY-MM-DDTHH:MM" // Required }Success Response :
Status 201{ "success": "Successfully updated time from {oldtime} to {newtime}" }Error Response :
Status 404{ "err": "No ticket with that ID exists" } -
URL :
/ticket/delete
Method :DELETE
URL Params : None
Data Params :id{ "id": ObjectID // Required }Success Response :
Status 200{ "success": "Successfully deleted ticket with id {id}" }Error Response :
Status 404{ "err": "No ticket with that ID exists" } -
URL :
/ticket/get-customer/:id
Method :GET
URL Params :id = [ObjectId]
Data Params : None
Success Response :Status 200{ "_id" : ObjectId, "name" : String, "phone" : String, "tickets" : [...] }Error Response :
Status 404{ "err": "No ticket with that ID exists" }OR
Status 400{ "err": "That ticket hasn't been booked yet" }
-
URL :
/customer/all
Method :GET
URL Params : None
Data Params : None
Success Response :Status 200[ { "_id" : ObjectId, "name" : String, "phone" : String, "tickets" : [...] } ... ] -
URL :
/customer/book
Method :POST
URL Params : None
Data Params :namephonetimetickets{ "name": String, //Required "phone": String, //Required "time": Date, //Required "tickets": Number //Required }Success Response :
Status 200{ "success": " {tickets} tickets booked successfully !" }Error Response :
Status 401{ "err": "No ticket available for time {time}" } OR { "err": "Only {number} ticket(s) are available !" } -
URL :
/customer/add
Method :POST
URL Params : None
Data Params :namephone{ "name": String, //Required "phone": String //Required }Success Response :
Status 200{ "success": "Customer added successfully" }Error Response :
Status 400{ "err": "Customer already exists" } -
URL :
/customer/:name
Method :GET
URL Params :name = [String]
Data Params : None
Success Response :Status 200{ "id" : ObjectId, "name" : String, "phone" : String, "tickets" : [...] }Error Response :
Status 404{ "err": "No customer with name {name} exists" }
P.S. This was the problem statement of Zomentum Hiring Assignment. Thanks for making me do this. Learnt a lot!