varun 2 years ago
commit 879c4d23d6

@ -20,8 +20,28 @@ exports.createConnections = async (req, body) => {
const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname }) const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname })
const usertobeInserted = req.body; const usertobeInserted = req.body;
tankInfo.connections.source = tankInfo.tankName; tankInfo.connections.source = tankInfo.tankName;
if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections; if (usertobeInserted.inputConnections) {
if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections; // 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 // 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 // default to false if not specified
};
});
}
const connection_data = req.body.outputConnections const connection_data = req.body.outputConnections
for (const data of connection_data){ for (const data of connection_data){
@ -78,8 +98,31 @@ exports.updateconnectionInfo = async (req, reply) => {
const updateData = req.body; const updateData = req.body;
tankInfo.connections.source = tankInfo.tankName; tankInfo.connections.source = tankInfo.tankName;
if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections; // if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections;
if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections; // if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections;
// Update the tank's input connections if provided
if (updateData.inputConnections) {
tankInfo.connections.inputConnections = updateData.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
};
});
}
// Update the tank's output connections if provided
if (updateData.outputConnections) {
tankInfo.connections.outputConnections = updateData.outputConnections.map(connection => {
return {
outputConnections: connection.outputConnections,
output_type: connection.output_type,
outputismotor: connection.outputismotor || false // default to false if not specified
};
});
}
const tank_connections = await tankInfo.save(); const tank_connections = await tankInfo.save();
return tank_connections; return tank_connections;
} catch (err) { } catch (err) {

@ -358,8 +358,6 @@ fastify.register(require("./routes/forTestingRoute"));
const start = async () => { const start = async () => {
try { try {
await fastify.listen(3000, "0.0.0.0"); await fastify.listen(3000, "0.0.0.0");
fastify.log.info(`listening on ${fastify.server.address().port}`); fastify.log.info(`listening on ${fastify.server.address().port}`);
fastify.log.info(`server listening on ${fastify.config}`); fastify.log.info(`server listening on ${fastify.config}`);

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

@ -3,6 +3,97 @@ const createConnectionController = require("../controllers/createConnectionContr
module.exports = function (fastify, opts, next) { 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({ fastify.route({
method: "POST", method: "POST",
url: "/api/createConnections/:customerId", url: "/api/createConnections/:customerId",
@ -32,6 +123,7 @@ module.exports = function (fastify, opts, next) {
properties: { properties: {
inputConnections: { type: "string", default: null }, inputConnections: { type: "string", default: null },
input_type: { type: "string", default: null }, input_type: { type: "string", default: null },
inputismotor: { type: "boolean", default: false },
}, },
}, },
}, },
@ -43,6 +135,7 @@ module.exports = function (fastify, opts, next) {
properties: { properties: {
outputConnections: { type: "string", default: null }, outputConnections: { type: "string", default: null },
output_type: { type: "string", default: null }, output_type: { type: "string", default: null },
outputismotor: { type: "boolean", default: false },
}, },
}, },
}, },
@ -53,18 +146,12 @@ module.exports = function (fastify, opts, next) {
basicAuth: [], basicAuth: [],
}, },
], ],
}, },
preHandler: fastify.auth([fastify.authenticate]), preHandler: fastify.auth([fastify.authenticate]),
handler: createConnectionController.createConnections, handler: createConnectionController.createConnections,
// onResponse: (request, reply) => {
// validationHandler.sendPhoneVerificationCode(request, reply);
// },
//onResponse: validationHandler.sendPhoneVerificationCode,
}); });
fastify.route({ fastify.route({
method: "PUT", method: "PUT",
url: "/api/updateConnections/:customerId", url: "/api/updateConnections/:customerId",
@ -95,6 +182,7 @@ module.exports = function (fastify, opts, next) {
properties: { properties: {
inputConnections: { type: "string", default: null }, inputConnections: { type: "string", default: null },
type: { type: "string", default: null }, type: { type: "string", default: null },
inputismotor: { type: "boolean"},
}, },
}, },
}, },
@ -106,6 +194,7 @@ module.exports = function (fastify, opts, next) {
properties: { properties: {
outputConnections: { type: "string", default: null }, outputConnections: { type: "string", default: null },
type: { type: "string", default: null }, type: { type: "string", default: null },
outputismotor: { type: "boolean" },
}, },
}, },
}, },

Loading…
Cancel
Save