inputismotor and outputismotor feilds are added

master
bhaskar 2 years ago
parent d30bdaec58
commit aaa5e2c370

@ -20,8 +20,28 @@ exports.createConnections = async (req, body) => {
const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname })
const usertobeInserted = req.body;
tankInfo.connections.source = tankInfo.tankName;
if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections;
if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections;
if (usertobeInserted.inputConnections) {
// update inputismotor field for each input connection
tankInfo.connections.inputConnections = usertobeInserted.inputConnections.map(connection => {
return {
inputConnections: connection.inputConnections,
input_type: connection.input_type,
motor_status: connection.motor_status || "0",
inputismotor: connection.inputismotor || false // default to false if not specified
};
});
}
if (usertobeInserted.outputConnections) {
// update outputismotor field for each output connection
tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
return {
outputConnections: connection.outputConnections,
output_type: connection.output_type,
outputismotor: connection.outputismotor || false // default to false if not specified
};
});
}
const connection_data = req.body.outputConnections
for (const data of connection_data){

@ -9,6 +9,27 @@ const ObjectId = Schema.Types.ObjectId;
// Store a random password reset code
const code = Math.floor(100000 + Math.random() * 900000);
const RoleSchema = new Schema({ name: String });
// const tanksSchema = new mongoose.Schema({
// hardwareId: { type: String },
// hardwareId_type: { type: String },
// hardwareId_company: { type: String },
// customerId: { type: String, default: null },
// tankName: { type: String, default: null },
// blockName: { type: String, default: null },
// capacity: { type: String, default: "0" },
// typeOfWater: { type: String, default: null },
// waterlevel: { type: String, default: "0" },
// tankLocation: { type: String, default: null },
// motor_status: { type: String, default: 0 },
// connections: {
// source: { type: String},
// inputConnections: [{ inputConnections: String,input_type:String,motor_status: { type: String, default: "0" } }],
// outputConnections: [{ outputConnections: String,output_type:String }]
// }
// });
const tanksSchema = new mongoose.Schema({
hardwareId: { type: String },
hardwareId_type: { type: String },
@ -20,16 +41,29 @@ const tanksSchema = new mongoose.Schema({
typeOfWater: { type: String, default: null },
waterlevel: { type: String, default: "0" },
tankLocation: { type: String, default: null },
motor_status: { type: String, default: 0 },
motor_status: { type: String, default: "0" },
connections: {
source: { type: String},
inputConnections: [{ inputConnections: String,input_type:String,motor_status: { type: String, default: "0" } }],
outputConnections: [{ outputConnections: String,output_type:String }]
source: { type: String },
inputConnections: [
{
inputConnections: { type: String },
input_type: { type: String },
inputismotor: { type: Boolean, default: false },
motor_status: { type: String, default: "0" }
}
],
outputConnections: [
{
outputConnections: { type: String },
output_type: { type: String },
outputismotor: { type: Boolean, default: false },
motor_status: { type: String, default: "0" }
}
]
}
});
});
const motordataSchema = new mongoose.Schema({
customerId: { type: String, default: null },

@ -3,6 +3,97 @@ const createConnectionController = require("../controllers/createConnectionContr
module.exports = function (fastify, opts, next) {
// fastify.route({
// method: "POST",
// url: "/api/createConnections/:customerId",
// schema: {
// tags: ["Connections"],
// description: "This is for cretae New Connection",
// summary: "This is for cretae New Connection.",
// params: {
// required: ["customerId"],
// type: "object",
// properties: {
// customerId: {
// type: "string",
// description: "customerId",
// },
// },
// },
// // body: {
// // type: "object",
// // properties: {
// // tankname: { type: "string" },
// // inputConnections: {
// // type: "array",
// // maxItems: 2500,
// // items: {
// // type: "object",
// // properties: {
// // inputConnections: { type: "string", default: null },
// // input_type: { type: "string", default: null },
// // },
// // },
// // },
// // outputConnections: {
// // type: "array",
// // maxItems: 2500,
// // items: {
// // type: "object",
// // properties: {
// // outputConnections: { type: "string", default: null },
// // output_type: { type: "string", default: null },
// // },
// // },
// // },
// // },
// // },
// body: {
// type: "object",
// properties: {
// tankname: { type: "string" },
// inputConnections: {
// type: "array",
// maxItems: 2500,
// items: {
// type: "object",
// properties: {
// inputConnections: { type: "string", default: null },
// input_type: { type: "string", default: null },
// inputismotor: { type: "boolean", default: true }
// },
// },
// },
// outputConnections: {
// type: "array",
// maxItems: 2500,
// items: {
// type: "object",
// properties: {
// outputConnections: { type: "string", default: null },
// output_type: { type: "string", default: null },
// outputismotor: { type: "boolean", default: true }
// },
// },
// },
// },
// },
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// preHandler: fastify.auth([fastify.authenticate]),
// handler: createConnectionController.createConnections,
// // onResponse: (request, reply) => {
// // validationHandler.sendPhoneVerificationCode(request, reply);
// // },
// //onResponse: validationHandler.sendPhoneVerificationCode,
// });
fastify.route({
method: "POST",
url: "/api/createConnections/:customerId",
@ -32,6 +123,7 @@ module.exports = function (fastify, opts, next) {
properties: {
inputConnections: { type: "string", default: null },
input_type: { type: "string", default: null },
inputismotor: { type: "boolean", default: true },
},
},
},
@ -43,6 +135,7 @@ module.exports = function (fastify, opts, next) {
properties: {
outputConnections: { type: "string", default: null },
output_type: { type: "string", default: null },
outputismotor: { type: "boolean", default: true },
},
},
},
@ -53,18 +146,12 @@ module.exports = function (fastify, opts, next) {
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: createConnectionController.createConnections,
// onResponse: (request, reply) => {
// validationHandler.sendPhoneVerificationCode(request, reply);
// },
//onResponse: validationHandler.sendPhoneVerificationCode,
});
fastify.route({
method: "PUT",
url: "/api/updateConnections/:customerId",

Loading…
Cancel
Save