TASK22211: standardize search-document endpoint contracts and phase21 coverage
This commit is contained in:
@@ -17,11 +17,11 @@
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
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 ||
|
||||
@@ -57,37 +57,41 @@ const groupArray = (arr) => {
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var incidentID = req.query.incidentid;
|
||||
var token = await getToken();
|
||||
const incidentID = req.query.incidentid;
|
||||
|
||||
var queryUrl =
|
||||
"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";
|
||||
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INCIDENT_ID_REQUIRED",
|
||||
message: "incidentid is required"
|
||||
});
|
||||
}
|
||||
|
||||
//console.log("docu: ", WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
try {
|
||||
const token = await getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
const queryUrl =
|
||||
"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),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
//delete data["pinswg_documentid"];
|
||||
data.value.forEach(function (element) {
|
||||
delete element["pinswg_documentid"];
|
||||
});
|
||||
);
|
||||
|
||||
var dataArr = groupArray(data.value);
|
||||
|
||||
// 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);
|
||||
data.value.forEach(function (element) {
|
||||
delete element["pinswg_documentid"];
|
||||
});
|
||||
|
||||
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 { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
@@ -44,41 +45,53 @@ const encryptDocReference = (documentRef) => {
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var incidentID = req.query.incidentid;
|
||||
var token = await getToken();
|
||||
const incidentID = req.query.incidentid;
|
||||
|
||||
var queryUrl =
|
||||
"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";
|
||||
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INCIDENT_ID_REQUIRED",
|
||||
message: "incidentid is required"
|
||||
});
|
||||
}
|
||||
|
||||
//console.log("docu: ", WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
try {
|
||||
const token = await getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
const queryUrl =
|
||||
"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),
|
||||
azureHeadersPaged(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
data.value.forEach(function (element) {
|
||||
Object.assign(element, {
|
||||
"pinswg_documentpublisheddate":
|
||||
element.pinswg_documentpublisheddate != null
|
||||
? element.pinswg_documentpublisheddate
|
||||
: element.pinswg_latestpublisheddate
|
||||
});
|
||||
element.pinswg_hashlink = encryptDocReference(
|
||||
element.pinswg_isharedocumentreference
|
||||
);
|
||||
);
|
||||
|
||||
data.value.forEach(function (element) {
|
||||
Object.assign(element, {
|
||||
"pinswg_documentpublisheddate":
|
||||
element.pinswg_documentpublisheddate != null
|
||||
? element.pinswg_documentpublisheddate
|
||||
: element.pinswg_latestpublisheddate
|
||||
});
|
||||
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(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
element.pinswg_hashlink = encryptDocReference(
|
||||
element.pinswg_isharedocumentreference
|
||||
);
|
||||
});
|
||||
|
||||
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 { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
@@ -70,20 +71,53 @@ const encryptDocReference = (documentRef) => {
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var pageNumber = req.query.pageNumber;
|
||||
var incidentID = req.query.incidentid;
|
||||
var token = await getToken();
|
||||
const pageNumber = req.query.pageNumber;
|
||||
const incidentID = req.query.incidentid;
|
||||
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;
|
||||
var fieldSort = req.query.fieldSort;
|
||||
var showNumberOfRecords = req.query.showNumberOfRecords;
|
||||
var documentType = req.query.documentType || "all";
|
||||
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
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.indexOf(",")<0?" and pinswg_isharedocumentlocations eq " + documentType :
|
||||
// : "") +
|
||||
|
||||
var docTypeQueryString = "";
|
||||
let docTypeQueryString = "";
|
||||
|
||||
if (documentType != "all") {
|
||||
if (documentType.indexOf(",") >= 0) {
|
||||
@@ -91,8 +125,6 @@ export default async function ApiProxy(req, res) {
|
||||
|
||||
docTypeQueryString = " and (";
|
||||
documentTypeArr.forEach(function (item, index) {
|
||||
console.log(item, index);
|
||||
|
||||
if (item != "all") {
|
||||
docTypeQueryString +=
|
||||
" pinswg_isharedocumentlocations eq " + item;
|
||||
@@ -118,47 +150,53 @@ export default async function ApiProxy(req, res) {
|
||||
//console.log("has this passed docuemntType:", documentType);
|
||||
//(documentType !="all" && " pinswg_pinswg_isharedocumentlocations eq " + )
|
||||
|
||||
var 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 + '" />')
|
||||
: "");
|
||||
try {
|
||||
const token = await getToken();
|
||||
|
||||
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
|
||||
.get(
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
data.value.forEach(function (element) {
|
||||
Object.assign(element, {
|
||||
"pinswg_documentpublisheddate":
|
||||
element.pinswg_documentpublisheddate != null
|
||||
? element.pinswg_documentpublisheddate
|
||||
: element.pinswg_latestpublisheddate
|
||||
});
|
||||
element.pinswg_hashlink = encryptDocReference(
|
||||
element.pinswg_isharedocumentreference
|
||||
);
|
||||
);
|
||||
|
||||
data.value.forEach(function (element) {
|
||||
Object.assign(element, {
|
||||
"pinswg_documentpublisheddate":
|
||||
element.pinswg_documentpublisheddate != null
|
||||
? element.pinswg_documentpublisheddate
|
||||
: element.pinswg_latestpublisheddate
|
||||
});
|
||||
var dataStr;
|
||||
_.has(data, "@odata.nextLink") == true &&
|
||||
((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);
|
||||
element.pinswg_hashlink = encryptDocReference(
|
||||
element.pinswg_isharedocumentreference
|
||||
);
|
||||
});
|
||||
|
||||
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 CryptoJS from "crypto-js";
|
||||
import { azureHeadersPaged } 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 documentID = req.query.documentid;
|
||||
var token = await getToken();
|
||||
const documentID = req.query.documentid;
|
||||
|
||||
var queryUrl =
|
||||
"pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
||||
documentID;
|
||||
if (typeof documentID !== "string" || documentID.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "DOCUMENT_ID_REQUIRED",
|
||||
message: "documentid is required"
|
||||
});
|
||||
}
|
||||
|
||||
return axios
|
||||
.get(
|
||||
try {
|
||||
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),
|
||||
azureHeadersPaged(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
);
|
||||
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "SEARCH_DOCUMENT_HISTORY_FETCH_FAILED",
|
||||
message: "Failed to fetch search document history"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,39 +43,50 @@
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { azureHeadersPaged } 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 documentID = req.query.documentid;
|
||||
var pageNumber = req.query.pageNumber;
|
||||
var token = await getToken();
|
||||
const documentID = req.query.documentid;
|
||||
|
||||
var 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 + '" />')
|
||||
// : "");
|
||||
if (typeof documentID !== "string" || documentID.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "DOCUMENT_ID_REQUIRED",
|
||||
message: "documentid is required"
|
||||
});
|
||||
}
|
||||
|
||||
return axios
|
||||
.get(
|
||||
try {
|
||||
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),
|
||||
azureHeadersPaged(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
);
|
||||
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "SEARCH_DOCUMENT_HISTORY_PAGED_FETCH_FAILED",
|
||||
message: "Failed to fetch paged search document history"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user