|
|
|
@ -235,6 +235,114 @@ exports.loginSupplier = async(request, reply) =>{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Login Delivery Handler
|
|
|
|
|
exports.loginDeliveryBoy = async(request, reply) =>{
|
|
|
|
|
loginObject = await supplierController.loginDeliveryBoy(request);
|
|
|
|
|
console.log("loginObject...",loginObject)
|
|
|
|
|
if (loginObject.same) {
|
|
|
|
|
const phoneVerified = loginObject.delivery.phoneVerified;
|
|
|
|
|
const oneTimePasswordSetFlag = loginObject.delivery.oneTimePasswordSetFlag;
|
|
|
|
|
console.log(
|
|
|
|
|
"oneTimePasswordSetFlag is ......",
|
|
|
|
|
oneTimePasswordSetFlag,
|
|
|
|
|
typeof oneTimePasswordSetFlag,
|
|
|
|
|
typeof phoneVerified
|
|
|
|
|
);
|
|
|
|
|
if (!phoneVerified) {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
phoneVerified: false,
|
|
|
|
|
|
|
|
|
|
phone: loginObject.delivery.phone,
|
|
|
|
|
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
|
|
|
|
|
message: "Please Verify your phone number",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else if (oneTimePasswordSetFlag) {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
phoneVerified: phoneVerified,
|
|
|
|
|
phone: loginObject.delivery.phone,
|
|
|
|
|
oneTimePasswordSetFlag: true,
|
|
|
|
|
message: "Password must be reset",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const token = fastify.jwt.sign(
|
|
|
|
|
{
|
|
|
|
|
deliveryBoyname: loginObject.delivery.name,
|
|
|
|
|
deliveryBoyId: loginObject.delivery._id,
|
|
|
|
|
},
|
|
|
|
|
//expiresIn: expressed in seconds or a string describing a time span zeit/ms. Eg: 60, "2 days", "10h", "7d".
|
|
|
|
|
//A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc),
|
|
|
|
|
//otherwise milliseconds unit is used by default ("120" is equal to "120ms").
|
|
|
|
|
{ expiresIn: "30d" }
|
|
|
|
|
);
|
|
|
|
|
console.log(token, "..token")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var d_id = loginObject.delivery._id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(d_id,"deliveryId")
|
|
|
|
|
var profilePicture = await ProfilePicture.findOne({ deliveryBoyId:d_id});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// request.session.set('supplierId', loginObject.supplier._id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!profilePicture) {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
phone: loginObject.delivery.phone,
|
|
|
|
|
deliveryBoyId: loginObject.delivery.deliveryBoyId,
|
|
|
|
|
deliveryBoyname: loginObject.delivery.name,
|
|
|
|
|
address: loginObject.delivery.address,
|
|
|
|
|
phoneVerified: loginObject.delivery.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}if (profilePicture) {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
picture:profilePicture.picture,
|
|
|
|
|
phone: loginObject.delivery.phone,
|
|
|
|
|
deliveryBoyId: loginObject.delivery.deliveryBoyId,
|
|
|
|
|
deliveryBoyname: loginObject.delivery.name,
|
|
|
|
|
address: loginObject.delivery.address,
|
|
|
|
|
phoneVerified: loginObject.delivery.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
error = {
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
code: 400,
|
|
|
|
|
message: "Invalid Details",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
reply.send(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if all the required fields are supplied by the user
|
|
|
|
|
|
|
|
|
|
exports.fieldCheck = async (req, reply) => {
|
|
|
|
|