raj 3 years ago
commit 5c28bf1784

@ -12,6 +12,7 @@ const fastify = require("fastify")({
exports.addTankers = async (req, reply) => {
try {
@ -28,7 +29,72 @@ console.log(req.params);
tankersData = {
supplierId:supplierId,
supplier_name:req.body.username,
supplier_name:req.body.supplier_name,
supplier_address : req.body.supplier_address,
tankerName: req.body.tankerName,
phoneNumber: req.body.phoneNumber,
alternative_phoneNumber: req.body.alternative_phoneNumber,
typeofwater: req.body.typeofwater,
capacity: req.body.capacity,
price: req.body.price,
status: req.body.status
};
console.log(req.body.typeofwater,req.body.capacity)
var tanker_Name = req.body.tankerName
var i_tank = await Tanker.findOne({ tankerName: tanker_Name,supplierId:supplierId})
if(i_tank){
throw new Error('tankername already exists');
}
else {
var tankers = new Tanker(tankersData);
checkFormEncoding = isUserFormUrlEncoded(req);
if (checkFormEncoding.isUserFormUrlEncoded) {
usertobeInserted = checkFormEncoding.tankers;
console.log("thsi true url string");
tankers.supplier_name = usertobeInserted.supplier_name;
tankers.supplier_address = usertobeInserted.supplier_address;
tankers.tankerName = usertobeInserted.tankerName;
tankers.phoneNumber = usertobeInserted.phoneNumber;
tankers.alternative_phoneNumber = usertobeInserted.alternative_phoneNumber;
tankers.capacity = usertobeInserted.capacity;
tankers.typeofwater = usertobeInserted.typeofwater;
tankers.price = usertobeInserted.price;
tankers.status = usertobeInserted.status;
}
}
const insertedTanker = await tankers.save();
return insertedTanker;
} catch (err) {
throw boom.boomify(err);
}
};
exports.deleteTankerInfo1 = async (req, reply) => {
try {
//const username = req.params.username;
console.log(req.params);
const supplierId = req.params.supplierId;
//console.log(loginObject.user.username)
// const userInfo = await User.findOne({ username: username.toString() });
// const updateData = req.body;
// console.log("This is the reply in the handler after the validations", reply);
tankersData = {
supplierId:supplierId,
supplier_name:req.body.supplier_name,
supplier_address : req.body.supplier_address,
tankerName: req.body.tankerName,
phoneNumber: req.body.phoneNumber,
@ -36,6 +102,7 @@ console.log(req.params);
typeofwater: req.body.typeofwater,
capacity: req.body.capacity,
price: req.body.price,
status: req.body.status
};
console.log(req.body.typeofwater,req.body.capacity)
@ -60,7 +127,7 @@ console.log(req.params);
tankers.capacity = usertobeInserted.capacity;
tankers.typeofwater = usertobeInserted.typeofwater;
tankers.price = usertobeInserted.price;
tankers.supplierId = usertobeInserted.supplierId;
tankers.status = usertobeInserted.status;
}
}
const insertedTanker = await tankers.save();
@ -437,3 +504,26 @@ exports.updatePipelineInfo = async (req, reply) => {
}
};
exports.status = async (req, reply) => {
try {
var status = req.query.status;
if (status === 'connected') {
try {
const tankers = await Tanker.find({});
console.log("tankers...", tankers)
reply.send(tankers);
} catch (err) {
reply.send({ message: err });
}
} else {
reply.send({ message: 'Not Connected' });
}
}
catch (err) {
throw boom.boomify(err);
}
};

@ -398,8 +398,9 @@ exports.sendSms = async (request, reply) => {
const apiKey = '2068323bea61494d315b';
const senderId = 'ARMNTA';
const mobile = request.body.mobileNumbers//'8341426949';
const message = `Welcome to Arminta !!! your OTP is ${code} please use it for login.`//`Welcome to Arminta !!! your OTP is ${code} please use it for login.`;
const message = `Welcome to Arminta !!! your OTP is ${code} please use it for login.`//`Welcome to Arminta !!! your OTP is ${code} please use it for login.`;
await User.findOneAndUpdate({phone: mobile}, { $set: {'phoneVerificationCode': code } })
const apiUrl = `https://smslogin.co/v3/api.php?username=${username}&apikey=${apiKey}&senderid=${senderId}&mobile=${mobile}&message=${encodeURIComponent(message)}`;
const options = {

@ -16,11 +16,13 @@ const tankersSchema = new mongoose.Schema({
phoneNumber: { type: String, default: null },
alternative_phoneNumber: { type: String, default: null },
typeofwater: [{ typeofwater: String}],
price:[{ typeofwater: String}],
capacity: { capacity: String},
price:[{ price: String}],
capacity: { type: String},
supplier_address: { type: String, default: null },
supplier_name : { type: String, default: null },
status: { type: String}
});
const tankersbookingSchema = new mongoose.Schema({

@ -53,7 +53,7 @@ module.exports = function (fastify, opts, next) {
},
},
capacity: { type: "string"},
price: {type : "string"}
},
},
@ -170,6 +170,7 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "POST",
url: "/api/bookingData/:customerId",
@ -552,9 +553,38 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "PUT",
url: "/api/deleteTanker1/:supplierId",
schema: {
tags: ["Supplier"],
summary: "This is to delete tanker",
params: {
required: ["supplierId"],
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
querystring: {
tankerName: {type: 'string'}
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tankersController.deleteTankerInfo1,
});
next();
}

Loading…
Cancel
Save