diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index 96e3f2f2..e24d4fd9 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -356,7 +356,9 @@ exports.deliveryboystartandstop = async (req, reply) => { const start_water_level = parseInt(booking_data.initial_water_level.replace(/,/g, ''), 10) const quantity_delivered = final_receiver_waterlevel-start_water_level - const distrubance_price = parseInt(quantity_delivered.replace(/,/g, ''), 10)*price_per_liter + // const distrubance_price = parseInt(quantity_delivered.replace(/,/g, ''), 10)*price_per_liter + const distrubance_price = quantity_delivered * price_per_liter + const amount_difference = price - distrubance_price await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { final_water_level: final_receiver_waterlevel ,stop_time:stop_time,quantityDelivered:quantity_delivered,distrubance_price:distrubance_price,amount_difference:amount_difference,tankerRunningStatus:"0"} }); reply.send({ status_code: 200, "stop time": stop_time,"final water level":final_receiver_waterlevel}); diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 23176bbe..759b1631 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -220,8 +220,8 @@ exports.tankerBooking = async (req, reply) => { supplierId:req.body.supplierId, tankName:req.body.tankName, tankLocation:req.body.tankLocation, - // latitude: req.body.latitude, - // longitude: req.body.longitude, + latitude: req.body.latitude, + longitude: req.body.longitude, //date: req.body.date, // time: req.body.time, customerPhone : customerPhone, @@ -254,8 +254,8 @@ exports.tankerBooking = async (req, reply) => { tankersBookingData.supplierPhone = supplierPhone; tankersBookingData.customerName = customerName; tankersBookingData.supplierName = supplierName; - // tankersBookingData.latitude =usertobeInserted.latitude - // tankersBookingData.longitude=usertobeInserted.longitude + tankersBookingData.latitude =usertobeInserted.latitude + tankersBookingData.longitude=usertobeInserted.longitude } } diff --git a/src/handlers/supplierHandler.js b/src/handlers/supplierHandler.js index 2d88e7ce..b8824f61 100644 --- a/src/handlers/supplierHandler.js +++ b/src/handlers/supplierHandler.js @@ -1,5 +1,5 @@ //Get the data models -const { Supplier, DeliveryBoy } = require("../models/supplier"); +const { Supplier, DeliveryBoy, profilePictureSupplier } = require("../models/supplier"); const { FriendRequest } = require("../models/supplier"); const { ProfilePicture, User } = require("../models/User"); const supplierController = require("../controllers/supplierController"); @@ -173,7 +173,7 @@ exports.loginSupplier = async (request, reply) => { var s_id = loginObject.supplier.supplierId; console.log(s_id, "supplierId"); - var profilePicture = await ProfilePicture.findOne({ supplierId: s_id }); + var profilePicture = await profilePictureSupplier.findOne({ supplierId: s_id }); // request.session.set('supplierId', loginObject.supplier._id) @@ -1189,3 +1189,29 @@ exports.getconnectedCustomers = async (req, reply) => { throw boom.boomify(err); } }; + + +exports.uploadProfilePicture = async (req, reply) => { + try { + const supplierId = req.params.supplierId; + const picture = req.body.picture; + + let profilePicture = await profilePictureSupplier.findOne({ supplierId }); + + console.log(profilePicture,"profile===") + if (!profilePicture) { + profilePicture = new profilePictureSupplier({ + supplierId, + picture, + }); + } else { + profilePicture.picture = picture; + } + + await profilePicture.save(); + + reply.send({ message: 'Profile picture uploaded successfully' }); + } catch (error) { + reply.status(500).send({ error: error.message }); + } +}; diff --git a/src/models/User.js b/src/models/User.js index fc6f6c06..2e536c89 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -114,18 +114,37 @@ const userSchema = new mongoose.Schema( { versionKey: false } ); +// const profilePictureSchema = new Schema({ +// customerId: { +// type: String,unique: true, +// required: true +// }, +// picture: { +// type: String, +// required: true +// } +// }); const profilePictureSchema = new Schema({ customerId: { - type: String,unique: true, + type: String, + unique: true, required: true }, picture: { - type: String, - required: true + type: { + type: String, + enum: ['jpeg', 'png', 'gif'], // add the file formats you support here + required: true + }, + data: { + type: Buffer, + required: true + } } }); + const ProfilePicture = mongoose.model('ProfilePicture', profilePictureSchema); const Counter = mongoose.model('Counter', CounterSchema); const User = mongoose.model("User", userSchema); diff --git a/src/models/supplier.js b/src/models/supplier.js index 13e3d143..9d246f60 100644 --- a/src/models/supplier.js +++ b/src/models/supplier.js @@ -131,12 +131,24 @@ const supplierSchema = new mongoose.Schema( fcmId: { type: String, default: null }, }); + const profilePictureSupplierSchema = new Schema({ + supplierId: { + type: String,unique: true, + required: true + }, + picture: { + type: String, + required: true + } + }); + const Supplier = mongoose.model("Supplier", supplierSchema); //const DeliveryAgent = mongoose.model("DeliveryAgent", deliveryAgent); const FriendRequest = mongoose.model('FriendRequest', friendRequestSchema); const DeliveryBoy = mongoose.model('DeliveryBoy', deliveryBoySchema); +const profilePictureSupplier = mongoose.model('ProfilePictureSupplier', profilePictureSupplierSchema); -module.exports = { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} +module.exports = { Supplier, generateSupplierId, FriendRequest,DeliveryBoy, profilePictureSupplier} diff --git a/src/models/tankers.js b/src/models/tankers.js index e78af467..297c6cb4 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -16,8 +16,8 @@ const tankersSchema = new mongoose.Schema({ tankerName: { type: String, default: null }, phoneNumber: { type: String, default: null }, alternative_phoneNumber: { type: String, default: null }, - typeofwater: [{ typeofwater: String}], - price:[{ price: String}], + typeofwater: { type: String, default: null }, + price:{ type: String, default: null }, capacity: { type: String}, supplier_address: { type: String, default: null }, supplier_name : { type: String, default: null }, diff --git a/src/routes/supplierRoute.js b/src/routes/supplierRoute.js index 6fea8da0..0059e087 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -539,6 +539,42 @@ module.exports = function (fastify, opts, next) { handler: supplierController.editCuurentSupplierInfo, }); + + fastify.route({ + method: "POST", + url: "/api/supplier/profile-picture/:supplierId", + schema: { + tags: ["Supplier"], + description: "This is for uploading profile picture supplier.", + summary: "This is for uploading profile picture supplier.", + params: { + type: "object", + properties: { + supplierId: { + type: "string", + description: "supplierId", + }, + }, + }, + body: { + type: "object", + required: ["picture"], + properties: { + picture: { + type: 'string' + } + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + handler: validationHandler.uploadProfilePicture, + }); + + next(); } diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index fba890dc..43b0552d 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -454,15 +454,35 @@ module.exports = function (fastify, opts, next) { }, }, }, + // body: { + // type: "object", + // required: ["picture"], + // properties: { + // picture: { + // type: 'string' + // } + // }, + // }, body: { type: "object", required: ["picture"], properties: { picture: { - type: 'string' + type: "object", + properties: { + type: { + type: "string", + enum: ['jpeg', 'png', 'gif'] + }, + data: { + type: "string", + format: "binary" + } + } } }, }, + security: [ { basicAuth: [],