From 51a67ef69b757134e8bbeb3062bce0411be816fb Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 8 Feb 2023 00:37:38 -0500 Subject: [PATCH] linked customer id with bores --- src/controllers/tankersController.js | 8 ++++---- src/controllers/tanksController.js | 2 +- src/controllers/userController.js | 1 - src/models/User.js | 1 + src/models/tankers.js | 7 ++++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index fd43c617..9f56d5af 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -125,7 +125,6 @@ exports.tankerBooking = async (req, reply) => { address: req.body.address, dateOfOrder: req.body.dateOfOrder, - }; var tankersBookingData = new Tankerbooking(bookingsData); @@ -175,9 +174,9 @@ exports.addBores = async (req, reply) => { try { //const username = req.params.username; - + var customerId = req.params.customerId; //console.log(req.params); - const username = loginObject.user.username; + //const username = loginObject.user.username; //console.log(loginObject.user.username) // const userInfo = await User.findOne({ username: username.toString() }); // const updateData = req.body; @@ -193,7 +192,7 @@ exports.addBores = async (req, reply) => { var bore_Name = req.body.boreName - var i_bore = await Bore.findOne({ boreName: bore_Name}) + var i_bore = await Bore.findOne({ boreName: bore_Name,customerId:customerId}) if(i_bore){ throw new Error('Bore already exists'); } @@ -205,6 +204,7 @@ exports.addBores = async (req, reply) => { if (checkFormEncoding.isUserFormUrlEncoded) { usertobeInserted = checkFormEncoding.bores; console.log("thsi true url string"); + tank.customerId = usertobeInserted.customerId bores.boreName = usertobeInserted.boreName; bores.typeofwater = usertobeInserted.typeofwater; bores.description = usertobeInserted.description; diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 20ba0ea2..aca0d437 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -111,6 +111,6 @@ exports.getTank = async (req, reply) => { reply.send({ error: err }); }); } catch (err) { - throw boom.boomify + throw boom.boomify(err); } }; \ No newline at end of file diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 5516b291..96863c9f 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -240,7 +240,6 @@ exports.addUser = async (req, reply) => { inchargeName: insertedUser.inchargeName, buildingName: insertedUser.buildingName, - emails: [ { email: insertedUser.emails[0].email, diff --git a/src/models/User.js b/src/models/User.js index 86f179ca..c962df5e 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -45,6 +45,7 @@ const userSchema = new mongoose.Schema( oneTimePasswordSetFlag: { type: Boolean, default: false }, emails: [{ email: String, verified: { type: Boolean, default: false } }], services: { password: { bcrypt: String } }, + profile: { role: [{ type: String, default: "user" }], firstName: { type: String, default: null }, diff --git a/src/models/tankers.js b/src/models/tankers.js index c8d76a18..2cca5ae0 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -11,7 +11,7 @@ const RoleSchema = new Schema({ name: String }); const tankersSchema = new mongoose.Schema({ - + customerId: { type: String, default: null }, tankerName: { type: String, default: null }, phoneNumber: { type: String, default: null }, typeofwater: [{ type: String, default: null }], @@ -20,7 +20,7 @@ const tankersSchema = new mongoose.Schema({ }); const tankersbookingSchema = new mongoose.Schema({ - + customerId: { type: String, default: null }, bookingid: { type: String, default: null,unique: true }, dateOfOrder: { type: String, default: null }, typeofwater: { type: String, default: null }, @@ -37,7 +37,7 @@ const tankersbookingSchema = new mongoose.Schema({ }); const boreSchema = new mongoose.Schema({ - + customerId: { type: String, default: null }, boreName: { type: String, default: null }, typeofwater: { type: String, default: null }, description: { type: String, default: null }, @@ -45,6 +45,7 @@ const boreSchema = new mongoose.Schema({ }); + const Tanker = mongoose.model("Tanker", tankersSchema); const Tankerbooking = mongoose.model("Tankerbooking", tankersbookingSchema); const Bore = mongoose.model("Bore", boreSchema);