TASK22102: slice1 api contract helper + email/admin pilot
This commit is contained in:
@@ -5,6 +5,7 @@ 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 WORDKEY = process.env.HASHKEY;
|
||||
|
||||
@@ -40,10 +41,14 @@ export default async function ApiProxy(req, res) {
|
||||
|
||||
const flattenedResults = data.value.map(flattenWatchlistEntry);
|
||||
|
||||
res.status(200).json(flattenedResults);
|
||||
return respondSuccess(res, flattenedResults);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "MAILING_LIST_FETCH_FAILED",
|
||||
message: "Failed to fetch mailing list"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,13 +28,18 @@
|
||||
import { consoleLogger, redactSensitive } from "../../../actions/core/logger";
|
||||
import { isNonEmptyString, sanitizeString } from "../../../actions/core/guards";
|
||||
import { getPreferredLanguage } from "../../../actions/services/accountService";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var data = req.body;
|
||||
const emailAddress = sanitizeString(data?.emailAddress);
|
||||
|
||||
if (!isNonEmptyString(emailAddress)) {
|
||||
return res.status(400).json({ error: "emailAddress is required" });
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "EMAIL_ADDRESS_REQUIRED",
|
||||
message: "emailAddress is required"
|
||||
});
|
||||
}
|
||||
|
||||
data.emailAddress = emailAddress;
|
||||
@@ -71,11 +76,15 @@ export default async function ApiProxy(req, res) {
|
||||
})
|
||||
.then((response) => {
|
||||
//console.log("thisis the response", response);
|
||||
return res.status(200).json(data);
|
||||
return respondSuccess(res, data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
return res.status(400).json(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "EMAIL_NOTIFY_FAILED",
|
||||
message: "Failed to send notify email"
|
||||
});
|
||||
});
|
||||
//return res.status(200).json(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user