Skip to content

Commit

Permalink
logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyvu committed Jan 22, 2025
1 parent cbd5bba commit 1c61dc9
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/lambda/submit/splitSPAId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export const getNextSplitSPAId = async (spaId: string) => {
const query = {
query: {
regexp: {
"id.keyword": `${spaId}-[A-Z]`, // only allow capital letters
"id.keyword": `${spaId}-[A-Z]`,
},
},
};
// get existing split SPAs for this package id
const matchingSplitSPAs = await search(domain, index, query);

let newSplitSPAId: string;
Expand All @@ -22,17 +23,15 @@ export const getNextSplitSPAId = async (spaId: string) => {
newSplitSPAId = `${spaId}-A`;
return newSplitSPAId;
}
// } else {
// newSplitSPAId = "";
// console.log(matchingSplitSPAs, "HELLOOO");
// return newSplitSPAId;
// }
} else {
newSplitSPAId = "";
const ids = matchingSplitSPAs.hits.hits.map((hit: any) => hit._source.id);
console.log(ids);
const suffixes = ids.map((id: string) => id.split("-").at(-1));
console.log(suffixes, "LETTERS");
const letterCharCodes = suffixes.map((letter: string, idx: number) => letter.charCodeAt(idx));
const lastLetter = Math.max(letterCharCodes);
console.log(letterCharCodes, "LETTERS");
console.log(lastLetter, "last letter");
return newSplitSPAId;
}
};

0 comments on commit 1c61dc9

Please sign in to comment.