TASK22168 endpoint account contract consistency slice
This commit is contained in:
@@ -16,49 +16,45 @@
|
||||
* description: hello world
|
||||
*/
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { azureHeaders } from "../../../actions/core/headers";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var emailAddress = req.query.emailAddress;
|
||||
const emailAddress = req.query.emailAddress;
|
||||
|
||||
if (typeof emailAddress === "undefined" || emailAddress.length === 0) {
|
||||
return res.status(400).json();
|
||||
if (typeof emailAddress !== "string" || emailAddress.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "EMAIL_ADDRESS_REQUIRED",
|
||||
message: "emailAddress is required"
|
||||
});
|
||||
}
|
||||
|
||||
var token = await getToken();
|
||||
try {
|
||||
const token = await getToken();
|
||||
const queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
emailAddress +
|
||||
"'&$count=true&$select=emailaddress1, contactid";
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
);
|
||||
|
||||
var queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
emailAddress +
|
||||
"'&$count=true&$select=emailaddress1, contactid";
|
||||
|
||||
// var queryUrl = "contacts/?$count=true&$select=emailaddress1, contactid";
|
||||
|
||||
var apiResponse = _.isEmpty(req.query)
|
||||
? res.status(400).json()
|
||||
: typeof emailAddress != "undefined" && emailAddress.length > 0
|
||||
? axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
})
|
||||
: res.status(400).json();
|
||||
|
||||
return apiResponse;
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "ACCOUNTS_FETCH_FAILED",
|
||||
message: "Failed to fetch accounts"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,42 +16,45 @@
|
||||
* description: hello world
|
||||
*/
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { azureHeaders } from "../../../actions/core/headers";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var emailAddress = req.query.emailAddress;
|
||||
var token = await getToken();
|
||||
const emailAddress = req.query.emailAddress;
|
||||
|
||||
var queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
emailAddress +
|
||||
"'&$count=true&$select=emailaddress1, contactid";
|
||||
if (typeof emailAddress !== "string" || emailAddress.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "EMAIL_ADDRESS_REQUIRED",
|
||||
message: "emailAddress is required"
|
||||
});
|
||||
}
|
||||
|
||||
var apiResponse = _.isEmpty(req.query)
|
||||
? res.status(400).json()
|
||||
: typeof emailAddress != "undefined" && emailAddress.length > 0
|
||||
? axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
})
|
||||
: res.status(400).json();
|
||||
try {
|
||||
const token = await getToken();
|
||||
const queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
emailAddress +
|
||||
"'&$count=true&$select=emailaddress1, contactid";
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
);
|
||||
|
||||
return apiResponse;
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "EMAIL_ACCOUNT_CHECK_FAILED",
|
||||
message: "Failed to check email account"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,54 +16,51 @@
|
||||
* description: hello world
|
||||
*/
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { azureHeaders } from "../../../actions/core/headers";
|
||||
import {
|
||||
escapeODataString,
|
||||
isNonEmptyString,
|
||||
sanitizeString
|
||||
} from "../../../actions/core/guards";
|
||||
import { consoleLogger, redactSensitive } from "../../../actions/core/logger";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var emailAddress = sanitizeString(req.query.emailAddress);
|
||||
var token = await getToken();
|
||||
const emailAddress = sanitizeString(req.query.emailAddress);
|
||||
|
||||
if (!isNonEmptyString(emailAddress)) {
|
||||
return res.status(400).json({ error: "emailAddress is required" });
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "EMAIL_ADDRESS_REQUIRED",
|
||||
message: "emailAddress is required"
|
||||
});
|
||||
}
|
||||
|
||||
var queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
escapeODataString(emailAddress) +
|
||||
"'&$count=true&$select=pinswg_preferredlanguage,contactid";
|
||||
try {
|
||||
const token = await getToken();
|
||||
const queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
escapeODataString(emailAddress) +
|
||||
"'&$count=true&$select=pinswg_preferredlanguage,contactid";
|
||||
|
||||
console.log(redactSensitive(queryUrl));
|
||||
// var queryUrl = "contacts/?$count=true&$select=emailaddress1, contactid";
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
);
|
||||
|
||||
var apiResponse = _.isEmpty(req.query)
|
||||
? res.status(400).json()
|
||||
: typeof emailAddress != "undefined" && emailAddress.length > 0
|
||||
? axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
})
|
||||
: res.status(400).json();
|
||||
|
||||
return apiResponse;
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "PREFERRED_LANGUAGE_FETCH_FAILED",
|
||||
message: "Failed to fetch preferred language"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user