From ba7006a2b33bad285ee8d37400a5a15ee506e7de Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Tue, 25 Apr 2023 11:22:47 +0530 Subject: [PATCH 1/2] fcmId added --- src/controllers/supplierController.js | 7 +++++-- src/controllers/supplierOrderController.js | 3 ++- src/controllers/userController.js | 4 +++- src/index.js | 1 + src/models/User.js | 1 + src/models/supplier.js | 2 ++ src/routes/supplierOrdersRoutes.js | 4 +++- src/routes/supplierRoute.js | 3 ++- src/routes/usersRoute.js | 3 ++- 9 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/controllers/supplierController.js b/src/controllers/supplierController.js index e9eba7be..0e82023f 100644 --- a/src/controllers/supplierController.js +++ b/src/controllers/supplierController.js @@ -104,7 +104,8 @@ exports.loginDeliveryBoy = async (req) => { zip: req.body.zip, }, latitude: req.body.latitude, - longitude: req.body.longitude + longitude: req.body.longitude, + fcmId : req.body.fcmId }; var supplier = new Supplier(s_data); @@ -129,6 +130,7 @@ exports.loginDeliveryBoy = async (req) => { supplier.alternativeContactNumber = suppliertobeInserted.alternativeContactNumber; supplier.latitude = suppliertobeInserted.latitude; supplier.longitude = suppliertobeInserted.longitude; + supplier.fcmId = suppliertobeInserted.fcmId } @@ -165,7 +167,8 @@ exports.loginDeliveryBoy = async (req) => { ], profile: insertedSupplier.profile, latitude: insertedSupplier.latitude, - longitude: insertedSupplier.longitude + longitude: insertedSupplier.longitude, + fcmId : insertedSupplier.fcmId }, status_code: 200, }; diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index 4312f68b..e7d77c18 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -75,7 +75,7 @@ exports.orderNow = async (req, reply) => { status:req.body.status, longitude: req.body.longitude, latitude:req.body.latitude, - + fcmId: req.body.fcmId }; var agent_mobile = req.body.phone @@ -104,6 +104,7 @@ exports.orderNow = async (req, reply) => { agent.status = usertobeInserted.status agent.longitude = usertobeInserted.longitude agent.latitude = usertobeInserted.latitude + agent.fcmId = usertobeInserted.fcmId } } diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 9216f40f..aa772fb8 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -193,6 +193,7 @@ exports.addUser = async (req, reply) => { }, longitude: req.body.longitude, latitude:req.body.latitude, + fcmId: req.body.fcmId }; @@ -218,7 +219,7 @@ exports.addUser = async (req, reply) => { user.customerId = usertobeInserted.customer_id; user.latitude = usertobeInserted.latitude; user.longitude = usertobeInserted.longitude - + user.fcmId = usertobeInserted.fcmId } console.log("---------checkurl ecnoded string-----------------------"); @@ -258,6 +259,7 @@ exports.addUser = async (req, reply) => { profile: insertedUser.profile, longitude: insertedUser.longitude, latitude:insertedUser.latitude, + fcmId: insertedUser.fcmId }, status_code: 200, }; diff --git a/src/index.js b/src/index.js index 0af4d460..af05969f 100644 --- a/src/index.js +++ b/src/index.js @@ -225,6 +225,7 @@ fastify.post("/api/login", { latitude: loginObject.user.latitude, longitude: loginObject.user.longitude, type: loginObject.user.profile.role, + fcmId: loginObject.user.fcmId, typeasobj: stringToJsonObject, }, }); diff --git a/src/models/User.js b/src/models/User.js index 8373d39a..338a7a17 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -95,6 +95,7 @@ const userSchema = new mongoose.Schema( latitude: {type: Number}, isActive: Boolean, tenantId: ObjectId, + fcmId: { type: String, default: null }, createdAt: { type: Date, default: function () { diff --git a/src/models/supplier.js b/src/models/supplier.js index f0210cf4..a5099f0b 100644 --- a/src/models/supplier.js +++ b/src/models/supplier.js @@ -67,6 +67,7 @@ const supplierSchema = new mongoose.Schema( latitude: {type: Number}, isActive: Boolean, tenantId: ObjectId, + fcmId: { type: String, default: null }, createdAt: { type: Date, default: function () { @@ -127,6 +128,7 @@ const supplierSchema = new mongoose.Schema( status: { type: String, default: "Inactive" }, longitude: { type : Number}, latitude: {type: Number}, + fcmId: { type: String, default: null }, }); diff --git a/src/routes/supplierOrdersRoutes.js b/src/routes/supplierOrdersRoutes.js index d6fe961c..029906a8 100644 --- a/src/routes/supplierOrdersRoutes.js +++ b/src/routes/supplierOrdersRoutes.js @@ -87,7 +87,9 @@ module.exports = function (fastify, opts, next) { zip: { type: "string", default: null }, status: { type: "string" }, latitude: { type: 'number' }, - longitude: { type: 'number'} + longitude: { type: 'number'}, + fcmId: { type: "string", default: null }, + }, }, diff --git a/src/routes/supplierRoute.js b/src/routes/supplierRoute.js index ce466b71..9e19caf4 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -279,7 +279,8 @@ module.exports = function (fastify, opts, next) { zip: { type: "string", default: null }, country: { type: "string", default: null }, latitude: { type: 'number' }, - longitude: { type: 'number'} + longitude: { type: 'number'}, + fcmId: { type: "string", default: null }, }, }, security: [ diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 47f15688..b5a33830 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -156,7 +156,8 @@ module.exports = function (fastify, opts, next) { country: { type: "string", default: null }, notes: { type: "string", default: null }, latitude: { type: 'number' }, - longitude: { type: 'number'} + longitude: { type: 'number'}, + fcmId: { type: "string", default: null }, }, }, security: [ From 79622d4f22b02381535924b2480fade02dabd7c0 Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Wed, 26 Apr 2023 15:29:10 +0530 Subject: [PATCH 2/2] order - delivered,cancel,pending apis --- src/controllers/supplierOrderController.js | 134 +++++++++++ src/routes/supplierOrdersRoutes.js | 247 +++++++++++++++++++++ 2 files changed, 381 insertions(+) diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index e7d77c18..e848a2d2 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -392,6 +392,49 @@ exports.userAccounts = async (req, reply) => { +exports.userAccountsofparticularSupplier = async (req, reply) => { + try { + + const booking = await Tankerbooking.find({customerId: req.params.customerId,supplierId: req.body.supplierId,}) + console.log(booking,) + + let acceptedCount = 0; + let pendingRejectedCount = 0; + let deliveredCount = 0; + let deliveredTotalPrice = 0; + let deliveredTotalAmountPaid = 0; + let deliveredTotalAmountDue = 0; + + for (let i = 0; i < booking.length; i++) { + let order = booking[i]; + if (order.orderStatus === "accepted") { + acceptedCount++; + } else if (order.orderStatus === "pending" || order.orderStatus === "rejected") { + pendingRejectedCount++; + } else if (order.orderStatus === "delivered") { + deliveredCount++; + deliveredTotalPrice += parseInt(order.price.replace(/,/g, ''), 10) + deliveredTotalAmountPaid += parseInt(order.amount_paid.replace(/,/g, ''), 10) + deliveredTotalAmountDue += parseInt(order.amount_due.replace(/,/g, ''), 10) + } + } + + console.log("Accepted orders count:", acceptedCount); + console.log("Pending or rejected orders count:", pendingRejectedCount); + console.log("Delivered orders count:", deliveredCount); + console.log("Delivered orders total price:", deliveredTotalPrice); + console.log("Delivered orders total amount paid:", deliveredTotalAmountPaid); + console.log("Delivered orders total amount due:", deliveredTotalAmountDue); + + + reply.send({ status_code: 200, count: booking.length, data: booking,acceptedCount:acceptedCount,pendingRejectedCount:pendingRejectedCount,deliveredCount:deliveredCount,deliveredTotalPrice:deliveredTotalPrice,deliveredTotalAmountPaid:deliveredTotalAmountPaid,deliveredTotalAmountDue:deliveredTotalAmountDue }); + } catch (err) { + throw boom.boomify(err); + } +}; + + + exports.supplierAccounts = async (req, reply) => { @@ -478,3 +521,94 @@ exports.tankerAccounts = async (req, reply) => { } }; + +exports.getAllOrderaccepted = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["accepted"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + +exports.getAllOrderdelivered = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["delivered"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + + +exports.getAllOrderreject = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["rejected"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + +exports.getAllOrderpending = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["pending"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + +exports.getBillingInfo = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const bookingId = req.params.bookingId; + try { + await Tankerbooking.findOne({ bookingid: bookingId}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; \ No newline at end of file diff --git a/src/routes/supplierOrdersRoutes.js b/src/routes/supplierOrdersRoutes.js index 029906a8..76e59002 100644 --- a/src/routes/supplierOrdersRoutes.js +++ b/src/routes/supplierOrdersRoutes.js @@ -326,6 +326,42 @@ module.exports = function (fastify, opts, next) { + + // fastify.get("/api/userAccountsofparticularSupplier/:customerId", { + // schema: { + // tags: ["Supplier-Order"], + // description: "This is for Get accounts of user for particular supplier", + // summary: "This is for to Get accounts of user for particular supplier", + // params: { + // required: ["customerId"], + // type: "object", + // properties: { + // customerId: { + // type: "string", + // description: "customerId", + // }, + // }, + // }, + // body: { + // type: "object", + // properties: { + + // supplierId:{type:"string"} + // }, + // }, + // security: [ + // { + // basicAuth: [], + // }, + // ], + // }, + // preHandler: fastify.auth([fastify.authenticate]), + // handler: supplierOrderController.userAccountsofparticularSupplier, + // }); + + + + fastify.get("/api/supplierAccounts/:supplierId", { schema: { tags: ["Supplier"], @@ -393,6 +429,217 @@ module.exports = function (fastify, opts, next) { }); + fastify.route({ + method: "GET", + url: "/api/accepted/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order pending for delivery", + summary: "This is for Get All order pending for delivery", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderaccepted, + + }); + fastify.route({ + method: "GET", + url: "/api/rejected/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order cancelled", + summary: "This is for Get All order cancelled", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderreject, + + }); + + fastify.route({ + method: "GET", + url: "/api/delivered/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order Delivered", + summary: "This is for Get All order Delivered", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderdelivered, + + }); + fastify.route({ + method: "GET", + url: "/api/pendingconformation/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order Pending for confirmation", + summary: "This is for Get All order pending for confirmation", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderpending, + + }); + + // fastify.route({ + // method: "GET", + // url: "/api/billing/:bookingId", + // schema: { + // tags: ["Supplier-Order"], + // description:"This is for Get Billing Information", + // summary: "This is for Get Billing Information", + // params: { + // required: ["bookingId"], + // type: "object", + // properties: { + // bookingId: { + // type: "string", + // description: "bookingId", + // }, + // }, + // }, + + // security: [ + // { + // basicAuth: [], + // }, + // ], + + // }, + // handler:supplierOrderController.getBillingInfo, + + // }); + + fastify.route({ + method: "GET", + url: "/api/billinginfo/:bookingId", + schema: { + tags: ["Supplier-Order"], + description:"This is for giving booking data billing information", + summary: "This is for giving booking data billing information", + params: { + required: ["bookingId"], + type: "object", + properties: { + bookingId: { + type: "string", + description: "bookingId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler:supplierOrderController.getBillingInfo, + // onResponse: (request, reply) => { + // validationHandler.sendPhoneVerificationCode(request, reply); + // }, + //onResponse: validationHandler.sendPhoneVerificationCode, + }); + + fastify.route({ + method: "GET", + url: "/api/userAccountsofparticularSupplier/:customerId", + schema: { + tags: ["Supplier-Order"], + description: "This is for Get accounts of user for particular supplier", + summary: "This is for to Get accounts of user for particular supplier", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + body: { + type: "object", + //required: ["customerId"], + properties: { + supplierId : { type : "string"} + }, + }, + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.userAccountsofparticularSupplier, + + }); + next(); }