Skip to content

Commit

Permalink
2.5.14 configuration SQUARE_MAXIMUM_ITEMS_IN_CATEGORY
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljonescodes committed Jan 31, 2024
1 parent a42ab0f commit 768ce06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/moa-square/moa-square.config.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -15,6 +21,8 @@ export type MyOrderAppSquareConfigType = {
squareTier1AppFeeBigIntNumerator: bigint;
squareTier2AppFeeBigIntNumerator: bigint;

squareMaximumItemsInCategory?: number;

squareTestUseS3?: boolean;
squareTestCode?: string;
squareTestAccessToken?: string;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/moa-square/services/categories.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Expand All @@ -22,6 +24,8 @@ export class CategoriesService extends EntityRepositoryService<CategoryEntity> {
protected readonly repository: Repository<CategoryEntity>,
@Inject(forwardRef(() => ItemsService))
private readonly itemsService: WrapperType<ItemsService>,
@Inject(MyOrderAppSquareConfig.KEY)
private readonly config: ConfigType<typeof MyOrderAppSquareConfig>,
private readonly catalogSortService: CatalogSortService,
) {
const logger = new Logger(CategoriesService.name);
Expand Down Expand Up @@ -77,7 +81,7 @@ export class CategoriesService extends EntityRepositoryService<CategoryEntity> {
leftJoinVariations,
leftJoinModifierLists,
whereOnlyEnabled,
limit: 30, // emergency fallback
limit: this.config?.squareMaximumItemsInCategory, // emergency fallback
})
.getMany(),
);
Expand Down

0 comments on commit 768ce06

Please sign in to comment.