diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 54c1c2c0..3023aa07 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -1,7 +1,7 @@ const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers') const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User') - +const { FriendRequest } = require('../models/supplier') //const User = require("../models/User"); const boom = require("boom"); @@ -527,3 +527,28 @@ exports.status = async (req, reply) => { } }; +exports.connectionStatus = async (req, reply) => { + try { + // query the database to check if the customer and supplier are connected + const isConnected = await User.findOne({ customerId: req.query.customerId }) + .populate('supplier', null, { supplierId: req.query.supplierId }) + .exec() + .then(customer => customer.supplier !== null); + + console.log("isconne..", isConnected) + + if (isConnected) { + // if customer and supplier are connected, return list of tankers + const tankers = await Tanker.find({ }).exec(); + console.log("tankers..", tankers) + reply.send({ tankers }); + } else { + // if customer and supplier are not connected, return error + reply.status(403).send({ error: 'Forbidden' }); + } + //res.send({ tankers }); + } catch (err) { + console.error(err); + reply.status(500).send({ error: 'Internal server error' }); + } +} \ No newline at end of file diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index b3015698..4c7a7fcf 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -6,7 +6,7 @@ const boom = require("boom"); const fastify = require("fastify")({ logger: true, }); -const tanksController = require("./tanksController") +// const tanksController = require("./tanksController") @@ -510,4 +510,4 @@ exports.consumption = async (req, reply) => { } catch (err) { throw boom.boomify(err); } -}; +}; \ No newline at end of file diff --git a/src/models/tankers.js b/src/models/tankers.js index 46bf80a3..81e8e02b 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -20,8 +20,12 @@ const tankersSchema = new mongoose.Schema({ capacity: { type: String}, supplier_address: { type: String, default: null }, supplier_name : { type: String, default: null }, - - status: { type: String} + + price: { + type: [String], + default: [] + }, + status: { type: String}, }); diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index b4ca6de0..aea3b9f2 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -53,6 +53,9 @@ module.exports = function (fastify, opts, next) { }, }, capacity: { type: "string"}, + price: {type : "string"}, + // status: {type: "string"} + }, @@ -583,7 +586,30 @@ module.exports = function (fastify, opts, next) { }); - + fastify.route({ + method: 'GET', + url: '/connection-status', + schema: { + tags: ["Supplier"], + description: "This is for Get Tank Data for status connected or not", + summary: "This is for to Get Tank Data for status connected or not", + querystring: { + type: 'object', + properties: { + customerId: { type: 'string' }, + //supplierId: { type: 'string' } + }, + required: ['customerId'] + }, + security: [ + { + basicAuth: [], + }, + ], + }, + handler: tankersController.connectionStatus + }); + next(); } diff --git a/src/tankers.js b/src/tankers.js new file mode 100644 index 00000000..e69de29b