varun 3 years ago
commit 5ee7cc0910

@ -80,6 +80,8 @@ exports.loginSupplier = async (req) => {
office_adress: req.body.office_adress,
zip: req.body.zip,
},
latitude: req.body.latitude,
longitude: req.body.longitude
};
var supplier = new Supplier(s_data);
@ -87,7 +89,7 @@ exports.loginSupplier = async (req) => {
//password is not at the top level in the collection.
supplierpass = req.body.password;
// If fields are sent via form encoding , capture the fields and assign them to the user Object.
// If fields are sent via form encoding , capture the fields and assign them to the supplier Object.
checkFormEncoding = isSupplierFormUrlEncoded(req);
if (checkFormEncoding.isSupplierFormUrlEncoded) {
@ -102,6 +104,8 @@ exports.loginSupplier = async (req) => {
supplier.supplierId = suppliertobeInserted.supplier_id;
supplier.office_adress = suppliertobeInserted.office_adress;
supplier.alternativeContactNumber = suppliertobeInserted.alternativeContactNumber;
supplier.latitude = suppliertobeInserted.latitude;
supplier.longitude = suppliertobeInserted.longitude;
}
@ -137,6 +141,8 @@ exports.loginSupplier = async (req) => {
},
],
profile: insertedSupplier.profile,
latitude: insertedSupplier.latitude,
longitude: insertedSupplier.longitude
},
status_code: 200,
};
@ -148,3 +154,62 @@ exports.loginSupplier = async (req) => {
throw boom.boomify(err);
}
};
exports.editCuurentSupplierInfo = async (req, reply) => {
try {
const { supplierId } = req.params;
const supplierInfo = await Supplier.findOne({ supplierId: supplierId.toString() });
const updateData = req.body;
if (updateData.firstName) supplierInfo.profile.firstName = updateData.firstName;
if (updateData.lastName) supplierInfo.profile.lastName = updateData.lastName;
if (updateData.suppliername) supplierInfo.suppliername = updateData.suppliername;
if (updateData.phone) supplierInfo.profile.contactNumber = updateData.phone;
if (updateData.office_address) supplierInfo.profile.office_address = updateData.office_address;
if (updateData.alternativeContactNumber) supplierInfo.profile.alternativeContactNumber = updateData.alternativeContactNumber;
if (updateData.city) supplierInfo.profile.city = updateData.city;
if (updateData.state) supplierInfo.profile.state = updateData.state;
if (updateData.country) supplierInfo.profile.country = updateData.country;
if (updateData.zip) supplierInfo.profile.zip = updateData.zip;
if (updateData.phone) supplierInfo.phone = updateData.phone;
if (updateData.emails) supplierInfo.emails = updateData.emails;
console.log(supplierInfo.emails[0].email)
if (updateData.role) supplierInfo.profile.role = updateData.role;
if (updateData.phone) {
const phoneNumber = updateData.phone //libphonenumberjs.parsePhoneNumber(updateData.phone);
if (phoneNumber) {
// access returned collection
if (!phoneNumber) { //if (!phoneNumber.isValid()) {
error = {
armintatankdata: {
error: true,
code: 10002,
message:
"10002 - Phone # " +
updateData.phone +
" is not a valid phone number",
},
};
req.body.regError = error;
reply.status(406).send(error);
}
}
}
if (supplierInfo.phone == updateData.phone) {
console.log("IF++++++++++++++=");
supplierInfo.phone = updateData.phone;
supplierInfo.phoneVerified = true;
} else {
console.log("Ilse++++++++++++++=");
supplierInfo.phone = updateData.phone;
supplierInfo.phoneVerified = false;
}
const supplier = await supplierInfo.save();
return supplier;
} catch (err) {
throw boom.boomify(err);
}
};

