From 98f4e8c7528c078dcaf0a97962675e8529a469a0 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 10 Feb 2023 05:14:24 -0500 Subject: [PATCH] MADE CHANGES IN TANKERS --- src/controllers/tankersController.js | 7 +++--- src/models/tankers.js | 4 +-- src/routes/tankersRoute.js | 37 ++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 1f00f7e3..148a48df 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -24,7 +24,6 @@ console.log(req.params); // const updateData = req.body; - // console.log("This is the reply in the handler after the validations", reply); tankersData = { customerId:customerId, @@ -33,7 +32,7 @@ console.log(req.params); typeofwater: req.body.typeofwater, capacity: req.body.capacity, }; - + console.log(req.body.typeofwater,req.body.capacity) var tanker_Name = req.body.tankerName var i_tank = await Tanker.findOne({ tankerName: tanker_Name,customerId:customerId}) @@ -55,9 +54,9 @@ console.log(req.params); tankers.customerId = usertobeInserted.customerId; } } - const insertedTank = await tankers.save(); + const insertedTanker = await tankers.save(); - return insertedTank; + return insertedTanker; } catch (err) { diff --git a/src/models/tankers.js b/src/models/tankers.js index fe748815..12e41449 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -14,8 +14,8 @@ 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 }], - capacity: [{ type: String, default: null }], + typeofwater: [{ typeofwater: String}], + capacity: [{ capacity: String}], }); diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index 57aee207..3a2a406c 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -29,15 +29,16 @@ module.exports = function (fastify, opts, next) { tankerName: { type: "string" }, phoneNumber: { type: "string"}, typeofwater: { - type: "array", + type: "array", maxItems: 2500, items: { type: "object", properties: { - typeofwater: { type: "string", default: null }, + typeofwater: { type: "string", default: null }, }, - }, + }, }, + capacity: { type: "array", maxItems: 2500, @@ -45,9 +46,11 @@ module.exports = function (fastify, opts, next) { type: "object", properties: { capacity: { type: "string", default: null }, - }, + }, }, }, + + }, }, @@ -58,7 +61,7 @@ module.exports = function (fastify, opts, next) { ], }, - preHandler: fastify.auth([fastify.authenticate]), + preHandler: fastify.auth([fastify.authenticate]), handler: tankersController.addTankers, // onResponse: (request, reply) => { // validationHandler.sendPhoneVerificationCode(request, reply); @@ -93,8 +96,28 @@ module.exports = function (fastify, opts, next) { properties: { tankerName: { type: "string", default: null }, phoneNumber: { type: "string", default: null }, - capacity: { type: "number" }, - typeofwater: { type: "string", default: null }, + typeofwater: { + type: "array", + maxItems: 2500, + items: { + type: "object", + properties: { + typeofwater: { type: "string", default: null }, + }, + }, + }, + + capacity: { + type: "array", + maxItems: 2500, + items: { + type: "object", + properties: { + capacity: { type: "string", default: null }, + }, + }, + }, + }, }, security: [