Skip to content

Commit

Permalink
feat(add-onemac-tombstone): Allow onemac records to be deleted from o…
Browse files Browse the repository at this point in the history
…pensearch

* Checking in.... error free in vs code but lambda having an issue...

* Fix null RAI issue

* correct some logic.  working now

* added the breaks

* add lead analyst... but its all null

* update table lists

* Add text helpers

* Item details UI buildout (#67)

* Stuff

* Add details pages

* update chip-spa page

* update chip-spa page

* update chip-spa page

* pushing pixels around

* pushing pixels around

* cleanup

* add test

* come up with a typesafe way to validate

* remove file

* validate against data and rewrite code

* add rai recieved date

* dry run validation seatool sink lambda

* change validation logic to account for null values

* add test data so ci test passes

* add onemac schema

* ship it

* add error messages

* thank you Mike

* add opensearch type

* refactor and fix seatool

* add to barrel file

* add logs

* fix type error

* don't include certain seatool records

* move id to after if check

* attempt to get better logging

* add more logging

* Handle onemac bad validation

* fixes (yet untested) for the seatool sink errors

* add received gat helper

* update

* update

* Update

* update

* update

* update

* update types

* refactor

* maybe this will work

* nullify

* add logging

* fix error

* set to undefined instead of null

* do fun things

* rename to seatoolrecordstodelete

* add onemac tombstone functionality

* fix decode error

---------

Co-authored-by: Mike Dial <[email protected]>
Co-authored-by: 13bfrancis <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2023
1 parent 9282170 commit 646d0ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/packages/shared-types/onemac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ export const transformOnemac = (id: string) => {

export type OneMacSink = z.infer<typeof onemacSchema>;
export type OneMacTransform = z.infer<ReturnType<typeof transformOnemac>>;
export type OneMacRecordsToDelete = Omit<
{
[Property in keyof OneMacTransform]: undefined;
},
"id"
> & { id: string };
2 changes: 1 addition & 1 deletion src/packages/shared-types/seatool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const transformSeatoolData = (id: string) => {

export type SeaToolTransform = z.infer<ReturnType<typeof transformSeatoolData>>;
export type SeaToolSink = z.infer<typeof seatoolSchema>;
export type RecordsToDelete = Omit<
export type SeaToolRecordsToDelete = Omit<
{
[Property in keyof SeaToolTransform]: undefined;
},
Expand Down
35 changes: 28 additions & 7 deletions src/services/data/handlers/sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ import { Handler } from "aws-lambda";
import { decode } from "base-64";
import * as os from "./../../../libs/opensearch-lib";
import {
RecordsToDelete,
SeaToolRecordsToDelete,
SeaToolTransform,
transformSeatoolData,
} from "shared-types/seatool";
import { OneMacTransform, transformOnemac } from "shared-types/onemac";
import {
OneMacRecordsToDelete,
OneMacTransform,
transformOnemac,
} from "shared-types/onemac";

if (!process.env.osDomain) {
throw "ERROR: process.env.osDomain is required,";
}
const osDomain: string = process.env.osDomain;

export const seatool: Handler = async (event) => {
const seaToolRecords: (SeaToolTransform | RecordsToDelete)[] = [];
const docObject: Record<string, SeaToolTransform | RecordsToDelete> = {};
const seaToolRecords: (SeaToolTransform | SeaToolRecordsToDelete)[] = [];
const docObject: Record<string, SeaToolTransform | SeaToolRecordsToDelete> =
{};
const rawArr: any[] = [];

for (const recordKey of Object.keys(event.records)) {
Expand Down Expand Up @@ -48,7 +53,7 @@ export const seatool: Handler = async (event) => {
}
} else {
const id: string = JSON.parse(decode(key));
const seaTombstone: RecordsToDelete = {
const seaTombstone: SeaToolRecordsToDelete = {
id,
actionType: undefined,
actionTypeId: undefined,
Expand Down Expand Up @@ -86,8 +91,8 @@ export const seatool: Handler = async (event) => {
};

export const onemac: Handler = async (event) => {
const oneMacRecords: OneMacTransform[] = [];
const docObject: Record<string, OneMacTransform> = {};
const oneMacRecords: (OneMacTransform | OneMacRecordsToDelete)[] = [];
const docObject: Record<string, OneMacTransform | OneMacRecordsToDelete> = {};

for (const recordKey of Object.keys(event.records)) {
for (const onemacRecord of event.records[recordKey] as {
Expand All @@ -112,6 +117,22 @@ export const onemac: Handler = async (event) => {
docObject[id] = result.data;
}
}
} else {
const id: string = decode(key);
const oneMacTombstone: OneMacRecordsToDelete = {
id,
additionalInformation: undefined,
attachments: undefined,
submitterEmail: undefined,
submitterName: undefined,
};

docObject[id] = oneMacTombstone;

console.log(
`Record ${id} has been nullified with the following data: `,
JSON.stringify(oneMacTombstone)
);
}
}
}
Expand Down

0 comments on commit 646d0ba

Please sign in to comment.