raj 3 years ago
commit 7725eaec7e

@ -1,8 +1,7 @@
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers') const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
const { FriendRequest } = require('../models/supplier')
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User') const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User')
const { FriendRequest } = require('../models/supplier')
//const User = require("../models/User"); //const User = require("../models/User");
const boom = require("boom"); const boom = require("boom");
@ -531,7 +530,7 @@ exports.status = async (req, reply) => {
exports.connectionStatus = async (req, reply) => { exports.connectionStatus = async (req, reply) => {
try { try {
// query the database to check if the customer and supplier are connected // query the database to check if the customer and supplier are connected
const isConnected = await FriendRequest.findOne({ customerId: req.query.customerId }) const isConnected = await User.findOne({ customerId: req.query.customerId })
.populate('supplier', null, { supplierId: req.query.supplierId }) .populate('supplier', null, { supplierId: req.query.supplierId })
.exec() .exec()
.then(customer => customer.supplier !== null); .then(customer => customer.supplier !== null);
@ -540,12 +539,12 @@ exports.connectionStatus = async (req, reply) => {
if (isConnected) { if (isConnected) {
// if customer and supplier are connected, return list of tankers // if customer and supplier are connected, return list of tankers
const tankers = await Tanker.find({ status : 'connected'}).exec(); const tankers = await Tanker.find({ }).exec();
console.log("tankers..", tankers) console.log("tankers..", tankers)
reply.send({ tankers }); reply.send({ tankers });
} else { } else {
// if customer and supplier are not connected, return error // if customer and supplier are not connected, return error
reply.status(403).send({ error: 'Forbidden' });8 reply.status(403).send({ error: 'Forbidden' });
} }
//res.send({ tankers }); //res.send({ tankers });
} catch (err) { } catch (err) {

@ -6,7 +6,7 @@ const boom = require("boom");
const fastify = require("fastify")({ const fastify = require("fastify")({
logger: true, logger: true,
}); });
const tanksController = require("./tanksController") // const tanksController = require("./tanksController")
@ -510,4 +510,4 @@ exports.consumption = async (req, reply) => {
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };

@ -597,24 +597,10 @@ module.exports = function (fastify, opts, next) {
type: 'object', type: 'object',
properties: { properties: {
customerId: { type: 'string' }, customerId: { type: 'string' },
supplierId: { type: 'string' } //supplierId: { type: 'string' }
}, },
required: ['customerId', 'supplierId'] required: ['customerId']
}, },
// response: {
// 200: {
// type: 'object',
// properties: {
// isConnected: { type: 'boolean' }
// }
// },
// 500: {
// type: 'object',
// properties: {
// error: { type: 'string' }
// }
// }
// }
security: [ security: [
{ {
basicAuth: [], basicAuth: [],
@ -624,6 +610,7 @@ module.exports = function (fastify, opts, next) {
handler: tankersController.connectionStatus handler: tankersController.connectionStatus
}); });
next(); next();
} }

Loading…
Cancel
Save