Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 1x 3x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 32x 1x 1x 1x 1x 1x 1x | import { APIGatewayEvent } from "aws-lambda";
import { response } from "libs/handler-lib";
import { getDomainAndNamespace } from "libs/utils";
import { BaseIndex } from "shared-types/opensearch";
import { ONEMAC_LEGACY_ORIGIN } from "shared-types/opensearch/main/transforms/legacy-transforms";
import { validateEnvVariable } from "shared-utils";
import { getStateFilter } from "../libs/api/auth/user";
import { getAppkChildren } from "../libs/api/package";
import { search } from "../libs/opensearch-lib";
import { handleOpensearchError } from "./utils";
// Handler function to search index
export const getSearchData = async (event: APIGatewayEvent) => {
validateEnvVariable("osDomain");
if (!event.pathParameters || !event.pathParameters.index) {
console.error(
"event.pathParameters.index path parameter required, Event: ",
JSON.stringify(event, null, 2),
);
return response({
statusCode: 400,
body: { message: "Index path parameter required" },
});
}
const { domain, index } = getDomainAndNamespace(event.pathParameters.index as BaseIndex);
try {
let query: any = {};
Eif (event.body) {
query = JSON.parse(event.body);
}
query.query = query?.query || {};
query.query.bool = query.query?.bool || {};
query.query.bool.must = query.query.bool?.must || [];
query.query.bool.must_not = query.query.bool?.must_not || [];
query.query.bool.must_not.push({ term: { deleted: true } });
const stateFilter = await getStateFilter(event);
Eif (stateFilter) {
query.query.bool.must.push(stateFilter);
}
// Return OneMAC records and NOSOs (denoted with SEATool origin and only NOSO)
query.query.bool.must.push({
bool: {
should: [
{ terms: { "origin.keyword": ["OneMAC", ONEMAC_LEGACY_ORIGIN] } },
{
bool: {
must: [
{ term: { "origin.keyword": "SEATool" } },
{ term: { "event.keyword": "NOSO" } },
],
},
},
],
},
});
query.from = query.from || 0;
query.size = query.size || 100;
const results = await search(domain, index, query);
for (let i = 0; i < results?.hits?.hits?.length; i++) {
if (results.hits.hits[i]._source?.appkParent) {
const children = await getAppkChildren(results.hits.hits[i]._id);
Eif (children?.hits?.hits?.length > 0) {
results.hits.hits[i]._source.appkChildren = children.hits.hits;
}
}
}
return response<unknown>({
statusCode: 200,
body: results,
});
} catch (error) {
return response(handleOpensearchError(error));
}
};
export const handler = getSearchData;
|