@ -11,7 +11,10 @@ const fastify = require("fastify")({
// Handle friend request creation
exports.friendRequest = async (request, reply) => {
try {
const { senderId, receiverId } = request.body;
// const { senderId, receiverId } = request.body;
const customerId = request.body.customerId;
const supplierId = request.body.supplierId;
// Check if the sender and receiver exist in the database
// const sender = await User.findById(senderId);
@ -19,8 +22,8 @@ exports.friendRequest = async (request, reply) => {
// console.log("sender" , sender)
// console.log("receiver" , receiver)
const sender = await User.findOne(senderId);
const receiver = await Supplier.findOne(receiverId);
const sender = await User.findOne({ customerId : customerId});
const receiver = await Supplier.findOne({ supplierId : supplierId});
console.log("sender" , sender.customerId)
console.log("receiver" , receiver.supplierId)

@ -192,6 +192,8 @@ exports.loginSupplier = async(request, reply) =>{
office_address: loginObject.supplier.profile.office_address,
phoneVerified: loginObject.supplier.phoneVerified,
oneTimePasswordSetFlag: loginObject.supplier.oneTimePasswordSetFlag,
latitude: loginObject.supplier.latitude,
longitude: loginObject.supplier.longitude,
type: loginObject.supplier.profile.role,
typeasobj: stringToJsonObject,
},
@ -210,6 +212,8 @@ exports.loginSupplier = async(request, reply) =>{
office_address: loginObject.supplier.profile.office_address,
phoneVerified: loginObject.supplier.phoneVerified,
oneTimePasswordSetFlag: loginObject.supplier.oneTimePasswordSetFlag,
latitude: loginObject.supplier.latitude,
longitude: loginObject.supplier.longitude,
type: loginObject.supplier.profile.role,
typeasobj: stringToJsonObject,
},

@ -46,7 +46,7 @@ const userSchema = new mongoose.Schema(
username: { type: String },
phone: { type: String, unique: true, trim: true },
address: String,
customerId: String,
customerId: { type: String },
buildingName: String,
inchargeName: String,
phoneVerified: { type: Boolean, default: false },

@ -48,17 +48,22 @@ const supplierSchema = new mongoose.Schema(
default: 'pending'
},
currentGPS: {
// It's important to define type within type field, because
// mongoose use "type" to identify field's object type.
gpsType: { type: String, default: "Point" },
// Default value is needed. Mongoose pass an empty array to
// array type by default, but it will fail MongoDB's pre-save
// validation.
coordinates: { type: [Number], default: [0, 0] },
},
// currentGPS: {
// // It's important to define type within type field, because
// // mongoose use "type" to identify field's object type.
// gpsType: { type: String, default: "Point" },
// // Default value is needed. Mongoose pass an empty array to
// // array type by default, but it will fail MongoDB's pre-save
// // validation.
// coordinates: { type: [Number], default: [0, 0] },
// },
// location: {
// type: { type: String },
// coordinates: [Number]
// },
longitude: { type : Number},
latitude: {type: Number},
isActive: Boolean,
tenantId: ObjectId,
createdAt: {

@ -93,6 +93,8 @@ module.exports = function (fastify, opts, next) {
state: { type: "string", default: null },
zip: { type: "string", default: null },
country: { type: "string", default: null },
latitude: { type: 'number' },
longitude: { type: 'number'}
},
},
security: [
@ -189,6 +191,57 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "PUT",
url: "/api/update/currentSupplier/:supplierId",
schema: {
tags: ["Supplier-Data"],
summary: "This is for update current supplier",
description: "This is for update current supplier",
params: {
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
body: {
type: "object",
properties: {
phone: { type: "string" },
firstName: { type: "string" },
lastName: { type: "string" },
suppliername: { type: "string" },
emails: {
type: "array",
maxItems: 2,
items: {
type: "object",
properties: {
email: { type: "string", default: null },
},
},
},
office_address: { type: "string" },
alternativeContactNumber: { type: "string" },
city: { type: "string" },
state: { type: "string" },
country: { type: "string" },
zip: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
preHandler: [fastify.auth([fastify.authenticate])],
handler: supplierController.editCuurentSupplierInfo,
});
next();
}

Loading…
Cancel
Save