diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 2baa3d23..8dc715db 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -10,6 +10,7 @@ const libphonenumberjs = require("libphonenumber-js"); // offers http-friendly error objects. const boom = require("boom"); const { Tankerbooking} = require("../models/tankers") +const {EstimationOrder} = require("../models/store"); // Get Data Models const { RequestedBooking,Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier") @@ -1500,4 +1501,20 @@ exports.getallsuppliers = async (req, reply) => { } catch (err) { throw boom.boomify(err); } +}; + + +exports.estimationsget = async (req, reply) => { + try { + // Find the specific tank + const estimations = await EstimationOrder.find({customerId:req.params.customerId + }); + if (!estimations) { + return reply.send({ status_code: 404, error: "estimations not found" }); + } + // Send the found tank within a list + reply.send({ status_code: 200, data: [estimations] }); + } catch (err) { + throw boom.boomify(err); + } }; \ No newline at end of file diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 354728d1..d36d8dc3 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -1242,7 +1242,25 @@ fastify.route({ handler: userController.getallsuppliers }); - + fastify.route({ + method: "GET", + url: "/api/estimationsget/:customerId", + schema: { + tags: ["User"], + description: "Get all estimations for particular customer", + summary: "Get all estimations for particular customer", + params: { + type: "object", + properties: { + customerId: { type: "string" } + + }, + required: ["customerId"] + } + }, + handler: userController.estimationsget + }); + next(); };