channel-partner.js
3.98 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"use strict";
/**
* channel-partner controller
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController(
"api::channel-partner.channel-partner",
({ strapi: Strapi }) => ({
async create(ctx) {
console.log(ctx);
// const currentChannelPartner = ctx.state.user;
const reraNumber = ctx.request.body?.data?.reraNumber;
console.log(reraNumber);
if (!reraNumber) {
return ctx.bad(`Please specify your rera number.`);
}
// 1. check if the channel partner already exist
const existingChannelPartner = await strapi.entityService.findMany(
"api::channel-partner.channel-partner",
{
filters: { reraNumber: reraNumber },
}
);
if (existingChannelPartner && existingChannelPartner.length !== 0) {
return ctx.badRequest(
`Channel Partner Already Exist with the Given rera number ${reraNumber}`
);
}
try {
const spertoRegisterCP = await strapi
.service("api::channel-partner.channel-partner")
.sendCPToSperto(ctx.request.body.data);
console.log("Helllo >>>>>>>>", spertoRegisterCP);
ctx.request.body.data.httpRegisterCPRequestHeaders = JSON.stringify(
spertoRegisterCP.headers
);
ctx.request.body.data.httpRegisterCPRequestMethod =
spertoRegisterCP.config.method;
ctx.request.body.data.httpRegisterCPRequestUrl =
spertoRegisterCP.config.url;
ctx.request.body.data.httpsRegisterCPRequestBody =
spertoRegisterCP.config.data;
ctx.request.body.data.httpRegisterCPResposneBody = JSON.stringify(
spertoRegisterCP.data
);
ctx.request.body.data.thirdPartyApiRegisterCPError = false;
} catch (error) {
ctx.request.body.data.httpRegisterCPRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.data.httpRegisterCPRequestMethod = error.config.method;
ctx.request.body.data.httpRegisterCPRequestUrl = error.config.url;
ctx.request.body.data.httpsRegisterCPRequestBody = error.config.data;
ctx.request.body.data.httpRegisterCPResposneBody = JSON.stringify(error.message);
ctx.request.body.data.thirdPartyApiRegisterCPError=true;
}
// try {
// const spertoCPOtp = await strapi.service
// .service("api::channel-partner.channel-partner")
// .getCPDataFromSperto(ctx.request.body.data);
// } catch (error) {
// }
// try {
// const spertoCPData = await strapi
// .service("api::channel-partner.channel-partner")
// .getCPDataFromSperto(ctx.request.body.data);
// ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
// spertoCPData.headers
// );
// ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = spertoCPData.config.method;
// ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = spertoCPData.config.url;
// ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = spertoCPData.config.data;
// ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify(
// spertoCPData.data
// );
// ctx.request.body.data.thirdThirdPartyOTPApiPartyApiError=false;
// } catch (error) {
// ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
// error.config.headers
// );
// ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = error.config.method;
// ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = error.config.url;
// ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = error.config.data;
// ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify(error.message);
// ctx.request.body.data.thirdThirdPartyOTPApiPartyApiError=true;
// }
return await super.create(ctx);
},
})
);