removed commented code

master
Varun 10 months ago
parent e10c29878b
commit 402ff36cbe

@ -10,500 +10,6 @@ const fastify = require("fastify")({
});
// add new tanks
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname })
// const usertobeInserted = req.body;
// tankInfo.connections.source = tankInfo.tankName;
// 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){
// if(data['output_type'] === "overhead"){
// const tankName = data['outputConnections']
// const tank_info = await Tank.findOne({ customerId: customerId.toString(),tankName:tankName })
// const connection_data_check =tank_info.connections.inputConnections
// const sump_names=[]
// for(const d of connection_data_check){
// if (sump_names.includes(d.inputConnections)) {
// console.log(`${d.inputConnections} exists in ${sump_names}`);
// } else {
// sump_names.push(d.inputConnections)
// }
// }
// console.log(sump_names)
// //tank_info.connections.inputConnections = tankname.toString()
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// const tankConnections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// { $addToSet: { 'connections.inputConnections': { $each: [{ inputConnections: tankname, input_type: 'sump' }] } } },
// { new: true }
// );
// }
// //console.log(tankConnections)
// }
// }
// const tank_connections = await tankInfo.save();
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: connection.motor_status || "0",
// inputismotor: connection.inputismotor || false,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// outputismotor: connection.outputismotor || false,
// };
// });
// }
// const tank_connections = await tankInfo.save();
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = tank_connections.connections.outputConnections;
// console.log("connection_data",connection_data)
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// const tankConnections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// { $addToSet: { 'connections.inputConnections': { $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: false }] } } },
// { new: true }
// );
// console.log("tankConnections", tankConnections.connections.);
// }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: connection.motor_status || "0",
// inputismotor: connection.inputismotor ,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// outputismotor: connection.outputismotor ,
// };
// });
// }
// const tank_connections = await tankInfo.save();
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = usertobeInserted.outputConnections;
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// const tankConnections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// {
// $addToSet: {
// 'connections.inputConnections': {
// $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: usertobeInserted.inputismotor }],
// },
// 'connections.outputConnections': {
// $each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor: usertobeInserted.outputismotor }],
// },
// },
// },
// { new: true }
// );
// console.log("tankConnections", tankConnections.connections.inputConnections);
// console.log("tankConnections", tankConnections.connections.outputConnections);
// }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: connection.motor_status || "0",
// inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false,
// };
// });
// }
// const tank_connections = await tankInfo.save();
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = usertobeInserted.outputConnections;
// console.log(connection_data, "connection_data")
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// const tankConnections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// {
// $addToSet: {
// 'connections.inputConnections': {
// $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: false }],
// },
// 'connections.outputConnections': {
// $each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor: false }],
// },
// },
// },
// { new: true }
// );
// console.log("tankConnections", tankConnections.connections.inputConnections);
// console.log("tankConnections", tankConnections.connections.outputConnections);
// }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: connection.motor_status || "0",
// inputismotor: connection.inputismotor,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// outputismotor: connection.outputismotor ,
// };
// });
// const outputConnectionNames = usertobeInserted.outputConnections.map(connection => connection.outputConnections);
// const existingInputConnections = tankInfo.connections.inputConnections.filter(connection =>
// outputConnectionNames.includes(connection.inputConnections)
// );
// for (const connection of existingInputConnections) {
// connection.inputismotor = true;
// }
// }
// const tank_connections = await tankInfo.save();
// console.log("tank_connections", tank_connections.connections.inputConnections)
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = usertobeInserted.outputConnections;
// console.log(connection_data, "connection_data");
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// console.log("tankName", tankName)
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// const tankConnections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// {
// $addToSet: {
// 'connections.inputConnections': {
// $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: tank_connections.connections.inputConnections.inputismotor }],
// },
// 'connections.outputConnections': {
// $each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor:tank_connections.connections.outputConnections.outputismotor }],
// },
// },
// },
// { new: true }
// );
// console.log("tankConnections", tankConnections.connections.inputConnections);
// console.log("tankConnections", tankConnections.connections.outputConnections);
// }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: "0",
// inputismotor: connection.inputismotor,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// motor_status: "0",
// outputismotor: connection.outputismotor
// };
// });
// const outputConnectionNames = usertobeInserted.outputConnections.map(connection => connection.outputConnections);
// const existingInputConnections = tankInfo.connections.inputConnections.filter(connection =>
// outputConnectionNames.includes(connection.inputConnections)
// );
// for (const connection of existingInputConnections) {
// connection.inputismotor = true;
// }
// }
// const tank_connections = await tankInfo.save();
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = usertobeInserted.outputConnections;
// console.log(connection_data, "connection_data");
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// console.log("data", data)
// if (sump_names.includes(tankName)) {
// console.log(`${tankName} exists in ${sump_names}`);
// } else {
// const tank_connections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// {
// $addToSet: {
// 'connections.inputConnections': {
// $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor }],
// },
// 'connections.outputConnections': {
// $each: [{ outputConnections: tankname, output_type: 'overhead' }],
// },
// },
// },
// { new: true }
// );
// console.log("tankConnections", tank_connections.connections.inputConnections);
// console.log("tankConnections", tank_connections.connections.outputConnections);
// }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, reply) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// // Retrieve the tank or return an error if it's not found
// const tankInfo = await Tank.findOne({ customerId: customerId.toString(), tankName: tankname });
// if (!tankInfo) {
// return reply.send({ status_code: 404, error: "Tank not found" });
// }
// // Update the source tank info
// tankInfo.connections.source = tankname;
// // Handle input connections
// if (req.body.inputConnections) {
// tankInfo.connections.inputConnections = req.body.inputConnections.map(connection => ({
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_id: connection.motor_id || null,
// motor_status: connection.motor_status || "0",
// motor_stop_status: connection.motor_stop_status || "1",
// inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
// capacity: connection.capacity || null,
// water_level: connection.water_level || null
// }));
// }
// // Handle output connections
// if (req.body.outputConnections) {
// tankInfo.connections.outputConnections = req.body.outputConnections.map(connection => ({
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// motor_id: connection.motor_id || null,
// motor_status: connection.motor_status || "0",
// motor_stop_status: connection.motor_stop_status || "1",
// outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false,
// capacity: connection.capacity || null,
// water_level: connection.water_level || null
// }));
// }
// // Save the updated tank connections
// const updatedTankConnections = await tankInfo.save();
// console.log("Updated Tank Connections:", updatedTankConnections.connections);
// // Send the updated tank connections as the response
// return reply.send({ status_code: 200, data: updatedTankConnections });
// } catch (err) {
// throw boom.boomify(err);
// }
// };
@ -646,139 +152,6 @@ exports.createConnections = async (req, res) => {
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: connection.motor_status || "0",
// inputismotor: connection.inputismotor,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// outputismotor: connection.outputismotor,
// };
// });
// }
// const tank_connections = await tankInfo.save();
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = usertobeInserted.outputConnections;
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// const tankConnections = await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// {
// $addToSet: {
// 'connections.inputConnections': {
// $each: [{ inputConnections: tankname, input_type: 'sump' }],
// },
// 'connections.outputConnections': {
// $each: [{ outputConnections: tankname, output_type: 'overhead' }],
// },
// },
// },
// { new: true }
// );
// console.log("tankConnections", tankConnections.connections.inputConnections);
// console.log("tankConnections", tankConnections.connections.outputConnections); }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
// exports.createConnections = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// const tankname = req.body.tankname;
// 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.map(connection => {
// return {
// inputConnections: connection.inputConnections,
// input_type: connection.input_type,
// motor_status: connection.motor_status || "0",
// inputismotor: connection.inputismotor,
// };
// });
// }
// if (usertobeInserted.outputConnections) {
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
// return {
// outputConnections: connection.outputConnections,
// output_type: connection.output_type,
// outputismotor: connection.outputismotor,
// };
// });
// }
// const tank_connections = await tankInfo.save();
// const connection_data_check = tank_connections.connections.inputConnections;
// const sump_names = connection_data_check.map(d => d.inputConnections);
// console.log(sump_names);
// const connection_data = usertobeInserted.outputConnections;
// for (const data of connection_data) {
// if (data['output_type'] === "overhead") {
// const tankName = data['outputConnections'];
// if (sump_names.includes(tankname)) {
// console.log(`${tankname} exists in ${sump_names}`);
// } else {
// await Tank.findOneAndUpdate(
// { customerId: customerId.toString(), tankName: tankName },
// {
// $addToSet: {
// 'connections.inputConnections': { inputConnections: tankname, input_type: 'sump' , inputismotor:tank_connections.connections.inputConnections},
// 'connections.outputConnections': { outputConnections: tankname, output_type: 'overhead', outputismotor : tank_connections.connections.outputConnections},
// },
// },
// { new: true }
// );
// }
// }
// }
// return tank_connections;
// } catch (err) {
// throw boom.boomify(err);
// }
// };
exports.updateconnectionInfo = async (req, reply) => {
try {
@ -860,30 +233,3 @@ exports.getConnections = async (req, reply) => {
// exports.createConnectionsforOh = async (req, body) => {
// try {
// const customerId = req.params.customerId;
// var tankname = req.body.tankname;
// const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname ,tankLocation:"sump"})
// const connection_data = tankinfo.connections.outputConnections
// for (data in connection_data) {
// console.log(data)
// }
// // 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;
// //const tank_connections = await tankInfo.save();
// // return tank_connections;
// } catch (err) {.
// throw boom.boomify(err);
// }
// };

@ -92,83 +92,6 @@ exports.installSignUp = async (request, reply) => {
// exports.installLogin = async (request, reply) => {
// try {
// const { phone, password } = request.body;
// // Check if an install with the phone number exists
// const install = await Install.findOne({ phone });
// if (!install) {
// return reply.status(401).send({
// simplydata: {
// error: true,
// message: 'Invalid Phone or password'
// }
// });
// }
// // Compare the password entered by the user with the hashed password stored in the database
// const isPasswordValid = await bcrypt.compare(password, install.services.password.bcrypt);
// if (!isPasswordValid) {
// return reply.status(401).send({
// simplydata: {
// error: true,
// message: 'Invalid phone or password'
// }
// });
// }
// // Generate a JWT token for the authenticated install
// const token = fastify.jwt.sign({ phone: install.phone }, 'your_jwt_secret', { expiresIn: '30d' });
// // Fetch the profile picture if it exists
// const profilePicture = await ProfilePictureInstall.findOne({ customerId: install._id });
// const responsePayload = {
// simplydata: {
// error: false,
// apiversion: fastify.config.APIVERSION,
// access_token: token,
// email: install.emails,
// installationId: install.installationId,
// phone: install.phone,
// address1: install.address1,
// address2: install.address2,
// phoneVerified: install.phoneVerified,
// oneTimePasswordSetFlag: install.oneTimePasswordSetFlag,
// type: install.profile.role,
// fcmId: install.fcmId,
// team: install.team,
// city: install.city,
// manager: install.manager,
// firstName: install.firstName,
// lastName: install.lastName,
// address: install.address,
// alternativeNumber: install.alternativeNumber,
// }
// };
// if (profilePicture) {
// responsePayload.simplydata.picture = profilePicture.picture;
// }
// // Return the token and user details to the client
// return reply.send(responsePayload);
// } catch (err) {
// reply.status(500).send({
// simplydata: {
// error: true,
// message: err.message
// }
// });
// }
// };
exports.installationVerifyPhone = async (req, reply) => {
console.log("-------------------------------------------------");
@ -708,81 +631,7 @@ exports.editStore = async (request, reply) => {
// exports.addStore = async (req, reply) => {
// try {
// const { storename, password, phone, emails } = req.body;
// if (!emails) {
// return reply.status(400).send({ error: 'Email is required and cannot be null.' });
// }
// var s_id = await generateStoreId();
// var building = storename.slice(0, 3).toUpperCase();
// var store_id = `AWSST${building}${s_id}`;
// const s_data = {
// storeId: store_id,
// storename,
// emails: emails.trim(),
// password,
// phone,
// description: req.body.description,
// profile: {
// firstName: req.body.firstName,
// lastName: req.body.lastName,
// contactNumber: phone,
// alternativeContactNumber: req.body.alternativeContactNumber,
// office_address: req.body.office_address,
// country: req.body.country,
// state: req.body.state,
// city: req.body.city,
// zip: req.body.zip,
// },
// latitude: req.body.latitude,
// longitude: req.body.longitude,
// fcmId: req.body.fcmId,
// };
// var store = new Store(s_data);
// var storepass = password;
// // Store hash in your password DB.
// var hash = await bcryptPassword(storepass);
// if (hash) {
// store.services.password.bcrypt = hash;
// store.profile.role = req.body.role || ["store"];
// var insertedStore = await Store.save();
// if (insertedStore) {
// var retStore = {
// armintatankdata: {
// storename: insertedStore.storename,
// phone: insertedStore.phone,
// storeId: insertedStore.storeId,
// office_address: insertedStore.profile.office_address,
// emails: insertedStore.emails,
// profile: insertedStore.profile,
// latitude: insertedStore.latitude,
// longitude: insertedStore.longitude,
// fcmId: insertedStore.fcmId,
// description: insertedStore.description,
// },
// status_code: 200,
// };
// return reply.status(200).send(retStore);
// }
// }
// } catch (err) {
// if (err.code === 11000) {
// // Handle duplicate key error
// return reply.status(400).send({ error: 'Duplicate key error', message: err.message });
// }
// throw boom.boomify(err);
// }
// };
const generatewaterlevelsensorId = async () => {
const result = await Counter.findOneAndUpdate(

@ -640,58 +640,7 @@ exports.getAllOrderaccepted = async (req, reply) => {
}
};
// exports.getAllOrderaccepted = async (req, reply) => {
// const customerId = req.params.customerId;
// try {
// const order = await Tankerbooking.findOne({ customerId: customerId, orderStatus: "accepted" }).exec();
// if (!order) {
// reply.status(404).send({ message: "No order found" });
// return;
// }
// const deliveryBoy = await DeliveryBoy.findOne({ phone: order.delivery_agent_mobile });
// const orderWithDeliveryBoyLocation = {
// ...order.toJSON(),
// deliveryBoyLocation: deliveryBoy ? { deliveryboy_latitude: deliveryBoy.latitude, deliveryboy_longitude: deliveryBoy.longitude } : null,
// };
// reply.send({ status_code: 200, data: orderWithDeliveryBoyLocation });
// } catch (err) {
// reply.status(400).send({ message: err.message });
// }
// };
// exports.getAllOrderaccepted = async (req, reply) => {
// const limit = parseInt(req.query.limit) || 100;
// const page = parseInt(req.query.page) || 1;
// const startindex = (page - 1) * limit;
// const customerId = req.params.customerId;
// try {
// const orders = await Tankerbooking.find({ customerId: customerId, orderStatus: "accepted" })
// .limit(limit)
// .skip(startindex)
// .exec();
// const order = orders[0];
// if (order) {
// const deliveryBoy = await DeliveryBoy.findOne({ phone: order.delivery_agent_mobile });
// const orderWithDeliveryBoyLocation = {
// ...order.toJSON(),
// deliveryBoyLocation: deliveryBoy ? { deliveryboy_latitude: deliveryBoy.latitude, deliveryboy_longitude: deliveryBoy.longitude } : null,
// };
// reply.send({ status_code: 200, data: orderWithDeliveryBoyLocation });
// } else {
// reply.status(404).send({ message: "No orders found" });
// }
// } catch (err) {
// reply.status(400).send({ message: err.message });
// }
// };
exports.getAllOrderdelivered = async (req, reply) => {

@ -1,20 +0,0 @@
//const mongoose = require("mongoose");
//const Schema = mongoose.Schema;
//const ObjectId = Schema.Types.ObjectId;
// Store a random password reset code
//const code = Math.floor(100000 + Math.random() * 900000);
//const inputSchema = new Schema({ name: String });
//const createConnectionsSchema = new mongoose.Schema({
// userName: { type: String, default: null },
//source: { type: String,unique:false,trim: true ,required: true},
//inputConnections: [{ inputConnections: String}],
//outputConnections: [{ outputConnections: String}]
//});
//module.exports = mongoose.model("Connections", createConnectionsSchema);

@ -115,58 +115,6 @@ const userSchema = new mongoose.Schema(
},
{ versionKey: false }
);
// const profilePictureSchema = new Schema({
// customerId: {
// type: String,unique: true,
// required: true
// },
// picture: {
// type: String,
// required: true
// }
// });
// const profilePictureSchema = new Schema({
// customerId: {
// type: String,
// unique: true,
// required: true
// },
// picture: {
// type: String,
// required: true,
// validate: {
// validator: function (value) {
// const supportedFormats = ['jpg', 'jpeg', 'png'];
// const fileExtension = value.split('.').pop().toLowerCase();
// return supportedFormats.includes(fileExtension);
// },
// message: 'Picture must be a JPEG, PNG or JPG image'
// }
// }
// });
// const profilePictureSchema = new Schema({
// customerId: {
// type: String,
// unique: true,
// required: true
// },
// picture: {
// type: Buffer, // Store the file as binary data
// required: true,
// validate: {
// validator: function (value) {
// const supportedFormats = ['jpg', 'jpeg', 'png'];
// const fileExtension = value.split('.').pop().toLowerCase();
// return supportedFormats.includes(fileExtension);
// },
// message: 'Picture must be a JPEG, PNG, or JPG image'
// }
// }
// });
const profilePictureSchema = new Schema({
customerId: {

@ -132,45 +132,7 @@ const supplierSchema = new mongoose.Schema(
fcmId: { type: String, default: null },
});
// const profilePictureSupplierSchema = new Schema({
// // supplierId: {
// // type: String,unique: true,
// // required: true
// // },
// // // picture: {
// // // type: String,
// // // required: true
// // // }
// // picture: {
// // type: String,
// // required: true,
// // validate: {
// // validator: function (value) {
// // const supportedFormats = ['jpg', 'jpeg', 'png'];
// // const fileExtension = value.split('.').pop().toLowerCase();
// // return supportedFormats.includes(fileExtension);
// // },
// // message: 'Picture must be a JPEG, PNG or JPG image'
// // }
// // }
// supplierId: {
// type: String,
// unique: true,
// required: true
// },
// picture: {
// type: Buffer,
// required: true,
// validate: {
// validator: function (value) {
// const supportedFormats = ['jpg', 'jpeg', 'png'];
// const fileExtension = value.split('.').pop().toLowerCase();
// return supportedFormats.includes(fileExtension);
// },
// message: 'Picture must be a JPEG, PNG, or JPG image'
// }
// }
// });
const profilePictureSupplierSchema = new Schema({
supplierId: {

@ -368,38 +368,7 @@ module.exports = function (fastify, opts, next) {
// fastify.get("/api/userAccountsofparticularSupplier/:customerId", {
// schema: {
// tags: ["Supplier-Order"],
// description: "This is for Get accounts of user for particular supplier",
// summary: "This is for to Get accounts of user for particular supplier",
// params: {
// required: ["customerId"],
// type: "object",
// properties: {
// customerId: {
// type: "string",
// description: "customerId",
// },
// },
// },
// body: {
// type: "object",
// properties: {
// supplierId:{type:"string"}
// },
// },
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// preHandler: fastify.auth([fastify.authenticate]),
// handler: supplierOrderController.userAccountsofparticularSupplier,
// });

@ -542,428 +542,6 @@ module.exports = function (fastify, opts, next) {
});
// fastify.route({
// method: "POST",
// url: "/api/supplier/profile-picture/:supplierId",
// schema: {
// tags: ["Supplier"],
// description: "This is for uploading profile picture supplier.",
// summary: "This is for uploading profile picture supplier.",
// params: {
// type: "object",
// properties: {
// supplierId: {
// type: "string",
// description: "supplierId",
// },
// },
// },
// body: {
// type: "object",
// required: ["picture"],
// properties: {
// picture: {
// type: 'string'
// }
// },
// },
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// handler: validationHandler.uploadProfilePicture,
// });
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture for a supplier',
// summary: 'Upload a profile picture for a supplier',
// params: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'Supplier ID',
// },
// },
// },
// consumes: ['multipart/form-data'],
// body: {
// type: 'object',
// properties: {
// picture: {
// type: 'string',
// description: 'Profile picture file',
// },
// },
// required: ['picture'],
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: validationHandler.uploadProfilePicture,
// });
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture for a supplier',
// summary: 'Upload a profile picture for a supplier',
// params: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'Supplier ID',
// },
// },
// },
// consumes: ['multipart/form-data'],
// body: {
// type: 'object',
// properties: {
// picture: {
// type: 'string',
// properties: {
// data: { type: 'string' },
// encoding: { type: 'string' },
// filename: { type: 'string' },
// },
// required: ['data', 'encoding', 'filename'], // Add required properties
// },
// },
// required: ['picture'],
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: validationHandler.uploadProfilePicture,
// });
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture for a supplier',
// summary: 'Upload a profile picture for a supplier',
// params: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'Supplier ID',
// },
// },
// },
// consumes: ['multipart/form-data'],
// body: {
// type: 'object',
// properties: {
// picture: {
// type: 'string',
// description: 'Profile picture file',
// // format: 'binary', // Specify the format as binary for file upload
// },
// },
// required: ['picture'],
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: validationHandler.uploadProfilePicture,
// });
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture for a supplier',
// summary: 'Upload a profile picture for a supplier',
// params: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'Supplier ID',
// },
// },
// },
// consumes: ['multipart/form-data'],
// body: {
// type: 'object',
// properties: {
// file: {
// type: 'string',
// description: 'Profile picture file',
// },
// },
// required: ['picture'],
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: validationHandler.uploadProfilePicture,
// });
// const { Storage } = require('@google-cloud/storage');
// const storage = new Storage({
// keyFilename :`/home/bhaskar/Downloads/arminta-tank-0f492875da39.json`,
// projectId : `arminta-tank`
// });
// const bucketName = 'armintaprofile_picture';
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture for a supplier',
// summary: 'Upload a profile picture for a supplier',
// // params: {
// // type: 'object',
// // properties: {
// // supplierId: {
// // type: 'string',
// // description: 'Supplier ID',
// // },
// // },
// // },
// consumes: ['multipart/form-data'],
// body: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'Supplier ID',
// },
// },
// required: ['picture'],
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: validationHandler.uploadProfilePicture
// });
const multer = require('multer');
const fs = require('fs');
const storage = multer.diskStorage({
destination: function (req, file, cb) {
if (!fs.existsSync(__dirname + '/temp')) {
fs.mkdirSync(__dirname + '/temp');
}
cb(null, './temp');
},
filename: function (req, file, cb) {
cb(null, file.originalname + '-' + Date.now() + '.' + file.mimetype.split('/')[1]);
},
});
const upload = multer({ storage: storage }).single('picture');
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier/:supplierId',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture supplier',
// summary: 'Upload a profile picture supplier',
// params: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'SupplierId',
// },
// },
// },
// body: {
// formData: {
// picture: {
// type: 'string',
// format: 'binary',
// description: 'Profile picture file',
// },
// },
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: async (req, reply) => {
// try {
// upload(req, reply, async (err) => {
// if (err) {
// reply.status(400).send({ error: 'Failed to upload profile picture' });
// return;
// }
// const supplierId = req.params.supplierId;
// const picturePath = req.file.path;
// let profilePicture = await profilePictureSupplier.findOne({ supplierId });
// if (!profilePicture) {
// profilePicture = new ProfilePicture({
// supplierId,
// picture: fs.readFileSync(picturePath),
// });
// } else {
// profilePicture.picture = fs.readFileSync(picturePath);
// }
// await profilePicture.save();
// // Delete the temporary uploaded file
// fs.unlinkSync(picturePath);
// reply.send({ message: 'Profile picture uploaded successfully' });
// });
// } catch (error) {
// reply.status(500).send({ error: error.message });
// }
// },
// });
next();
}

@ -450,39 +450,7 @@ module.exports = function (fastify, opts, next) {
// Login for a user is in the main index.js file.
// fastify-jwt used to create the token was throwing exceptions and requierd
// it be called before the route is loaded.
// fastify.route({
// method: "POST",
// url: "/api/users/profile-picture/:customerId",
// schema: {
// tags: ["User"],
// description: "This is for uploading profile picture.",
// summary: "This is for uploading profile picture.",
// params: {
// type: "object",
// properties: {
// customerId: {
// type: "string",
// description: "customerId",
// },
// },
// },
// body: {
// type: "object",
// required: ["picture"],
// properties: {
// picture: {
// type: 'string'
// }
// },
// },
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// handler: userController.uploadProfilePicture,
// });
const multer = require('multer');

Loading…
Cancel
Save