@@ -29,7 +29,8 @@ import type {
2929 AdminProductListRequest ,
3030 UpdateCategoryRequest ,
3131 OrderListRequest ,
32- OrderParameters
32+ OrderParameters ,
33+ CreateCategoryRequest
3334} from 'commercify-api-client' ;
3435import { EnvironmentConfig } from '../env' ;
3536import {
@@ -46,8 +47,13 @@ import {
4647 orderSummaryResponseMapper
4748} from '$lib/mappers' ;
4849import { OrderCache , ProductCache } from '$lib/cache' ;
49- import type { CreateProductInput , UpdateCategoryInput , UpdateProductInput } from '$lib/types' ;
50- import { categoryResponseMapper } from '$lib/mappers/category.mapper' ;
50+ import type {
51+ CreateCategoryInput ,
52+ CreateProductInput ,
53+ UpdateCategoryInput ,
54+ UpdateProductInput
55+ } from '$lib/types' ;
56+ import { categoryListMapper , categoryResponseMapper } from '$lib/mappers/category.mapper' ;
5157import { paymentResponseMapper } from '$lib/mappers/payments.mapper' ;
5258
5359/**
@@ -373,7 +379,7 @@ export class CachedCommercifyApiClient {
373379 return {
374380 list : CacheHelpers . createSimpleCachedEndpoint (
375381 'categories' ,
376- ( ) => this . client . categories . list ( ) ,
382+ ( ) => this . client . categories . list ( categoryListMapper ) ,
377383 CACHE_TTL . CATEGORIES
378384 ) ,
379385 get : ( id : number ) => {
@@ -384,8 +390,22 @@ export class CachedCommercifyApiClient {
384390 CACHE_TTL . CATEGORY
385391 ) ;
386392 } ,
393+ create : async ( data : CreateCategoryInput ) => {
394+ const requestData : CreateCategoryRequest = {
395+ name : data . name ,
396+ description : data . description || '' ,
397+ parent_id : data . parentId ? parseInt ( data . parentId ) : undefined
398+ } ;
399+
400+ const result = await this . client . categories . create ( requestData , categoryResponseMapper ) ;
401+
402+ // Invalidate category caches after creation
403+ await CacheInvalidator . invalidateAllCategoryCaches ( ) ;
404+
405+ return result ;
406+ } ,
387407 update : async ( id : number , data : any ) => {
388- const requestData = {
408+ const requestData : UpdateCategoryRequest = {
389409 name : data . name ,
390410 description : data . description || '' ,
391411 parent_id : data . parentId ? parseInt ( data . parentId ) : undefined
0 commit comments