lead.js
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
/**
* lead controller
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::lead.lead", () => ({
async sendLeads(ctx) {},
async create(ctx) {
try {
const spretoLeadData = await strapi
.service("api::lead.lead")
.sendLeadToSperto(ctx.request.body.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
);
} 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);
}
const leadData = await super.create(ctx);
return ctx.send({
leadData,
});
},
}));