Commit 3e22dd36 by jaymehta

otp for gift card

1 parent 6662bada
...@@ -26,17 +26,23 @@ module.exports = createCoreController("api::end-user.end-user", () => ({ ...@@ -26,17 +26,23 @@ module.exports = createCoreController("api::end-user.end-user", () => ({
ctx.request.body.data.email ctx.request.body.data.email
); );
let existingUser; let existingUser;
existingUser = await strapi.entityService.findMany("api::end-user.end-user", { existingUser = await strapi.entityService.findMany(
// fields: ["id"], "api::end-user.end-user",
filters: { phone: { $eq: ctx.request.body.data.mobileNo } }, {
}); // fields: ["id"],
filters: { phone: { $eq: ctx.request.body.data.mobileNo } },
}
);
console.log("existingUser> 1", existingUser); console.log("existingUser> 1", existingUser);
if (!existingUser) { if (!existingUser) {
existingUser = await strapi.entityService.findMany("api::end-user.end-user", { existingUser = await strapi.entityService.findMany(
// fields: ["id"], "api::end-user.end-user",
filters: { email: { $eq: ctx.request.body.data.email } }, {
}); // fields: ["id"],
filters: { email: { $eq: ctx.request.body.data.email } },
}
);
} }
console.log("existingUser > 2", existingUser); console.log("existingUser > 2", existingUser);
...@@ -61,13 +67,16 @@ module.exports = createCoreController("api::end-user.end-user", () => ({ ...@@ -61,13 +67,16 @@ module.exports = createCoreController("api::end-user.end-user", () => ({
if (existingUser && existingUser.length !== 0) { if (existingUser && existingUser.length !== 0) {
} else { } else {
ctx.request.body.data.user = currentUser.id; ctx.request.body.data.user = currentUser.id;
const response = await strapi.entityService.create("api::end-user.end-user", { const response = await strapi.entityService.create(
data: { "api::end-user.end-user",
...ctx.request.body.data, {
phone: ctx.request.body.data.mobileNo, data: {
publishedAt: date, ...ctx.request.body.data,
}, phone: ctx.request.body.data.mobileNo,
}); publishedAt: date,
},
}
);
console.log("response", response); console.log("response", response);
return { otpSent: true, data: response }; return { otpSent: true, data: response };
...@@ -82,4 +91,24 @@ module.exports = createCoreController("api::end-user.end-user", () => ({ ...@@ -82,4 +91,24 @@ module.exports = createCoreController("api::end-user.end-user", () => ({
}); });
}, },
async giftCardOtp(ctx) {
// Generate one time password (otp)
// console.log(ctx.request.body);
const oneTimePassword = Math.floor(1000 + Math.random() * 9000);
const res = await strapi.entityService.update(
"plugin::users-permissions.user",
ctx.request.body.data.userId,
{
data: {
oneTimePassword: `${oneTimePassword}`,
},
}
);
// console.log("res", res);
// TODO: ADD FUNCTIONALITY FOR EMAIL AND SMS
ctx.send({
ok: true,
message: "OTP sent successfully",
});
},
})); }));
const routes = {
routes: [
{
method: "POST",
path: "/end-user/verify-gift-card-otp",
handler: "api::end-user.end-user.giftCardOtp",
config: {
// some configuration...
}
},
]
};
module.exports = routes;
\ No newline at end of file \ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!