Commit 19abb7f4 by jaymehta

end user sign up

1 parent 9ac2ea61
......@@ -15,7 +15,7 @@
"type": "relation",
"relation": "oneToOne",
"target": "api::end-user.end-user",
"inversedBy": "courseDetail"
"mappedBy": "courseDetail"
},
"experience": {
"type": "relation",
......
......@@ -15,7 +15,7 @@
"name": {
"type": "string"
},
"number": {
"phone": {
"type": "string"
},
"age": {
......@@ -26,6 +26,9 @@
"relation": "oneToOne",
"target": "api::course-detail.course-detail",
"inversedBy": "endUser"
},
"email": {
"type": "string"
}
}
}
'use strict';
"use strict";
/**
* end-user controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController('api::end-user.end-user');
module.exports = createCoreController("api::end-user.end-user", () => ({
async create(ctx) {
// console.log("ctx", ctx.request.body);
// Get user from user entity
const currentUser = await strapi
.query("plugin::users-permissions.user")
.findOne({
populate: ["user"],
where: {
$and: [{ email: ctx.request.body.data.email }],
},
});
// Check if its already existing in vendor entity
console.log("currentUser", currentUser);
console.log(
"phoneNumber",
ctx.request.body.data.mobileNo,
ctx.request.body.data.email
);
let existingUser;
existingUser = await strapi.entityService.findMany("api::end-user.end-user", {
// fields: ["id"],
filters: { phone: { $eq: ctx.request.body.data.mobileNo } },
});
console.log("existingUser> 1", existingUser);
if (!existingUser) {
existingUser = await strapi.entityService.findMany("api::end-user.end-user", {
// fields: ["id"],
filters: { email: { $eq: ctx.request.body.data.email } },
});
}
console.log("existingUser > 2", existingUser);
// Generate one time password (otp)
const oneTimePassword = Math.floor(1000 + Math.random() * 9000);
await strapi.entityService.update(
"plugin::users-permissions.user",
currentUser.id,
{
data: {
oneTimePassword: `${oneTimePassword}`,
},
}
);
const date = new Date();
// TODO: Code to send OTP on email
// TODO: Code to send OTP on SMS
console.log("ctx.request.body.data", ctx.request.body.data);
console.log("existingUser", existingUser);
if (existingUser && existingUser.length !== 0) {
} else {
ctx.request.body.data.user = currentUser.id;
const response = await strapi.entityService.create("api::end-user.end-user", {
data: {
...ctx.request.body.data,
phone: ctx.request.body.data.mobileNo,
publishedAt: date,
},
});
console.log("response", response);
return { otpSent: true, data: response };
// ctx.request.body.data.user = currentUser;
// console.log("ctx.request.body.data", ctx.request.body.data);
// return await super.create(ctx);
}
ctx.send({
ok: true,
message: "Existing vendor found, skipping creation only sent OTP.",
});
},
}));
......@@ -8,7 +8,7 @@
"description": ""
},
"options": {
"draftAndPublish": true
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
......
......@@ -119,7 +119,8 @@ module.exports = createCoreController("api::experience.experience", () => ({
if (!ctx.request.body.data.category) {
throw new ValidationError("Category is a mandatory field");
}
console.log("subcategoyr", ctx.request.body.data.subCategory);
console.log("subcategoyr", ctx.params);
const { id } = ctx.params;
const subCategory = await strapi
.query("api::sub-categorie.sub-categorie")
......@@ -137,12 +138,15 @@ module.exports = createCoreController("api::experience.experience", () => ({
},
},
});
const activity = await strapi.entityService.update(
"api::experience.experience",
{ id: ctx.request.body.data.activityId },
console.log(
"ctx.request.body.data.activityId",
ctx.request.body.data.activityId
);
const updatedExperience = await strapi
.query("api::experience.experience")
.update(
{ id },
{
data: {
name: ctx.request.body.data.name,
description: ctx.request.body.data.description,
pricePerPerson: ctx.request.body.data.pricePerPerson,
......@@ -174,15 +178,51 @@ module.exports = createCoreController("api::experience.experience", () => ({
contactPersonForBooking:
ctx.request.body.data.contactPersonForBooking,
...ctx.request.body.data.daysBoolean,
},
}
);
// const activity = await strapi.entityService.update(
// "api::experience.experience",
// { id: ctx.request.body.data.activityId },
// {
// name: ctx.request.body.data.name,
// description: ctx.request.body.data.description,
// pricePerPerson: ctx.request.body.data.pricePerPerson,
// address: ctx.request.body.data.address,
// masterPincode: ctx.request.body.data.pincode.id,
// minimumDuration: ctx.request.body.data.minimumDuration,
// maximumDuration: ctx.request.body.data.maximumDuration,
// duration: ctx.request.body.data.duration,
// ageLowerLimit: ctx.request.body.data.ageLowerLimit,
// ageNotes: ctx.request.body.data.ageNotes,
// phoneNumber: ctx.request.body.data.phoneNumber,
// minGroupSize: ctx.request.body.data.minGroupSize,
// maxGroupSize: ctx.request.body.data.maxGroupSize,
// activityType: ctx.request.body.data.activityType,
// link: ctx.request.body.data.link,
// cancellationPolicy: ctx.request.body.data.cancellationPolicy,
// // vendor: ctx.request.body.data.vendor.id,
// subCategory: subCategory.id,
// category: category.id,
// giftSomeone: ctx.request.body.data.giftSomeone,
// fromDate: ctx.request.body.data.fromDate,
// toDate: ctx.request.body.data.toDate,
// fromTime: ctx.request.body.data.fromTime,
// toTime: ctx.request.body.data.toTime,
// offers: ctx.request.body.data.offers,
// rating: ctx.request.body.data.rating,
// contactPersonForActivity:
// ctx.request.body.data.contactPersonForActivity,
// contactPersonForBooking: ctx.request.body.data.contactPersonForBooking,
// ...ctx.request.body.data.daysBoolean,
// }
// );
console.log("updatedExperience", updatedExperience);
ctx.send({
success: true,
message: "Activity updated",
data: {
...activity,
...updatedExperience,
},
});
},
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!