referral.js
2.19 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict";
/**
* referral controller
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::referral.referral", () => ({
async create(ctx) {
console.log("create started");
try {
const spertoRefereeData = await strapi
.service("api::referral.referral")
.sendReferee(ctx.request.body.data);
console.log("spertoRefereeData", spertoRefereeData.data.member_id);
const spertoReferralData = await strapi.service("api::referral.referral").sendReferral({...ctx.request.body.data, parent_id: spertoRefereeData.data.member_id})
ctx.request.body.data.httpRequestHeaders = JSON.stringify(
spertoRefereeData.headers
);
ctx.request.body.data.httpReferralRequestHeaders = JSON.stringify(
spertoReferralData.headers
);
ctx.request.body.data.httpRequestMethod = spertoRefereeData.config.method;
ctx.request.body.data.httpReferralRequestMethod = spertoReferralData.config.method;
ctx.request.body.data.httpReferralRequestUrl = spertoReferralData.config.url;
ctx.request.body.data.httpRequestUrl = spertoRefereeData.config.url;
ctx.request.body.data.httpsReferralRequestBody = spertoReferralData.config.data;
ctx.request.body.data.httpsRequestBody = spertoRefereeData.config.data;
ctx.request.body.data.httpResposneBody = JSON.stringify(
spertoRefereeData.data
);
ctx.request.body.data.httpReferralResposneBody = JSON.stringify(
spertoReferralData.data
);
ctx.request.body.data.thirdPartyApiError = false;
} catch (error) {
console.log("error", 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 referralData = await super.create(ctx);
return ctx.send({
referralData,
});
},
}));