made changes

master
varun 3 years ago
parent 636d286763
commit 9a4974a006

@ -0,0 +1,39 @@
const Supplier = require("../models/supplier");
const boom = require("boom");
const fastify = require("fastify")({
logger: true,
});
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
exports.orderNow = async (req, reply) => {
try {
const customerId = req.body.customerId;
const bookingId = req.params.bookingId;
const tankerName = req.body.tankerName;
const booking_info = await Tankerbooking.findOne({ bookingid: bookingId})
const action = req.body.action
const typeofwater = req.body.typeofwater
if(action === "accept"){
booking_info.orderStatus = "accepted"
booking_info.price = "500"
}
else {
booking_info.orderStatus = "rejected"
}
const booking = await booking_info.save();
return booking;
} catch (err) {
throw boom.boomify(err);
}
};

@ -18,7 +18,7 @@ exports.addTankers = async (req, reply) => {
//const username = req.params.username;
console.log(req.params);
var customerId = req.params.customerId;
const supplierId = req.params.supplierId;
//console.log(loginObject.user.username)
// const userInfo = await User.findOne({ username: username.toString() });
// const updateData = req.body;
@ -26,7 +26,7 @@ console.log(req.params);
// console.log("This is the reply in the handler after the validations", reply);
tankersData = {
customerId:customerId,
supplierId:supplierId,
tankerName: req.body.tankerName,
phoneNumber: req.body.phoneNumber,
alternative_phoneNumber: req.body.alternative_phoneNumber,
@ -36,7 +36,7 @@ console.log(req.params);
console.log(req.body.typeofwater,req.body.capacity)
var tanker_Name = req.body.tankerName
var i_tank = await Tanker.findOne({ tankerName: tanker_Name,customerId:customerId})
var i_tank = await Tanker.findOne({ tankerName: tanker_Name,supplierId:supplierId})
if(i_tank){
throw new Error('tankername already exists');
}
@ -53,7 +53,7 @@ console.log(req.params);
tankers.alternative_phoneNumber = usertobeInserted.alternative_phoneNumber;
tankers.capacity = usertobeInserted.capacity;
tankers.typeofwater = usertobeInserted.typeofwater;
tankers.customerId = usertobeInserted.customerId;
tankers.supplierId = usertobeInserted.supplierId;
}
}
const insertedTanker = await tankers.save();
@ -70,11 +70,11 @@ console.log(req.params);
exports.updateTankersInfo = async (req, reply) => {
try {
var customerId = req.params.customerId;
var supplierId = req.params.supplierId;
var tankerName = req.query.tankerName;
var tanker = req.body;
const { ...updateData } = tanker;
const update = await Tanker.findOneAndUpdate({ customerId:customerId,tankerName: tankerName, }, updateData, { new: true });
const update = await Tanker.findOneAndUpdate({ supplierId:supplierId,tankerName: tankerName, }, updateData, { new: true });
//console.log(update.username)
//return update;
@ -90,9 +90,9 @@ exports.updateTankersInfo = async (req, reply) => {
//delete selected tanker
exports.deleteTankerInfo = async (req, reply) => {
try {
var customerId = req.params.customerId;
var supplierId = req.params.supplierId;
var tankerName = req.query.tankerName;
const tanker = await Tanker.findOneAndDelete({ customerId:customerId,tankerName: tankerName, });
const tanker = await Tanker.findOneAndDelete({ supplierId:supplierId,tankerName: tankerName, });
reply.send({ status_code: 200, data: tanker});
// return tanker;
} catch (err) {
@ -164,7 +164,7 @@ exports.tankerBooking = async (req, reply) => {
exports.getTanker = async (req, reply) => {
try {
await Tanker.find({customerId: req.query.customerId})
await Tanker.find({supplierId: req.query.supplierId})
.exec()
.then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length });

@ -256,7 +256,7 @@ exports.motorAction = async (req, reply) => {
const action = req.body.action
const receiver_tank = req.body.to
const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:(req.body.to_type).toLowerCase()});
const receiver_capacity = receiver_tank_info.capacity
const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10)
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)

@ -57,10 +57,10 @@ fastify.register(fastifyEnv, options).ready((err) => {
const apiversion = "1.0.0";
// fastify.register(require('fastify-cookie'))
fastify.register(require('fastify-session'), {
secret: 'my-secret-key',
cookie: { secure: true }
});
// fastify.register(require('fastify-session'), {
// secret: 'my-secret-key',
// cookie: { secure: true }
// });
isSupplierFormUrlEncoded = (req) => {
var isSupplierFormUrlEncoded = false;

@ -336,6 +336,7 @@ fastify.register(require("./routes/tanksRoute"));
fastify.register(require("./routes/createConnectionsRoute"));
fastify.register(require("./routes/tankersRoute.js"));
fastify.register(require("./routes/supplierRoute"));
fastify.register(require("./routes/supplierOrdersRoutes"));
// Testing route allows for retrieving a user by phone so one can see what is the phone verification code sent for a given user's phone

@ -11,7 +11,7 @@ const RoleSchema = new Schema({ name: String });
const tankersSchema = new mongoose.Schema({
customerId: { type: String, default: null },
supplierId: { type: String, default: null },
tankerName: { type: String, default: null },
phoneNumber: { type: String, default: null },
alternative_phoneNumber: { type: String, default: null },
@ -24,6 +24,7 @@ const tankersbookingSchema = new mongoose.Schema({
customerId: { type: String, default: null },
tankerName: { type: String, default: null },
bookingid: { type: String, default: null,unique: true },
supplierId:{type: String, default: null},
dateOfOrder: { type: String, default: null },
date: { type: String, default: null },
time: { type: String, default: null },

@ -0,0 +1,65 @@
const fastify = require("fastify");
const supplierOrderController = require("../controllers/supplierOrderController");
const validationHandler = require("../handlers/supplierHandler");
module.exports = function (fastify, opts, next) {
fastify.route({
method: "POST",
url: "/api/ordernow/:bookingId",
schema: {
tags: ["Supplier-Order"],
description:"This is for giving booking data to supplier",
summary: "This is for giving booking data to supplier",
params: {
required: ["bookingId"],
type: "object",
properties: {
bookingId: {
type: "string",
description: "bookingId",
},
},
},
body: {
type: "object",
properties: {
supplierName: {type: 'string'},
supplierId: { type: "string" },
customerId:{type:"string"},
capacity: { type: "string" },
customer_address: { type: "string" },
dateOfOrder: { type: "string"},
action:{type:"string"},
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: fastify.auth([fastify.authenticate]),
handler:supplierOrderController.orderNow,
// onResponse: (request, reply) => {
// validationHandler.sendPhoneVerificationCode(request, reply);
// },
//onResponse: validationHandler.sendPhoneVerificationCode,
});
next();
}

@ -8,18 +8,18 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "POST",
url: "/api/addTankers/:customerId",
url: "/api/addTankers/:supplierId",
schema: {
tags: ["Supplier"],
description: "This is to cretae New Tanker",
summary: "This is to Create New Tanker.",
params: {
required: ["customerId"],
required: ["supplierId"],
type: "object",
properties: {
customerId: {
supplierId: {
type: "string",
description: "customerId",
description: "supplierId",
},
},
},
@ -74,17 +74,17 @@ module.exports = function (fastify, opts, next) {
//update tankers
fastify.route({
method: "PUT",
url: "/api/updateTankers/:customerId",
url: "/api/updateTankers/:supplierId",
schema: {
tags: ["Supplier"],
summary: "This is to update tanker",
params: {
required: ["customerId"],
required: ["supplierId"],
type: "object",
properties: {
customerId: {
supplierId: {
type: "string",
description: "customerId",
description: "supplierId",
},
},
},
@ -138,17 +138,17 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "PUT",
url: "/api/deleteTanker/:customerId",
url: "/api/deleteTanker/:supplierId",
schema: {
tags: ["Supplier"],
summary: "This is to delete tanker",
params: {
required: ["customerId"],
required: ["supplierId"],
type: "object",
properties: {
customerId: {
supplierId: {
type: "string",
description: "customerId",
description: "supplierId",
},
},
},
@ -220,7 +220,7 @@ module.exports = function (fastify, opts, next) {
description: "This is for Get Tanker Data",
summary: "This is for to Get Tanker Data",
querystring: {
customerId: {type: 'string'}
supplierId: {type: 'string'}
},
security: [
{

Loading…
Cancel
Save