creating records of sensors coming in bulk

master
varun 1 year ago
parent 77ca1f1357
commit a1a8410c2a

@ -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);
}
};

@ -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};

@ -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();
};

Loading…
Cancel
Save