Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jay Mehta
/
strapi-setup-file
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Registry
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 13639740
authored
2022-11-22 13:10:41 +0530
by
jay
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
send lead while sign up (unsolved error)
1 parent
00989511
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
15 deletions
src/api/end-user/content-types/end-user/schema.json
src/api/end-user/controllers/end-user.js
src/api/end-user/services/end-user.js
src/api/end-user/content-types/end-user/schema.json
View file @
1363974
...
@@ -29,6 +29,24 @@
...
@@ -29,6 +29,24 @@
},
},
"dialCode"
:
{
"dialCode"
:
{
"type"
:
"string"
"type"
:
"string"
},
"httpsRequestBody"
:
{
"type"
:
"text"
},
"httpRequestHeaders"
:
{
"type"
:
"text"
},
"httpRequestUrl"
:
{
"type"
:
"text"
},
"httpRequestMethod"
:
{
"type"
:
"string"
},
"httpResposneBody"
:
{
"type"
:
"text"
},
"thirdPartyApiError"
:
{
"type"
:
"boolean"
}
}
}
}
}
}
src/api/end-user/controllers/end-user.js
View file @
1363974
...
@@ -60,17 +60,12 @@ module.exports = factories.createCoreController(
...
@@ -60,17 +60,12 @@ module.exports = factories.createCoreController(
password
:
oneTimePassword
,
password
:
oneTimePassword
,
});
});
// 5. change from draft to published.
// 5. change from draft to published.
await
strapi
.
entityService
.
update
(
await
strapi
.
entityService
.
update
(
"api::end-user.end-user"
,
endUser
.
id
,
{
"api::end-user.end-user"
,
data
:
{
endUser
.
id
,
publishedAt
:
new
Date
(),
{
},
data
:
{
});
publishedAt
:
new
Date
(),
},
}
);
// TODO: at this point we might have to invoke a Hiranandani API to send the newly registered user there.
// TODO: at this point we might have to invoke a Hiranandani API to send the newly registered user there.
ctx
.
send
({
ok
:
true
,
message
:
"user registered"
});
ctx
.
send
({
ok
:
true
,
message
:
"user registered"
});
...
@@ -78,9 +73,33 @@ module.exports = factories.createCoreController(
...
@@ -78,9 +73,33 @@ module.exports = factories.createCoreController(
// Wrapping a core action (leaves core logic in place)
// Wrapping a core action (leaves core logic in place)
async
create
(
ctx
)
{
async
create
(
ctx
)
{
console
.
log
(
"ctx.request.body"
,
ctx
.
request
.
body
);
try
{
const
spretoLeadData
=
await
strapi
.
service
(
"api::lead.lead"
)
.
sendLeadToSperto
(
ctx
.
request
.
body
.
data
);
// console.log("spretoLeadData.data", spretoLeadData.data);
ctx
.
request
.
body
.
data
.
httpRequestHeaders
=
JSON
.
stringify
(
spretoLeadData
.
headers
);
ctx
.
request
.
body
.
data
.
httpRequestMethod
=
spretoLeadData
.
config
.
method
;
ctx
.
request
.
body
.
data
.
httpRequestUrl
=
spretoLeadData
.
config
.
url
;
ctx
.
request
.
body
.
data
.
httpsRequestBody
=
spretoLeadData
.
config
.
data
;
ctx
.
request
.
body
.
data
.
httpResposneBody
=
JSON
.
stringify
(
spretoLeadData
.
data
);
ctx
.
request
.
body
.
data
.
thirdPartyApiError
=
false
;
}
catch
(
error
)
{
ctx
.
request
.
body
.
data
.
httpRequestHeaders
=
JSON
.
stringify
(
error
.
config
.
headers
);
ctx
.
request
.
body
.
data
.
httpRequestMethod
=
error
.
config
.
method
;
ctx
.
request
.
body
.
data
.
httpRequestUrl
=
error
.
config
.
url
;
ctx
.
request
.
body
.
data
.
httpsRequestBody
=
error
.
config
.
data
;
ctx
.
request
.
body
.
data
.
httpResposneBody
=
JSON
.
stringify
(
error
.
message
);
ctx
.
request
.
body
.
data
.
thirdPartyApiError
=
true
;
}
const
currentUser
=
ctx
.
state
.
user
;
const
currentUser
=
ctx
.
state
.
user
;
// 2. check if the current user already has an existing business listing (existingEndUser) against their name.
// 2. check if the current user already has an existing business listing (existingEndUser) against their name.
const
existingEndUser
=
await
strapi
.
entityService
.
findMany
(
const
existingEndUser
=
await
strapi
.
entityService
.
findMany
(
"api::end-user.end-user"
,
"api::end-user.end-user"
,
...
...
src/api/end-user/services/end-user.js
View file @
1363974
...
@@ -12,7 +12,6 @@ module.exports = createCoreService(
...
@@ -12,7 +12,6 @@ module.exports = createCoreService(
"api::end-user.end-user"
,
"api::end-user.end-user"
,
({
strapi
:
Strapi
})
=>
({
({
strapi
:
Strapi
})
=>
({
async
sendOTPToSpreto
(
data
)
{
async
sendOTPToSpreto
(
data
)
{
console
.
log
(
data
);
const
headers
=
{
"Content-Type"
:
"application/json"
};
const
headers
=
{
"Content-Type"
:
"application/json"
};
const
otpDetails
=
{
const
otpDetails
=
{
api_key
:
process
.
env
.
SPERTO_API_KEY
,
api_key
:
process
.
env
.
SPERTO_API_KEY
,
...
@@ -34,7 +33,76 @@ module.exports = createCoreService(
...
@@ -34,7 +33,76 @@ module.exports = createCoreService(
otpDetails
,
otpDetails
,
{
headers
:
headers
}
{
headers
:
headers
}
);
);
return
spertoResponse
;
const
leadData
=
{
api_key
:
process
.
env
.
SPERTO_API_KEY
,
lead_category
:
"W"
,
campaign_key
:
process
.
env
.
CAMPAIGN_KEY
,
customer_name
:
data
.
fullName
,
mobile1_isd
:
""
,
mobile_no1
:
data
.
mobileNo
,
email_id1
:
data
.
email
,
otp_verified_yn
:
"N"
,
};
// console.log("lead data", leadData);
if
(
data
.
comments
)
{
leadData
.
comments
=
data
.
comments
;
}
if
(
data
?.
project
)
{
const
projectData
=
await
strapi
.
db
.
query
(
"api::project.project"
)
.
findOne
({
where
:
{
id
:
data
?.
project
,
},
});
leadData
.
project_name
=
projectData
.
projectName
;
}
const
spertoLeadResponse
=
await
axios
.
post
(
"https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php"
,
leadData
,
{
headers
:
headers
}
);
// console.log("spertoLeadResponse", spertoLeadResponse);
return
spertoLeadResponse
,
spertoResponse
;
// return ;
},
},
// ({ strapi: Strapi }) => ({async sendLeadToSperto(data) {
// console.log(data);
// const headers = { "Content-Type": "application/json" };
// const leadData = {
// api_key: process.env.SPERTO_API_KEY,
// lead_category: "W",
// campaign_key: process.env.CAMPAIGN_KEY,
// customer_name: data.fullName,
// mobile1_isd: "",
// mobile_no1: data.mobileNo,
// email_id1: data.email,
// otp_verified_yn: "N",
// };
// if (data.comments) {
// leadData.comments = data.comments;
// }
// if (data?.project) {
// const projectData = await strapi.db
// .query("api::project.project")
// .findOne({
// where: {
// id: data?.project,
// },
// });
// leadData.project_name = projectData.projectName;
// }
// const spertoResponse = await axios.post(
// "https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php",
// leadData,
// { headers: headers }
// );
// return spertoResponse;
// }})
})
})
);
);
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment