From 362c53649a63370656e460a275fbdab938ba4864 Mon Sep 17 00:00:00 2001 From: PLJNS Date: Thu, 26 Oct 2023 21:44:32 -0400 Subject: [PATCH] 2.5.7 really try to find a customer --- src/moa-square/guards/customers.guard.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/moa-square/guards/customers.guard.ts b/src/moa-square/guards/customers.guard.ts index 8f625f21..5a0b1010 100644 --- a/src/moa-square/guards/customers.guard.ts +++ b/src/moa-square/guards/customers.guard.ts @@ -66,10 +66,23 @@ export class CustomersGuard implements CanActivate { }); if (!customer) { - customer = await this.service.createSaveAndSyncSquare({ - userId: user.id, - merchantIdOrPath, - }); + try { + customer = await this.service.createSaveAndSyncSquare({ + userId: user.id, + merchantIdOrPath, + }); + } catch { + customer = await this.service.findOneWithUserIdAndMerchantIdOrPath({ + where: { + userId: user.id, + merchantIdOrPath, + }, + }); + + if (!customer) { + throw new NotFoundException(translations.customersNotFound); + } + } } // Store customer object in request for later use