From 846e3e6368df7eef2e7614f97a3141a9000098df Mon Sep 17 00:00:00 2001 From: Joe Arndt Date: Fri, 27 Feb 2026 21:30:24 -0600 Subject: [PATCH 1/3] added tag filtering --- src/tags/tag-data.service.ts | 12 +++++++++--- src/tags/tags.controller.ts | 15 +++++++++++++-- src/tags/tags.service.ts | 5 +++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/tags/tag-data.service.ts b/src/tags/tag-data.service.ts index df417c5..7776047 100644 --- a/src/tags/tag-data.service.ts +++ b/src/tags/tag-data.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { DataSource, Repository } from 'typeorm'; +import { DataSource, ILike, Repository } from 'typeorm'; import { Tag } from './entities/tag.entity'; import { UpdateTagDto } from './dto/update-tag.dto'; +import { GetTagFilters } from './tags.controller'; @Injectable() export class TagDataService { @@ -11,8 +12,13 @@ export class TagDataService { this.tags = this.dataSource.getRepository(Tag); } - public async getAll(): Promise { - return await this.tags.find(); + public async getAll(filters: GetTagFilters): Promise { + const idFilters = filters.ids?.map(id => { return { id }}) ?? []; + const nameFilters = filters.tags?.map(tag => { return { name: ILike('%' + tag + '%') }}) ?? []; + return await this.tags.find({ + where: [...idFilters, ...nameFilters], + order: { name: filters.sort === 'desc' ? 'desc' : 'asc' }, + }); } public async getById(id: string): Promise { diff --git a/src/tags/tags.controller.ts b/src/tags/tags.controller.ts index d627f8e..e240343 100644 --- a/src/tags/tags.controller.ts +++ b/src/tags/tags.controller.ts @@ -6,6 +6,7 @@ import { Delete, Body, Param, + Query, HttpCode, HttpStatus, BadRequestException, @@ -23,8 +24,12 @@ export class TagsController { @Get() @HttpCode(HttpStatus.OK) - public async findAll(): Promise { - return await this.tagsService.findAll(); + public async findAll(@Query() filters: GetTagFilters): Promise { + const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : []; + const tags = Array.isArray(filters.tags) ? filters.tags : filters.tags ? [filters.tags] : []; + const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc'; + + return await this.tagsService.findAll({ ids, tags, sort }); } @Get(':id') @@ -73,3 +78,9 @@ export class TagsController { return await this.tagsService.remove(id); } } + +export interface GetTagFilters { + ids?: string[]; + tags?: string[]; + sort?: 'asc' | 'desc'; +} diff --git a/src/tags/tags.service.ts b/src/tags/tags.service.ts index ab5ff92..c47d9be 100644 --- a/src/tags/tags.service.ts +++ b/src/tags/tags.service.ts @@ -3,13 +3,14 @@ import { CreateTagDto } from './dto/create-tag.dto'; import { UpdateTagDto } from './dto/update-tag.dto'; import { TagDataService } from './tag-data.service'; import { Tag } from './entities/tag.entity'; +import { GetTagFilters } from './tags.controller'; @Injectable() export class TagsService { public constructor(private tagDataService: TagDataService) { } - public async findAll(): Promise { - return await this.tagDataService.getAll(); + public async findAll(filters: GetTagFilters): Promise { + return await this.tagDataService.getAll(filters); } public async findById(id: string): Promise { From 9daca90d6b68bb114ee20684b4f506230d1c8c8e Mon Sep 17 00:00:00 2001 From: Joe Arndt Date: Fri, 27 Feb 2026 21:41:31 -0600 Subject: [PATCH 2/3] added merchant filtering --- src/merchants/merchant-data.service.ts | 13 ++++++++++--- src/merchants/merchants.controller.ts | 15 +++++++++++++-- src/merchants/merchants.service.ts | 5 +++-- src/tags/tag-data.service.ts | 3 ++- src/tags/tags.controller.ts | 4 ++-- src/tags/tags.service.ts | 4 ++-- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/merchants/merchant-data.service.ts b/src/merchants/merchant-data.service.ts index efbb956..088a356 100644 --- a/src/merchants/merchant-data.service.ts +++ b/src/merchants/merchant-data.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { DataSource, Repository } from 'typeorm'; +import { DataSource, ILike, Repository } from 'typeorm'; import { Merchant } from './entities/merchant.entity'; import { UpdateMerchantDto } from './dto/update-merchant.dto'; +import { GetMerchantFilters } from './merchants.controller'; @Injectable() export class MerchantDataService { @@ -11,8 +12,14 @@ export class MerchantDataService { this.merchants = this.dataSource.getRepository(Merchant); } - public async getAll(): Promise { - return await this.merchants.find(); + public async get(filters: GetMerchantFilters): Promise { + const idFilters = filters.ids?.map(id => { return { id }}) ?? []; + const nameFilters = filters.merchants?.map(tag => { return { name: ILike('%' + tag + '%') }}) ?? []; + + return await this.merchants.find({ + where: [...idFilters, ...nameFilters], + order: { name: filters.sort === 'desc' ? 'desc' : 'asc' }, + }); } public async getById(id: string): Promise { diff --git a/src/merchants/merchants.controller.ts b/src/merchants/merchants.controller.ts index 97a7ac3..2cff37d 100644 --- a/src/merchants/merchants.controller.ts +++ b/src/merchants/merchants.controller.ts @@ -6,6 +6,7 @@ import { Delete, Body, Param, + Query, HttpCode, HttpStatus, NotFoundException, @@ -23,8 +24,12 @@ export class MerchantsController { @Get() @HttpCode(HttpStatus.OK) - public async findAll(): Promise { - return await this.merchantsService.findAll(); + public async find(@Query() filters: GetMerchantFilters): Promise { + const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : []; + const merchants = Array.isArray(filters.merchants) ? filters.merchants : filters.merchants ? [filters.merchants] : []; + const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc'; + + return await this.merchantsService.find({ ids, merchants, sort }); } @Get(':id') @@ -73,3 +78,9 @@ export class MerchantsController { return await this.merchantsService.remove(id); } } + +export interface GetMerchantFilters { + ids?: string[]; + merchants?: string[]; + sort?: 'asc' | 'desc'; +} diff --git a/src/merchants/merchants.service.ts b/src/merchants/merchants.service.ts index ef98690..56a5d84 100644 --- a/src/merchants/merchants.service.ts +++ b/src/merchants/merchants.service.ts @@ -3,13 +3,14 @@ import { CreateMerchantDto } from './dto/create-merchant.dto'; import { UpdateMerchantDto } from './dto/update-merchant.dto'; import { MerchantDataService } from './merchant-data.service'; import { Merchant } from './entities/merchant.entity'; +import { GetMerchantFilters } from './merchants.controller'; @Injectable() export class MerchantsService { public constructor(private merchantDataService: MerchantDataService) { } - public async findAll(): Promise { - return await this.merchantDataService.getAll(); + public async find(filters: GetMerchantFilters): Promise { + return await this.merchantDataService.get(filters); } public async findById(id: string): Promise { diff --git a/src/tags/tag-data.service.ts b/src/tags/tag-data.service.ts index 7776047..ee9400f 100644 --- a/src/tags/tag-data.service.ts +++ b/src/tags/tag-data.service.ts @@ -12,9 +12,10 @@ export class TagDataService { this.tags = this.dataSource.getRepository(Tag); } - public async getAll(filters: GetTagFilters): Promise { + public async get(filters: GetTagFilters): Promise { const idFilters = filters.ids?.map(id => { return { id }}) ?? []; const nameFilters = filters.tags?.map(tag => { return { name: ILike('%' + tag + '%') }}) ?? []; + return await this.tags.find({ where: [...idFilters, ...nameFilters], order: { name: filters.sort === 'desc' ? 'desc' : 'asc' }, diff --git a/src/tags/tags.controller.ts b/src/tags/tags.controller.ts index e240343..b27e5fa 100644 --- a/src/tags/tags.controller.ts +++ b/src/tags/tags.controller.ts @@ -24,12 +24,12 @@ export class TagsController { @Get() @HttpCode(HttpStatus.OK) - public async findAll(@Query() filters: GetTagFilters): Promise { + public async find(@Query() filters: GetTagFilters): Promise { const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : []; const tags = Array.isArray(filters.tags) ? filters.tags : filters.tags ? [filters.tags] : []; const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc'; - return await this.tagsService.findAll({ ids, tags, sort }); + return await this.tagsService.find({ ids, tags, sort }); } @Get(':id') diff --git a/src/tags/tags.service.ts b/src/tags/tags.service.ts index c47d9be..954dbb2 100644 --- a/src/tags/tags.service.ts +++ b/src/tags/tags.service.ts @@ -9,8 +9,8 @@ import { GetTagFilters } from './tags.controller'; export class TagsService { public constructor(private tagDataService: TagDataService) { } - public async findAll(filters: GetTagFilters): Promise { - return await this.tagDataService.getAll(filters); + public async find(filters: GetTagFilters): Promise { + return await this.tagDataService.get(filters); } public async findById(id: string): Promise { From 69723d0801abb0fa101b968adf893771d8aebcc4 Mon Sep 17 00:00:00 2001 From: Joe Arndt Date: Fri, 27 Feb 2026 21:48:33 -0600 Subject: [PATCH 3/3] added category filtering --- .../Categories/LOC GET Categories.bru | 6 +++++- .../Common Cents/Merchants/LOC GET Merchants.bru | 6 +++++- bruno/Common Cents/Tags/LOC GET Tags.bru | 4 ++++ src/categories/categories.controller.ts | 15 +++++++++++++-- src/categories/categories.service.ts | 5 +++-- src/categories/category-data.service.ts | 13 ++++++++++--- src/merchants/merchant-data.service.ts | 2 +- src/tags/tag-data.service.ts | 2 +- 8 files changed, 42 insertions(+), 11 deletions(-) diff --git a/bruno/Common Cents/Categories/LOC GET Categories.bru b/bruno/Common Cents/Categories/LOC GET Categories.bru index 8d46826..54aee7f 100644 --- a/bruno/Common Cents/Categories/LOC GET Categories.bru +++ b/bruno/Common Cents/Categories/LOC GET Categories.bru @@ -5,7 +5,11 @@ meta { } get { - url: {{localBaseUrl}}/{{resourcePath}} + url: {{localBaseUrl}}/{{resourcePath}}?sort=desc body: none auth: inherit } + +params:query { + sort: desc +} diff --git a/bruno/Common Cents/Merchants/LOC GET Merchants.bru b/bruno/Common Cents/Merchants/LOC GET Merchants.bru index 5ba79b7..bd061db 100644 --- a/bruno/Common Cents/Merchants/LOC GET Merchants.bru +++ b/bruno/Common Cents/Merchants/LOC GET Merchants.bru @@ -5,7 +5,11 @@ meta { } get { - url: {{localBaseUrl}}/{{resourcePath}} + url: {{localBaseUrl}}/{{resourcePath}}?sort=desc body: none auth: inherit } + +params:query { + sort: desc +} diff --git a/bruno/Common Cents/Tags/LOC GET Tags.bru b/bruno/Common Cents/Tags/LOC GET Tags.bru index dc19694..65caa02 100644 --- a/bruno/Common Cents/Tags/LOC GET Tags.bru +++ b/bruno/Common Cents/Tags/LOC GET Tags.bru @@ -9,3 +9,7 @@ get { body: none auth: inherit } + +params:query { + ~tags: Tundra +} diff --git a/src/categories/categories.controller.ts b/src/categories/categories.controller.ts index 878f76c..d8a8775 100644 --- a/src/categories/categories.controller.ts +++ b/src/categories/categories.controller.ts @@ -6,6 +6,7 @@ import { Delete, Body, Param, + Query, HttpCode, HttpStatus, BadRequestException, @@ -23,8 +24,12 @@ export class CategoriesController { @Get() @HttpCode(HttpStatus.OK) - public async findAll(): Promise { - return await this.categoriesService.findAll(); + public async find(@Query() filters: GetCategoryFilters): Promise { + const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : []; + const categories = Array.isArray(filters.categories) ? filters.categories : filters.categories ? [filters.categories] : []; + const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc'; + + return await this.categoriesService.find({ ids, categories, sort}); } @Get(':id') @@ -73,3 +78,9 @@ export class CategoriesController { return await this.categoriesService.remove(id); } } + +export interface GetCategoryFilters { + ids?: string[]; + categories?: string[]; + sort?: 'asc' | 'desc'; +} diff --git a/src/categories/categories.service.ts b/src/categories/categories.service.ts index 8753b43..ee93b0a 100644 --- a/src/categories/categories.service.ts +++ b/src/categories/categories.service.ts @@ -3,13 +3,14 @@ import { CreateCategoryDto } from './dto/create-category.dto'; import { UpdateCategoryDto } from './dto/update-category.dto'; import { CategoryDataService } from './category-data.service'; import { Category } from './entities/category.entity'; +import { GetCategoryFilters } from './categories.controller'; @Injectable() export class CategoriesService { public constructor(private categoryDataService: CategoryDataService) { } - public async findAll(): Promise { - return await this.categoryDataService.getAll(); + public async find(filters: GetCategoryFilters): Promise { + return await this.categoryDataService.get(filters); } public async findById(id: string): Promise { diff --git a/src/categories/category-data.service.ts b/src/categories/category-data.service.ts index 455bac4..7277274 100644 --- a/src/categories/category-data.service.ts +++ b/src/categories/category-data.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { DataSource, Repository } from 'typeorm'; +import { DataSource, ILike, Repository } from 'typeorm'; import { Category } from './entities/category.entity'; import { UpdateCategoryDto } from './dto/update-category.dto'; +import { GetCategoryFilters } from './categories.controller'; @Injectable() export class CategoryDataService { @@ -11,8 +12,14 @@ export class CategoryDataService { this.categories = this.dataSource.getRepository(Category); } - public async getAll(): Promise { - return await this.categories.find(); + public async get(filters: GetCategoryFilters): Promise { + const idFilters = filters.ids?.map(id => { return { id }}) ?? []; + const nameFilters = filters.categories?.map(tag => { return { name: ILike('%' + tag + '%') }}) ?? []; + + return await this.categories.find({ + where: [...idFilters, ...nameFilters], + order: { name: filters.sort === 'desc' ? 'desc' : 'asc' } + }); } public async getById(id: string): Promise { diff --git a/src/merchants/merchant-data.service.ts b/src/merchants/merchant-data.service.ts index 088a356..23f8ee8 100644 --- a/src/merchants/merchant-data.service.ts +++ b/src/merchants/merchant-data.service.ts @@ -18,7 +18,7 @@ export class MerchantDataService { return await this.merchants.find({ where: [...idFilters, ...nameFilters], - order: { name: filters.sort === 'desc' ? 'desc' : 'asc' }, + order: { name: filters.sort === 'desc' ? 'desc' : 'asc' } }); } diff --git a/src/tags/tag-data.service.ts b/src/tags/tag-data.service.ts index ee9400f..c9b0137 100644 --- a/src/tags/tag-data.service.ts +++ b/src/tags/tag-data.service.ts @@ -18,7 +18,7 @@ export class TagDataService { return await this.tags.find({ where: [...idFilters, ...nameFilters], - order: { name: filters.sort === 'desc' ? 'desc' : 'asc' }, + order: { name: filters.sort === 'desc' ? 'desc' : 'asc' } }); }