From 768ce060f4e5da92d38df471e79adddbfa06bd09 Mon Sep 17 00:00:00 2001 From: PLJNS Date: Wed, 31 Jan 2024 18:17:34 -0500 Subject: [PATCH] 2.5.14 configuration SQUARE_MAXIMUM_ITEMS_IN_CATEGORY --- src/moa-square/moa-square.config.ts | 18 +++++++++++++++++- src/moa-square/services/categories.service.ts | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/moa-square/moa-square.config.ts b/src/moa-square/moa-square.config.ts index c079c6d5..42abddfb 100644 --- a/src/moa-square/moa-square.config.ts +++ b/src/moa-square/moa-square.config.ts @@ -1,6 +1,12 @@ import { registerAs } from '@nestjs/config'; import { plainToClass } from 'class-transformer'; -import { IsBoolean, IsOptional, IsString, validateSync } from 'class-validator'; +import { + IsBoolean, + IsNumber, + IsOptional, + IsString, + validateSync, +} from 'class-validator'; import { toBigIntOrThrow } from '../utils/to-big-int-or-throw.js'; export type MyOrderAppSquareConfigType = { @@ -15,6 +21,8 @@ export type MyOrderAppSquareConfigType = { squareTier1AppFeeBigIntNumerator: bigint; squareTier2AppFeeBigIntNumerator: bigint; + squareMaximumItemsInCategory?: number; + squareTestUseS3?: boolean; squareTestCode?: string; squareTestAccessToken?: string; @@ -70,6 +78,10 @@ class MyOrderAppSquareConfigValidator { SQUARE_TIER_2_APP_FEE_BIG_INT_NUMERATOR!: number; + @IsNumber() + @IsOptional() + SQUARE_MAXIMUM_ITEMS_IN_CATEGORY?: number; + @IsBoolean() @IsOptional() SQUARE_TEST_USE_S3?: boolean; @@ -206,6 +218,10 @@ export const MyOrderAppSquareConfig = registerAs('moaSquare', () => { process.env.SQUARE_TIER_2_APP_FEE_BIG_INT_NUMERATOR!, ), + squareMaximumItemsInCategory: process.env.SQUARE_MAXIMUM_ITEMS_IN_CATEGORY + ? parseInt(process.env.SQUARE_MAXIMUM_ITEMS_IN_CATEGORY, 10) + : undefined, + squareTestCode: process.env.SQUARE_TEST_CODE, squareTestAccessToken: process.env.SQUARE_TEST_ACCESS_TOKEN, squareTestRefreshToken: process.env.SQUARE_TEST_REFRESH_TOKEN, diff --git a/src/moa-square/services/categories.service.ts b/src/moa-square/services/categories.service.ts index 221e8326..8b7c481d 100644 --- a/src/moa-square/services/categories.service.ts +++ b/src/moa-square/services/categories.service.ts @@ -1,4 +1,5 @@ import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import type { ConfigType } from '@nestjs/config'; import { InjectRepository } from '@nestjs/typeorm'; import { CatalogObject } from 'square'; import { Repository } from 'typeorm'; @@ -10,6 +11,7 @@ import { CategoryPatchBody, } from '../dto/catalogs/category-patch.dto.js'; import { CategoryEntity } from '../entities/category.entity.js'; +import { MyOrderAppSquareConfig } from '../moa-square.config.js'; import { CatalogSortService } from './catalog-sort.service.js'; import { ItemsService } from './items.service.js'; @@ -22,6 +24,8 @@ export class CategoriesService extends EntityRepositoryService { protected readonly repository: Repository, @Inject(forwardRef(() => ItemsService)) private readonly itemsService: WrapperType, + @Inject(MyOrderAppSquareConfig.KEY) + private readonly config: ConfigType, private readonly catalogSortService: CatalogSortService, ) { const logger = new Logger(CategoriesService.name); @@ -77,7 +81,7 @@ export class CategoriesService extends EntityRepositoryService { leftJoinVariations, leftJoinModifierLists, whereOnlyEnabled, - limit: 30, // emergency fallback + limit: this.config?.squareMaximumItemsInCategory, // emergency fallback }) .getMany(), );