@@ -143,6 +143,20 @@ export class StorageItemsService {
143
143
org_filter ?: string ,
144
144
) {
145
145
// Build a base query without range for counting and apply all filters
146
+
147
+ // Get nested categories of X category ID.
148
+ const matchingCategories : string [ ] = [ ] ;
149
+ if ( category ) {
150
+ const { data : categories } = await supabase . rpc (
151
+ "get_category_descendants" ,
152
+ {
153
+ category_uuid : category ,
154
+ } ,
155
+ ) ;
156
+ matchingCategories . push (
157
+ ...( categories as { id : string } [ ] ) . map ( ( c ) => c . id ) ,
158
+ ) ;
159
+ }
146
160
const base = applyItemFilters (
147
161
supabase
148
162
. from ( "view_manage_storage_items" )
@@ -153,7 +167,7 @@ export class StorageItemsService {
153
167
isActive,
154
168
tags,
155
169
location_filter,
156
- category ,
170
+ categories : matchingCategories ,
157
171
from_date,
158
172
to_date,
159
173
availability_min,
@@ -193,7 +207,7 @@ export class StorageItemsService {
193
207
isActive,
194
208
tags,
195
209
location_filter,
196
- category ,
210
+ categories : matchingCategories ,
197
211
from_date,
198
212
to_date,
199
213
availability_min,
@@ -202,7 +216,6 @@ export class StorageItemsService {
202
216
} ) ;
203
217
204
218
if ( order_by ) query . order ( order_by ?? "created_at" , { ascending } ) ;
205
-
206
219
const result = await query ;
207
220
208
221
if ( result . error ) {
@@ -250,7 +263,19 @@ export class StorageItemsService {
250
263
if ( ! supabase ) {
251
264
throw new BadRequestException ( "Supabase client is not initialized." ) ;
252
265
}
253
-
266
+ // Get nested categories of X category ID.
267
+ const matchingCategories : string [ ] = [ ] ;
268
+ if ( category ) {
269
+ const { data : categories } = await supabase . rpc (
270
+ "get_category_descendants" ,
271
+ {
272
+ category_uuid : category ,
273
+ } ,
274
+ ) ;
275
+ matchingCategories . push (
276
+ ...( categories as { id : string } [ ] ) . map ( ( c ) => c . id ) ,
277
+ ) ;
278
+ }
254
279
// Build a base query with organization filtering
255
280
const base = applyItemFilters (
256
281
supabase
@@ -263,7 +288,7 @@ export class StorageItemsService {
263
288
isActive,
264
289
tags,
265
290
location_filter,
266
- category ,
291
+ categories : matchingCategories ,
267
292
} ,
268
293
) ;
269
294
const countResult = await base ;
@@ -299,7 +324,7 @@ export class StorageItemsService {
299
324
isActive,
300
325
tags,
301
326
location_filter,
302
- category ,
327
+ categories : matchingCategories ,
303
328
} ) ;
304
329
305
330
if ( order_by ) query . order ( order_by ?? "created_at" , { ascending } ) ;
@@ -324,10 +349,6 @@ export class StorageItemsService {
324
349
* @returns An object containing the total count of storage items.
325
350
*/
326
351
async getItemCount ( req : AuthRequest , role : string , orgId : string ) {
327
- console . log ( "Request path:" , req . path ) ;
328
- console . log ( "Headers:" , req . headers ) ;
329
- console . log ( "ActiveRoleContext:" , req . activeRoleContext ) ;
330
-
331
352
const supabase = req . supabase ;
332
353
const result = await supabase
333
354
. from ( "storage_items" )
0 commit comments