From 259a3640dd26a23c7b21544d42d04325445274e4 Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Thu, 4 May 2023 11:27:30 +0530 Subject: [PATCH 1/5] changes --- src/models/tankers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 }, From 2eb264433e0f2a695a0cb88a2fd4677bbf2b3686 Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Thu, 4 May 2023 15:10:16 +0530 Subject: [PATCH 2/5] supplier profilePicture --- src/handlers/supplierHandler.js | 30 +++++++++++++++++++++++++-- src/models/supplier.js | 14 ++++++++++++- src/routes/supplierRoute.js | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/handlers/supplierHandler.js b/src/handlers/supplierHandler.js index 2d88e7ce..229dbb03 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/supplier.js b/src/models/supplier.js index 13e3d143..9e9d2197 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/routes/supplierRoute.js b/src/routes/supplierRoute.js index 6fea8da0..416bd1c6 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(); } From 0a9d15ccc1ea3f052e18d5a4f22f119adc6142d8 Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Thu, 4 May 2023 15:22:33 +0530 Subject: [PATCH 3/5] changes --- src/controllers/tankersController.js | 8 ++++---- src/handlers/supplierHandler.js | 2 +- src/models/supplier.js | 2 +- src/routes/supplierRoute.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) 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 229dbb03..b8824f61 100644 --- a/src/handlers/supplierHandler.js +++ b/src/handlers/supplierHandler.js @@ -1193,7 +1193,7 @@ exports.getconnectedCustomers = async (req, reply) => { exports.uploadProfilePicture = async (req, reply) => { try { - const supplierId = req.params.supplierId; + const supplierId = req.params.supplierId; const picture = req.body.picture; let profilePicture = await profilePictureSupplier.findOne({ supplierId }); diff --git a/src/models/supplier.js b/src/models/supplier.js index 9e9d2197..9d246f60 100644 --- a/src/models/supplier.js +++ b/src/models/supplier.js @@ -132,7 +132,7 @@ const supplierSchema = new mongoose.Schema( }); const profilePictureSupplierSchema = new Schema({ - supplierId: { + supplierId: { type: String,unique: true, required: true }, diff --git a/src/routes/supplierRoute.js b/src/routes/supplierRoute.js index 416bd1c6..0059e087 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -571,7 +571,7 @@ module.exports = function (fastify, opts, next) { }, ], }, - handler: validationHandler.uploadProfilePicture, + handler: validationHandler.uploadProfilePicture, }); From 2284eacec1104938fce1f273e6103f0190b03cea Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Thu, 4 May 2023 16:07:35 +0530 Subject: [PATCH 4/5] changes --- src/controllers/supplierOrderController.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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}); From f890d25cf981ada650d1552cf9bc65d14e11bbc0 Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Thu, 4 May 2023 16:25:26 +0530 Subject: [PATCH 5/5] profilepicture file format --- src/models/User.js | 25 ++++++++++++++++++++++--- src/routes/usersRoute.js | 22 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) 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/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: [],