From a1a8410c2ae65e8a850442e89e5454644e6f17ae Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 24 Jul 2024 04:38:30 -0400 Subject: [PATCH] creating records of sensors coming in bulk --- src/controllers/storeController.js | 30 ++++++++++++++++++++++- src/models/store.js | 35 +++++++++++++++++++++++---- src/routes/storeRoute.js | 38 +++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 5c898dbe..4ebfd302 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -10,7 +10,7 @@ const fastify = require("fastify")({ return uuidv4(); }, }); -const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor,MotorSwitchSensor} = require("../models/store"); +const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors} = require("../models/store"); const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User') @@ -971,3 +971,31 @@ exports.getpumpswitchqc = async (req, reply) => { throw boom.boomify(err); } }; + + +exports.createSensor = async (req, reply) => { + try { + const storeId = req.params.storeId; + const { indate, batchno, hardwareId_company, quantity } = req.body; + + const date = moment().format('MM-DD'); + let entries = []; + + for (let i = 0; i < quantity; i++) { + const newSensor = { + storeId, + batchno, + type, + indate, + hardwareId_company + }; + + entries.push(newSensor); + } + + const savedSensors = await Insensors.insertMany(entries); + reply.code(200).send(savedSensors); + } catch (err) { + reply.code(500).send(err); + } +}; diff --git a/src/models/store.js b/src/models/store.js index d6135c1c..0fc9bb22 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -110,7 +110,7 @@ const installationschema = new mongoose.Schema({ phoneVerificationCode: { type: Number, default: 11111 }, passwordResetCode: { type: Number, default: 11111 }, oneTimePasswordSetFlag: { type: Boolean, default: false }, - emails: { type: String, unique: true }, + emails: {type: String}, services: { password: { bcrypt: { type: String, required: true } @@ -218,7 +218,6 @@ const motorSwitchSensorInSchema = new mongoose.Schema({ masterId: { type: String, default: null }, type: { type: String }, indate: { type: String }, - qccheck: { type: String, default: null }, qccheckdate: { type: String, default: null }, qcby: { type: String, default: null }, @@ -234,7 +233,35 @@ const motorSwitchSensorInSchema = new mongoose.Schema({ - +const insensorsSchema = new mongoose.Schema({ + storeId: { type: String }, + hardwareId: { type: String }, + masterId: { type: String, default: null }, + type: { type: String }, + indate: { type: String }, + hardwareId_company: { type: String }, + qccheck: { type: String, default: null }, + qccheckdate: { type: String, default: null }, + qcby: { type: String, default: null }, + comment: { type: String, default: "0" }, + outforrepairdate: { type: String, default: "0" }, + sendto: { type: String, default: null }, + repairfeedback: { type: String, default: "0" }, + dateofinstallation: { type: String, default: null }, + installedby: { type: String, default: "0" }, + customerId: { type: String, default: "0" }, + comments: { type: String, default: "0" }, + quantity: { type: Number, default: 0 }, + batchno: { type: String, default: null }, + sensor_type: { type: String, enum: ['slaves', 'motorswitch', 'master'] }, // adding sensor_type field + +}); + + + + + + const Insensors = mongoose.model('Insensors', insensorsSchema); const Store = mongoose.model("Store", storeSchema); const WaterLeverSensor = mongoose.model('WaterLeverSensor', waterLeverSensorInSchema); const ProfilePictureStore = mongoose.model('ProfilePictureStore', profilePictureStoreSchema); @@ -243,4 +270,4 @@ const motorSwitchSensorInSchema = new mongoose.Schema({ const Install = mongoose.model("Install", installationschema); - module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor}; + module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors}; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index c5552988..4e9d7308 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -98,7 +98,7 @@ fastify.post('/api/stores', { summary: "This is for Create New Store.", body: { type: "object", - required: ["storename", "phone", "emails", "password"], + required: ["storename", "phone", "password"], properties: { storename: { type: "string" }, phone: { type: "string" }, @@ -689,5 +689,41 @@ fastify.post("/api/installmotorswitch/:storeId", { }, handler: storeController.installmotorswitch, }) + +fastify.post("/api/createwaterlevelSensorintime/:storeId", { + schema: { + description: "This is for creating Sensors at in time", + tags: ["Store-Data"], + summary: "This is for creating Sensors at in time", + params: { + required: ["storeId"], + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + }, + }, + + body: { + type: "object", + + properties: { + batchno: { type: "string" }, + quantity: { type: "string" }, + indate: { type: "string" }, + hardwareId_company: { type: "string" } + }, + }, + }, + handler: storeController.createSensor, +}) + + + + + + next(); };