changes updated controllers models routes

master
raj 3 years ago
commit 54a2decdfd

@ -1,4 +1,5 @@
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')
@ -527,3 +528,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 FriendRequest.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({ status : 'connected'}).exec();
console.log("tankers..", tankers)
reply.send({ tankers });
} else {
// if customer and supplier are not connected, return error
reply.status(403).send({ error: 'Forbidden' });8
}
//res.send({ tankers });
} catch (err) {
console.error(err);
reply.status(500).send({ error: 'Internal server error' });
}
}

@ -21,7 +21,11 @@ const tankersSchema = new mongoose.Schema({
supplier_address: { type: String, default: null }, supplier_address: { type: String, default: null },
supplier_name : { type: String, default: null }, supplier_name : { type: String, default: null },
status: { type: String} price: {
type: [String],
default: []
},
status: { type: String},
}); });

@ -53,6 +53,9 @@ module.exports = function (fastify, opts, next) {
}, },
}, },
capacity: { type: "string"}, capacity: { type: "string"},
price: {type : "string"},
// status: {type: "string"}
}, },
@ -583,7 +586,43 @@ 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', 'supplierId']
},
// response: {
// 200: {
// type: 'object',
// properties: {
// isConnected: { type: 'boolean' }
// }
// },
// 500: {
// type: 'object',
// properties: {
// error: { type: 'string' }
// }
// }
// }
security: [
{
basicAuth: [],
},
],
},
handler: tankersController.connectionStatus
});
next(); next();
} }

Loading…
Cancel
Save