update current supplier

master
Bhaskara Kishore 3 years ago
parent a3c123ca59
commit 886e13b122

@ -87,7 +87,7 @@ exports.loginSupplier = async (req) => {
//password is not at the top level in the collection. //password is not at the top level in the collection.
supplierpass = req.body.password; 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); checkFormEncoding = isSupplierFormUrlEncoded(req);
if (checkFormEncoding.isSupplierFormUrlEncoded) { if (checkFormEncoding.isSupplierFormUrlEncoded) {
@ -148,3 +148,62 @@ exports.loginSupplier = async (req) => {
throw boom.boomify(err); 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);
}
};

@ -189,6 +189,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(); next();
} }

Loading…
Cancel
Save