tank name uniquenesst,added payment system to delivery boy

master
varun 3 years ago
parent b9de78e368
commit 42612bb437

@ -305,3 +305,24 @@ exports.deliveryboystartandstop = async (req, reply) => {
exports.amountUpdateByDeliveryBoy = async (req, reply) => {
try {
console.log(req.params.supplierId)
const amount_paid = parseInt(req.body.amount_paid.replace(/,/g, ''), 10)
const payment_mode = req.body.payment_mode
const booking = await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId});
const tanker_price = parseInt(booking.price.replace(/,/g, ''), 10)
const amount_due = tanker_price-amount_paid
await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId}, { $set: { amount_paid: amount_paid,amount_due:amount_due,payment_mode:payment_mode} });
const booking_data = await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId});
const final_amount_due = parseInt(booking_data.amount_due.replace(/,/g, ''), 10)
if(final_amount_due === 0){
await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId}, { $set: { payment_status:"paid" }});
}
} catch (err) {
throw boom.boomify(err);
}
};

@ -32,11 +32,13 @@ console.log(req.params);
capacity: req.body.capacity,
typeOfWater: req.body.typeOfWater,
tankLocation:(req.body.tankLocation).toLowerCase(),
tankLocation:req.body.tankLocation.toLowerCase(),
};
//console.log( req.body.tankLocation.toLowerCase())
var tank_name = req.body.tankName
var tankLocation = req.body.tankLocation
var tankLocation = req.body.tankLocation.toLowerCase()
var i_tank = await Tank.findOne({ tankName: tank_name,customerId:customerId,tankLocation:tankLocation})
if(i_tank){
throw new Error('tankname already exists');
@ -56,6 +58,7 @@ console.log(req.params);
tank.typeOfWater = usertobeInserted.typeOfWater;
tank.tankLocation = (usertobeInserted.tankLocation).toLowerCase();
console.log((usertobeInserted.tankLocation).toLowerCase())
}
}
const insertedTank = await tank.save();

@ -256,7 +256,45 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "PUT",
url: "/api/amountpaidByCustomer/:bookingId",
schema: {
tags: ["Supplier"],
summary: "This is for delivery boy to update the amount paid by customer after start and stop",
params: {
required: ["bookingId"],
type: "object",
properties: {
bookingId: {
type: "string",
description: "bookingId",
},
},
},
body: {
type: "object",
// required: ['phone'],
properties: {
amount_paid: { type: "string" },
payment_mode: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
preHandler: fastify.auth([fastify.authenticate]),
handler: supplierOrderController.amountUpdateByDeliveryBoy,
});
next();
}

Loading…
Cancel
Save