diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index b12e13be..89cf11c0 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -10,7 +10,9 @@ const fastify = require("fastify")({ return uuidv4(); }, }); -const { Install, ProfilePictureInstall, generateinstallationId,Store} = require("../models/store"); +const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor} = require("../models/store"); +const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User') + @@ -403,99 +405,35 @@ exports.installSignUp = async (request, reply) => { } }; - - - + const generatewaterlevelsensorId = async () => { + const result = await Counter.findOneAndUpdate( + { _id: 'waterlevelsensor_id' }, + { $inc: { seq: 1 } }, + { upsert: true, new: true } + ); + return result.seq; + }; - // exports.loginStore = async (request, reply) => { - // try { - // let store = await Store.findOne({ phone: request.body.phone }); - // if (!store) { - // return reply.code(400).send({ - // simplydata: { - // error: true, - // code: 400, - // message: "Invalid Phone or Password", - // }, - // }); - // } - - // const isMatch = await bcrypt.compare(request.body.password, store.services.password.bcrypt); - // if (!isMatch) { - // return reply.code(400).send({ - // simplydata: { - // error: true, - // code: 400, - // message: "Invalid Phone or Password", - // }, - // }); - // } - - // const token = request.jwt.sign( - // { - // storename: store.storename, - // storeId: store._id, - // roles: store.profile.role, - // }, - // { expiresIn: "30d" } - // ); - - // var profilePicture = await profilePictureStore.findOne({ storeId: store.storeId }); - - // if (!profilePicture) { - // reply.send({ - // simplydata: { - // error: false, - // apiversion: fastify.config.APIVERSION, - // access_token: token, - // email: store.emails, - // phone: store.phone, - // storeId: store.storeId, - // storename: store.storename, - // office_address: store.profile.office_address, - // phoneVerified: store.phoneVerified, - // oneTimePasswordSetFlag: store.oneTimePasswordSetFlag, - // latitude: store.latitude, - // longitude: store.longitude, - // description: store.description, - // type: store.profile.role, - // typeasobj: JSON.stringify(Object.assign({}, store.profile.role)), - // }, - // }); - // } else { - // reply.send({ - // simplydata: { - // error: false, - // apiversion: fastify.config.APIVERSION, - // access_token: token, - // picture: profilePicture.picture, - // email: store.emails, - // phone: store.phone, - // storeId: store.storeId, - // storename: store.storename, - // office_address: store.profile.office_address, - // phoneVerified: store.phoneVerified, - // oneTimePasswordSetFlag: store.oneTimePasswordSetFlag, - // latitude: store.latitude, - // longitude: store.longitude, - // description: store.description, - // type: store.profile.role, - // typeasobj: JSON.stringify(Object.assign({}, store.profile.role)), - // }, - // }); - // } - // } catch (err) { - // reply.send({ - // simplydata: { - // error: true, - // code: 500, - // message: err.message, - // }, - // }); - // } - // }; - - + const moment = require('moment'); + exports.createwaterlevelSensor = async (req, reply) => { + try { + const { hardwareId,hardwareId_company, type, indate } = req.body; + var mater_seq_id = await generatewaterlevelsensorId(); + const date = moment().format('MM-DD'); + const prefix = 'AS-' + date + '--MALOV1-'; + var masterId = `${prefix}${mater_seq_id}`; + const newSensor = new WaterLeverSensor({ + hardwareId, + masterId, + type, + indate + }); + const savedSensor = await newSensor.save(); + reply.code(201).send(savedSensor); + } catch (err) { + reply.code(500).send(err); + } + }; \ No newline at end of file diff --git a/src/models/store.js b/src/models/store.js index b6d7109e..68d0248c 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -153,13 +153,60 @@ const installationschema = new mongoose.Schema({ +const waterLeverSensorInSchema = new mongoose.Schema({ + 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" }, + + + slaves: { + source: { type: String }, + tankhardware: [ + { + tankhardwareId: { type: String }, + slaveId: { 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" }, + } + ] + } +}); + + + + const Store = mongoose.model("Store", storeSchema); - + const WaterLeverSensor = mongoose.model('WaterLeverSensor', waterLeverSensorInSchema); const ProfilePictureStore = mongoose.model('ProfilePictureStore', profilePictureStoreSchema); const ProfilePictureInstall = mongoose.model('ProfilePictureInstall', profilePictureInstallSchema); const Install = mongoose.model("Install", installationschema); - module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore}; + module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor}; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index de77f6de..4df03ac6 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -134,7 +134,24 @@ fastify.post('/api/stores', { handler: storeController.addStore, }); - +fastify.post("/api/createwaterlevelSensor", { + schema: { + description: "This is for creating waterlevel Sensor", + tags: ["Store-Data"], + summary: "This is for creating waterlevel Sensor", + body: { + type: "object", + + properties: { + hardwareId: { type: "string" }, + type: { type: "string" }, + indate: { type: "string" }, + hardwareId_company: { type: "string" } + }, + }, + }, + handler: storeController.createwaterlevelSensor, +}) next(); };