TASK22211: normalize hash and metadata endpoint contracts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import nextConnect from "next-connect";
|
||||
import { getSession } from "next-auth/react";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const ApiProxy = nextConnect();
|
||||
|
||||
@@ -8,7 +9,11 @@ ApiProxy.get(async (req, res) => {
|
||||
const session = await getSession({ req });
|
||||
|
||||
if (!session) {
|
||||
return res.status(401).json();
|
||||
return respondError(res, {
|
||||
status: 401,
|
||||
code: "UNAUTHENTICATED",
|
||||
message: "Authentication required"
|
||||
});
|
||||
}
|
||||
|
||||
const rawQueryPath = req.query.path;
|
||||
@@ -39,10 +44,14 @@ ApiProxy.get(async (req, res) => {
|
||||
!allowedPrefix.some((prefix) => queryPath.startsWith(prefix)) ||
|
||||
queryPath.includes("/api/endpoint/gethash_api")
|
||||
) {
|
||||
return res.status(400).json();
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH_PATH",
|
||||
message: "Invalid path for hash generation"
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json({ hash: hashAPIPath(rawQueryPath) });
|
||||
return respondSuccess(res, { hash: hashAPIPath(rawQueryPath) });
|
||||
});
|
||||
|
||||
export default ApiProxy;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
@@ -5,16 +7,32 @@ const WEBAPI_URL =
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var whichForm = req.query.whichForm;
|
||||
const whichForm = req.query.whichForm;
|
||||
|
||||
if (typeof whichForm !== "string" || whichForm.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "WHICH_FORM_REQUIRED",
|
||||
message: "whichForm is required"
|
||||
});
|
||||
}
|
||||
|
||||
// var queryUrl =
|
||||
// "EntityDefinitions(LogicalName='pinswg_" +
|
||||
// whichForm +
|
||||
// "')/Attributes?$count=true&$select=LogicalName,RequiredLevel";
|
||||
|
||||
const mandatoryFieldsData = require("../../../data/mandatoryfields/pinswg_" +
|
||||
whichForm +
|
||||
".json");
|
||||
try {
|
||||
const mandatoryFieldsData = require(
|
||||
"../../../data/mandatoryfields/pinswg_" + whichForm + ".json"
|
||||
);
|
||||
|
||||
return res.status(200).json(mandatoryFieldsData);
|
||||
return respondSuccess(res, mandatoryFieldsData);
|
||||
} catch (error) {
|
||||
return respondError(res, {
|
||||
status: 404,
|
||||
code: "MANDATORY_FIELDS_NOT_FOUND",
|
||||
message: "Mandatory fields data not found for requested form"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
* description: hello world
|
||||
*/
|
||||
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
@@ -24,16 +26,32 @@ const WEBAPI_URL =
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var whichForm = req.query.whichForm;
|
||||
const whichForm = req.query.whichForm;
|
||||
|
||||
if (typeof whichForm !== "string" || whichForm.trim().length === 0) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "WHICH_FORM_REQUIRED",
|
||||
message: "whichForm is required"
|
||||
});
|
||||
}
|
||||
|
||||
// var queryUrl =
|
||||
// "EntityDefinitions(LogicalName='pinswg_" +
|
||||
// whichForm +
|
||||
// "')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet&$count=true";
|
||||
|
||||
const pickListData = require("../../../data/picklistdata/pinswg_" +
|
||||
whichForm +
|
||||
".json");
|
||||
try {
|
||||
const pickListData = require(
|
||||
"../../../data/picklistdata/pinswg_" + whichForm + ".json"
|
||||
);
|
||||
|
||||
return res.status(200).json(pickListData);
|
||||
return respondSuccess(res, pickListData);
|
||||
} catch (error) {
|
||||
return respondError(res, {
|
||||
status: 404,
|
||||
code: "PICKLISTS_NOT_FOUND",
|
||||
message: "Picklist data not found for requested form"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user