From 1c61dc955f4a910dc00c7deed8c143aa43849b67 Mon Sep 17 00:00:00 2001 From: tiffanyvu Date: Wed, 22 Jan 2025 11:45:56 -0800 Subject: [PATCH] logic --- lib/lambda/submit/splitSPAId.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/lambda/submit/splitSPAId.ts b/lib/lambda/submit/splitSPAId.ts index 18a8bcc17..cb53d0b86 100644 --- a/lib/lambda/submit/splitSPAId.ts +++ b/lib/lambda/submit/splitSPAId.ts @@ -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; @@ -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; } };