Skip to content

Commit 8c57167

Browse files
committed
handle malformed numbers as well
1 parent e7345aa commit 8c57167

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/app/api/kioskOrder/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function POST(request: Request) {
4848

4949
// 1. Validate user input
5050
const lookupService = await getLookupService();
51-
const phoneNumber = await lookupService.phoneNumbers(data.phone).fetch();
51+
const lookupResult = await lookupService.phoneNumbers(data.phone).fetch();
5252
if (!data.phone || !data?.item?.title || !data.event) {
5353
return new Response("Missing required fields", {
5454
status: 400,
@@ -57,7 +57,7 @@ export async function POST(request: Request) {
5757
}
5858

5959
// TODO potentially check sms_pumping_risk here
60-
if (!phoneNumber.valid) {
60+
if (!lookupResult.valid) {
6161
return new Response("Phone number is invalid", {
6262
status: 400,
6363
statusText: "Phone number is invalid",
@@ -80,7 +80,7 @@ export async function POST(request: Request) {
8080
}
8181

8282
// 3. Create new conversation
83-
const sender = data.whatsapp ? `whatsapp:${data.phone}` : data.phone;
83+
const sender = data.whatsapp ? `whatsapp:${lookupResult.phoneNumber}` : lookupResult.phoneNumber;
8484
const participantConversations = await getConversationsOfSender(sender);
8585
const activeConversations = participantConversations.filter(
8686
(conv) => conv.conversationState === "active",
@@ -108,7 +108,7 @@ export async function POST(request: Request) {
108108
// 4. Add attendee to sync list
109109
// incorrect but doesn't matter for this single-use event, should check if attendee is already in list
110110
try {
111-
const country = getCountryFromPhone(data.phone);
111+
const country = getCountryFromPhone(lookupResult.phoneNumber);
112112
await updateOrCreateSyncMapItem(
113113
NEXT_PUBLIC_ACTIVE_CUSTOMERS_MAP,
114114
conversationSid,

0 commit comments

Comments
 (0)