|
|
|
@ -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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -120,7 +124,7 @@ exports.loginSupplier = async (req) => {
|
|
|
|
|
role = ["supplier"];
|
|
|
|
|
supplier.profile.role = role;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insertedSupplier = await supplier.save();
|
|
|
|
|
console.log(insertedSupplier);
|
|
|
|
|
if (insertedSupplier) {
|
|
|
|
@ -137,6 +141,8 @@ exports.loginSupplier = async (req) => {
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
profile: insertedSupplier.profile,
|
|
|
|
|
latitude: insertedSupplier.latitude,
|
|
|
|
|
longitude: insertedSupplier.longitude
|
|
|
|
|
},
|
|
|
|
|
status_code: 200,
|
|
|
|
|
};
|
|
|
|
@ -147,4 +153,63 @@ exports.loginSupplier = async (req) => {
|
|
|
|
|
} catch (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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|