61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
/**
|
|
* @swagger
|
|
* /api/endpoint/getemailaccountcheck_api:
|
|
* get:
|
|
* tags: [Login]
|
|
* description: Returns portal login
|
|
* summary: Phase 2
|
|
* parameters:
|
|
* - name: emailAddress
|
|
* in: query
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* responses:
|
|
* 200:
|
|
* description: hello world
|
|
*/
|
|
import axios from "axios";
|
|
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) {
|
|
const emailAddress = req.query.emailAddress;
|
|
|
|
if (typeof emailAddress !== "string" || emailAddress.trim().length === 0) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "EMAIL_ADDRESS_REQUIRED",
|
|
message: "emailAddress is required"
|
|
});
|
|
}
|
|
|
|
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 respondSuccess(res, data);
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "EMAIL_ACCOUNT_CHECK_FAILED",
|
|
message: "Failed to check email account"
|
|
});
|
|
}
|
|
}
|