TASK22211: standardize search-document endpoint contracts and phase21 coverage
This commit is contained in:
@@ -17,11 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
|
||||||
import { azureHeaders } from "../../../actions/core/headers";
|
import { azureHeaders } from "../../../actions/core/headers";
|
||||||
import { consoleLogger } from "../../../actions/core/logger";
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { getToken } from "../../../actions/core/token";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
process.env.RELAY_ROOT ||
|
process.env.RELAY_ROOT ||
|
||||||
@@ -57,37 +57,41 @@ const groupArray = (arr) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var incidentID = req.query.incidentid;
|
const incidentID = req.query.incidentid;
|
||||||
var token = await getToken();
|
|
||||||
|
|
||||||
var queryUrl =
|
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
||||||
"pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
return respondError(res, {
|
||||||
incidentID +
|
status: 400,
|
||||||
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null&$select=pinswg_isharedocumentlocations";
|
code: "INCIDENT_ID_REQUIRED",
|
||||||
|
message: "incidentid is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//console.log("docu: ", WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
try {
|
||||||
|
const token = await getToken();
|
||||||
|
|
||||||
return axios
|
const queryUrl =
|
||||||
.get(
|
"pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
||||||
|
incidentID +
|
||||||
|
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null&$select=pinswg_isharedocumentlocations";
|
||||||
|
|
||||||
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeaders(token.access_token)
|
azureHeaders(token.access_token)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
//delete data["pinswg_documentid"];
|
|
||||||
data.value.forEach(function (element) {
|
|
||||||
delete element["pinswg_documentid"];
|
|
||||||
});
|
|
||||||
|
|
||||||
var dataArr = groupArray(data.value);
|
data.value.forEach(function (element) {
|
||||||
|
delete element["pinswg_documentid"];
|
||||||
// var dataStr;
|
|
||||||
// _.has(data, "@odata.nextLink") == true &&
|
|
||||||
// ((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
|
||||||
// (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
|
||||||
res.status(200).json(dataArr);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
consoleLogger(error);
|
|
||||||
res.status(400).json(error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const dataArr = groupArray(data.value);
|
||||||
|
return respondSuccess(res, dataArr);
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "SEARCH_DOCUMENT_TYPES_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch search document types"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { azureHeadersPaged } from "../../../actions/core/headers";
|
|||||||
import { consoleLogger } from "../../../actions/core/logger";
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { getToken } from "../../../actions/core/token";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
@@ -44,41 +45,53 @@ const encryptDocReference = (documentRef) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var incidentID = req.query.incidentid;
|
const incidentID = req.query.incidentid;
|
||||||
var token = await getToken();
|
|
||||||
|
|
||||||
var queryUrl =
|
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
||||||
"pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
return respondError(res, {
|
||||||
incidentID +
|
status: 400,
|
||||||
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference,pinswg_name,pinswg_latestpublishedversion,pinswg_latestpublisheddate,pinswg_documentpublisheddate";
|
code: "INCIDENT_ID_REQUIRED",
|
||||||
|
message: "incidentid is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//console.log("docu: ", WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
try {
|
||||||
|
const token = await getToken();
|
||||||
|
|
||||||
return axios
|
const queryUrl =
|
||||||
.get(
|
"pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
||||||
|
incidentID +
|
||||||
|
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference,pinswg_name,pinswg_latestpublishedversion,pinswg_latestpublisheddate,pinswg_documentpublisheddate";
|
||||||
|
|
||||||
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeadersPaged(token.access_token)
|
azureHeadersPaged(token.access_token)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
data.value.forEach(function (element) {
|
data.value.forEach(function (element) {
|
||||||
Object.assign(element, {
|
Object.assign(element, {
|
||||||
"pinswg_documentpublisheddate":
|
"pinswg_documentpublisheddate":
|
||||||
element.pinswg_documentpublisheddate != null
|
element.pinswg_documentpublisheddate != null
|
||||||
? element.pinswg_documentpublisheddate
|
? element.pinswg_documentpublisheddate
|
||||||
: element.pinswg_latestpublisheddate
|
: element.pinswg_latestpublisheddate
|
||||||
});
|
|
||||||
element.pinswg_hashlink = encryptDocReference(
|
|
||||||
element.pinswg_isharedocumentreference
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
var dataStr;
|
element.pinswg_hashlink = encryptDocReference(
|
||||||
_.has(data, "@odata.nextLink") == true &&
|
element.pinswg_isharedocumentreference
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
);
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
|
||||||
res.status(200).json(data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
consoleLogger(error);
|
|
||||||
res.status(400).json(error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (_.has(data, "@odata.nextLink") === true) {
|
||||||
|
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
||||||
|
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return respondSuccess(res, data);
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "SEARCH_DOCUMENT_DETAILS_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch search document details"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import { azureHeadersPagedCustom } from "../../../actions/core/headers";
|
|||||||
import { consoleLogger } from "../../../actions/core/logger";
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { getToken } from "../../../actions/core/token";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
@@ -70,20 +71,53 @@ const encryptDocReference = (documentRef) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var pageNumber = req.query.pageNumber;
|
const pageNumber = req.query.pageNumber;
|
||||||
var incidentID = req.query.incidentid;
|
const incidentID = req.query.incidentid;
|
||||||
var token = await getToken();
|
const orderby = req.query.orderby;
|
||||||
|
const fieldSort = req.query.fieldSort;
|
||||||
|
const showNumberOfRecords = req.query.showNumberOfRecords;
|
||||||
|
const documentType = req.query.documentType || "all";
|
||||||
|
|
||||||
var orderby = req.query.orderby;
|
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
||||||
var fieldSort = req.query.fieldSort;
|
return respondError(res, {
|
||||||
var showNumberOfRecords = req.query.showNumberOfRecords;
|
status: 400,
|
||||||
var documentType = req.query.documentType || "all";
|
code: "INCIDENT_ID_REQUIRED",
|
||||||
|
message: "incidentid is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof orderby !== "string" || orderby.trim().length === 0) {
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "ORDER_BY_REQUIRED",
|
||||||
|
message: "orderby is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof fieldSort !== "string" || fieldSort.trim().length === 0) {
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "FIELD_SORT_REQUIRED",
|
||||||
|
message: "fieldSort is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof showNumberOfRecords !== "string" ||
|
||||||
|
showNumberOfRecords.trim().length === 0
|
||||||
|
) {
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "SHOW_NUMBER_OF_RECORDS_REQUIRED",
|
||||||
|
message: "showNumberOfRecords is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// (documentType != "all"
|
// (documentType != "all"
|
||||||
// ? documentType.indexOf(",")<0?" and pinswg_isharedocumentlocations eq " + documentType :
|
// ? documentType.indexOf(",")<0?" and pinswg_isharedocumentlocations eq " + documentType :
|
||||||
// : "") +
|
// : "") +
|
||||||
|
|
||||||
var docTypeQueryString = "";
|
let docTypeQueryString = "";
|
||||||
|
|
||||||
if (documentType != "all") {
|
if (documentType != "all") {
|
||||||
if (documentType.indexOf(",") >= 0) {
|
if (documentType.indexOf(",") >= 0) {
|
||||||
@@ -91,8 +125,6 @@ export default async function ApiProxy(req, res) {
|
|||||||
|
|
||||||
docTypeQueryString = " and (";
|
docTypeQueryString = " and (";
|
||||||
documentTypeArr.forEach(function (item, index) {
|
documentTypeArr.forEach(function (item, index) {
|
||||||
console.log(item, index);
|
|
||||||
|
|
||||||
if (item != "all") {
|
if (item != "all") {
|
||||||
docTypeQueryString +=
|
docTypeQueryString +=
|
||||||
" pinswg_isharedocumentlocations eq " + item;
|
" pinswg_isharedocumentlocations eq " + item;
|
||||||
@@ -118,47 +150,53 @@ export default async function ApiProxy(req, res) {
|
|||||||
//console.log("has this passed docuemntType:", documentType);
|
//console.log("has this passed docuemntType:", documentType);
|
||||||
//(documentType !="all" && " pinswg_pinswg_isharedocumentlocations eq " + )
|
//(documentType !="all" && " pinswg_pinswg_isharedocumentlocations eq " + )
|
||||||
|
|
||||||
var queryUrl =
|
try {
|
||||||
"pinswg_documents?$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
const token = await getToken();
|
||||||
incidentID +
|
|
||||||
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null" +
|
|
||||||
docTypeQueryString +
|
|
||||||
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference,pinswg_name,pinswg_latestpublishedversion,pinswg_latestpublisheddate,pinswg_documentpublisheddate&$orderby=" +
|
|
||||||
orderby +
|
|
||||||
" " +
|
|
||||||
fieldSort +
|
|
||||||
"&$count=true" +
|
|
||||||
(typeof pageNumber != "undefined"
|
|
||||||
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
|
|
||||||
: "");
|
|
||||||
|
|
||||||
console.log("docu paged 1: ", queryUrl);
|
const queryUrl =
|
||||||
|
"pinswg_documents?$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
||||||
|
incidentID +
|
||||||
|
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null" +
|
||||||
|
docTypeQueryString +
|
||||||
|
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference,pinswg_name,pinswg_latestpublishedversion,pinswg_latestpublisheddate,pinswg_documentpublisheddate&$orderby=" +
|
||||||
|
orderby +
|
||||||
|
" " +
|
||||||
|
fieldSort +
|
||||||
|
"&$count=true" +
|
||||||
|
(typeof pageNumber != "undefined"
|
||||||
|
? "&$skiptoken=" +
|
||||||
|
('<cookie pagenumber="' + pageNumber + '" />')
|
||||||
|
: "");
|
||||||
|
|
||||||
return axios
|
const { data } = await axios.get(
|
||||||
.get(
|
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
data.value.forEach(function (element) {
|
data.value.forEach(function (element) {
|
||||||
Object.assign(element, {
|
Object.assign(element, {
|
||||||
"pinswg_documentpublisheddate":
|
"pinswg_documentpublisheddate":
|
||||||
element.pinswg_documentpublisheddate != null
|
element.pinswg_documentpublisheddate != null
|
||||||
? element.pinswg_documentpublisheddate
|
? element.pinswg_documentpublisheddate
|
||||||
: element.pinswg_latestpublisheddate
|
: element.pinswg_latestpublisheddate
|
||||||
});
|
|
||||||
element.pinswg_hashlink = encryptDocReference(
|
|
||||||
element.pinswg_isharedocumentreference
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
var dataStr;
|
element.pinswg_hashlink = encryptDocReference(
|
||||||
_.has(data, "@odata.nextLink") == true &&
|
element.pinswg_isharedocumentreference
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
);
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
|
||||||
return res.status(200).json(data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
consoleLogger(error);
|
|
||||||
res.status(400).json(error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (_.has(data, "@odata.nextLink") === true) {
|
||||||
|
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
||||||
|
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return respondSuccess(res, data);
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "SEARCH_DOCUMENT_DETAILS_PAGED_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch paged search document details"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,34 +17,45 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
|
||||||
import { azureHeadersPaged } from "../../../actions/core/headers";
|
import { azureHeadersPaged } from "../../../actions/core/headers";
|
||||||
import { consoleLogger } from "../../../actions/core/logger";
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { getToken } from "../../../actions/core/token";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
process.env.RELAY_ROOT ||
|
process.env.RELAY_ROOT ||
|
||||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var documentID = req.query.documentid;
|
const documentID = req.query.documentid;
|
||||||
var token = await getToken();
|
|
||||||
|
|
||||||
var queryUrl =
|
if (typeof documentID !== "string" || documentID.trim().length === 0) {
|
||||||
"pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
return respondError(res, {
|
||||||
documentID;
|
status: 400,
|
||||||
|
code: "DOCUMENT_ID_REQUIRED",
|
||||||
|
message: "documentid is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return axios
|
try {
|
||||||
.get(
|
const token = await getToken();
|
||||||
|
const queryUrl =
|
||||||
|
"pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
||||||
|
documentID;
|
||||||
|
|
||||||
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeadersPaged(token.access_token)
|
azureHeadersPaged(token.access_token)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
res.status(200).json(data);
|
return respondSuccess(res, data);
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
consoleLogger(error);
|
||||||
consoleLogger(error);
|
return respondError(res, {
|
||||||
res.status(400).json(error);
|
status: 400,
|
||||||
|
code: "SEARCH_DOCUMENT_HISTORY_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch search document history"
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,39 +43,50 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
|
||||||
import { azureHeadersPaged } from "../../../actions/core/headers";
|
import { azureHeadersPaged } from "../../../actions/core/headers";
|
||||||
import { consoleLogger } from "../../../actions/core/logger";
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { getToken } from "../../../actions/core/token";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
process.env.RELAY_ROOT ||
|
process.env.RELAY_ROOT ||
|
||||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var documentID = req.query.documentid;
|
const documentID = req.query.documentid;
|
||||||
var pageNumber = req.query.pageNumber;
|
|
||||||
var token = await getToken();
|
|
||||||
|
|
||||||
var queryUrl =
|
if (typeof documentID !== "string" || documentID.trim().length === 0) {
|
||||||
"pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
return respondError(res, {
|
||||||
documentID;
|
status: 400,
|
||||||
// +
|
code: "DOCUMENT_ID_REQUIRED",
|
||||||
// (typeof pageNumber != "undefined"
|
message: "documentid is required"
|
||||||
// ? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
|
});
|
||||||
// : "");
|
}
|
||||||
|
|
||||||
return axios
|
try {
|
||||||
.get(
|
const token = await getToken();
|
||||||
|
|
||||||
|
const queryUrl =
|
||||||
|
"pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
||||||
|
documentID;
|
||||||
|
// +
|
||||||
|
// (typeof pageNumber != "undefined"
|
||||||
|
// ? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
|
||||||
|
// : "");
|
||||||
|
|
||||||
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeadersPaged(token.access_token)
|
azureHeadersPaged(token.access_token)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
res.status(200).json(data);
|
return respondSuccess(res, data);
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
consoleLogger(error);
|
||||||
consoleLogger(error);
|
return respondError(res, {
|
||||||
res.status(400).json(error);
|
status: 400,
|
||||||
|
code: "SEARCH_DOCUMENT_HISTORY_PAGED_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch paged search document history"
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -971,6 +971,368 @@ test("getadvancedsearch catch path returns ADVANCED_SEARCH_FETCH_FAILED", async
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumenthistory returns DOCUMENT_ID_REQUIRED when documentid missing", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumenthistory_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: { get: async () => ({ data: { value: [] } }) },
|
||||||
|
consoleLogger: () => {}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: {} };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(res.state.jsonBody.error.code, "DOCUMENT_ID_REQUIRED");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumenthistory catch path returns SEARCH_DOCUMENT_HISTORY_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumenthistory_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("relay failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: { documentid: "d1" } };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"SEARCH_DOCUMENT_HISTORY_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumenthistory success returns existing data payload contract", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumenthistory_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => ({
|
||||||
|
data: { value: [{ _pinswg_documentid_value: "d1" }] }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
consoleLogger: () => {}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: { documentid: "d1" } };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 200);
|
||||||
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
||||||
|
value: [{ _pinswg_documentid_value: "d1" }]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumenthistorypaged returns DOCUMENT_ID_REQUIRED when documentid missing", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumenthistorypaged_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: { get: async () => ({ data: { value: [] } }) },
|
||||||
|
consoleLogger: () => {}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: {} };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(res.state.jsonBody.error.code, "DOCUMENT_ID_REQUIRED");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumenthistorypaged catch path returns SEARCH_DOCUMENT_HISTORY_PAGED_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumenthistorypaged_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("relay failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: { documentid: "d1" } };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"SEARCH_DOCUMENT_HISTORY_PAGED_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentdetails returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumentdetails_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: { get: async () => ({ data: { value: [] } }) },
|
||||||
|
consoleLogger: () => {},
|
||||||
|
CryptoJS: {
|
||||||
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
||||||
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
||||||
|
},
|
||||||
|
_: { has: () => false }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: {} };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(res.state.jsonBody.error.code, "INCIDENT_ID_REQUIRED");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentdetails catch path returns SEARCH_DOCUMENT_DETAILS_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumentdetails_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("relay failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {},
|
||||||
|
CryptoJS: {
|
||||||
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
||||||
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
||||||
|
},
|
||||||
|
_: { has: () => false }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = { query: { incidentid: "i1" } };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"SEARCH_DOCUMENT_DETAILS_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentdetailspaged returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumentdetailspaged_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPagedCustom: () => ({}),
|
||||||
|
axios: { get: async () => ({ data: { value: [] } }) },
|
||||||
|
consoleLogger: () => {},
|
||||||
|
CryptoJS: {
|
||||||
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
||||||
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
||||||
|
},
|
||||||
|
_: { has: () => false }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
query: {
|
||||||
|
orderby: "createdon",
|
||||||
|
fieldSort: "asc",
|
||||||
|
showNumberOfRecords: "10"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(res.state.jsonBody.error.code, "INCIDENT_ID_REQUIRED");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentdetailspaged catch path returns SEARCH_DOCUMENT_DETAILS_PAGED_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule(
|
||||||
|
"pages/api/endpoint/getsearchdocumentdetailspaged_api.js",
|
||||||
|
{
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPagedCustom: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("relay failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {},
|
||||||
|
CryptoJS: {
|
||||||
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
||||||
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
||||||
|
},
|
||||||
|
_: { has: () => false }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
query: {
|
||||||
|
incidentid: "i1",
|
||||||
|
orderby: "createdon",
|
||||||
|
fieldSort: "asc",
|
||||||
|
showNumberOfRecords: "10"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"SEARCH_DOCUMENT_DETAILS_PAGED_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentTypes returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
||||||
|
const mod = loadModule("pages/api/endpoint/getsearchdocumentTypes_api.js", {
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeaders: () => ({}),
|
||||||
|
axios: { get: async () => ({ data: { value: [] } }) },
|
||||||
|
consoleLogger: () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { query: {} };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(res.state.jsonBody.error.code, "INCIDENT_ID_REQUIRED");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentTypes catch path returns SEARCH_DOCUMENT_TYPES_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule("pages/api/endpoint/getsearchdocumentTypes_api.js", {
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeaders: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("relay failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { query: { incidentid: "i1" } };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"SEARCH_DOCUMENT_TYPES_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getsearchdocumentTypes success returns grouped data payload contract", async () => {
|
||||||
|
const mod = loadModule("pages/api/endpoint/getsearchdocumentTypes_api.js", {
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeaders: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => ({
|
||||||
|
data: {
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
pinswg_isharedocumentlocations: 1,
|
||||||
|
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue":
|
||||||
|
"Plans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pinswg_isharedocumentlocations: 1,
|
||||||
|
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue":
|
||||||
|
"Plans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pinswg_isharedocumentlocations: 2,
|
||||||
|
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue":
|
||||||
|
"Letters"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
consoleLogger: () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { query: { incidentid: "i1" } };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 200);
|
||||||
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), [
|
||||||
|
{
|
||||||
|
pinswg_isharedocumentlocations: 1,
|
||||||
|
pinswg_isharedocumentlocationsLabel: "Plans",
|
||||||
|
count: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pinswg_isharedocumentlocations: 2,
|
||||||
|
pinswg_isharedocumentlocationsLabel: "Letters",
|
||||||
|
count: 1
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
let passed = 0;
|
let passed = 0;
|
||||||
for (const currentTest of tests) {
|
for (const currentTest of tests) {
|
||||||
|
|||||||
Reference in New Issue
Block a user