Просмотр исходного кода

fix: use custom_id for shop lookup in custom URLs endpoints

Issue Found:
- POST /api/shops/:id/custom-urls only accepted internal shop ID
- PATCH /api/shops/:id/custom-urls/:customUrlId only accepted internal shop ID
- DELETE /api/shops/:id/custom-urls/:customUrlId only accepted internal shop ID
- GET /api/shops/:id/custom-urls was already correct

Fix Applied:
- Changed getShopById(id) to getShopByAnyId(id) in all three endpoints
- Now tries custom_id first, then falls back to internal UUID
- Consistent with other endpoints like GET /api/shops/:id

Updated Documentation:
- Changed "Shop ID" to "Shop ID (internal UUID or custom UUID)"
- Added clarifying comments in code

Impact:
- Users can now use custom_id for all custom URL operations
- Consistent API behavior across all shop endpoints
- No breaking changes (internal IDs still work)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh 8 месяцев назад
Родитель
Сommit
352e725368
1 измененных файлов с 9 добавлено и 7 удалено
  1. 9 7
      src/api/components/CustomUrlsEndpoint.ts

+ 9 - 7
src/api/components/CustomUrlsEndpoint.ts

@@ -24,7 +24,7 @@ export class CustomUrlsEndpoint extends BaseEndpointComponent {
               in: 'path',
               type: 'string',
               required: true,
-              description: 'Shop ID'
+              description: 'Shop ID (internal UUID or custom UUID)'
             }
           ],
           requestBody: {
@@ -141,7 +141,7 @@ export class CustomUrlsEndpoint extends BaseEndpointComponent {
               in: 'path',
               type: 'string',
               required: true,
-              description: 'Shop ID'
+              description: 'Shop ID (internal UUID or custom UUID)'
             },
             {
               name: 'customUrlId',
@@ -200,7 +200,7 @@ export class CustomUrlsEndpoint extends BaseEndpointComponent {
               in: 'path',
               type: 'string',
               required: true,
-              description: 'Shop ID'
+              description: 'Shop ID (internal UUID or custom UUID)'
             },
             {
               name: 'customUrlId',
@@ -268,8 +268,8 @@ export class CustomUrlsEndpoint extends BaseEndpointComponent {
         return;
       }
 
-      // Check if shop exists
-      const shop = this.db.getShopById(id);
+      // Check if shop exists (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(id);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;
@@ -370,7 +370,8 @@ export class CustomUrlsEndpoint extends BaseEndpointComponent {
         return;
       }
 
-      const shop = this.db.getShopById(id);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(id);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;
@@ -409,7 +410,8 @@ export class CustomUrlsEndpoint extends BaseEndpointComponent {
 
       const { id, customUrlId } = req.params;
 
-      const shop = this.db.getShopById(id);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(id);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;