63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
/**
|
|
* @swagger
|
|
* /api/endpoint/getpersonalaccount_api:
|
|
* get:
|
|
* tags: [Account]
|
|
* description: Get personal account
|
|
* summary: Phase 2
|
|
* parameters:
|
|
* - name: contactid
|
|
* in: query
|
|
* required: true
|
|
* example: 726158c6-708d-ec11-aad8-00224800be9c
|
|
* 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 contactid = req.query.contactid;
|
|
|
|
if (typeof contactid !== "string" || contactid.trim().length === 0) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "CONTACT_ID_REQUIRED",
|
|
message: "contactid is required"
|
|
});
|
|
}
|
|
|
|
try {
|
|
const token = await getToken();
|
|
const queryUrl =
|
|
"contacts(" +
|
|
contactid +
|
|
")?$select=firstname, lastname, emailaddress1, telephone1, company, address1_line1,address1_line2,address1_city, address1_county,address1_postalcode,pinswg_typeofinvolvement,pinswg_contact_associatedlpa,pinswg_preferredlanguage&$count=true";
|
|
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: "PERSONAL_ACCOUNT_FETCH_FAILED",
|
|
message: "Failed to fetch personal account"
|
|
});
|
|
}
|
|
}
|