Explorar el Código

fix: use custom_id for shop lookup in ALL remaining endpoints

Comprehensive Fix - All 14 Endpoints Updated:

ShopsEndpoint (1):
- PATCH /api/shops/:id/schedule

WebhooksEndpoint (2):
- PUT /api/shops/:id/webhook
- PATCH /api/shops/:id/webhook

QdrantEndpoint (8):
- GET /api/shops/:shopId/qdrant
- POST /api/shops/:shopId/qdrant/enable
- POST /api/shops/:shopId/qdrant/disable
- GET /api/shops/:shopId/qdrant/search/shipping
- GET /api/shops/:shopId/qdrant/search/contacts
- GET /api/shops/:shopId/qdrant/search/terms
- GET /api/shops/:shopId/qdrant/search/faq
- DELETE /api/shops/:shopId/qdrant

McpEndpoint (3):
- GET /api/shops/:shopId/mcp/analytics
- GET /api/shops/:shopId/mcp/search/shipping
- GET /api/shops/:shopId/mcp/search/contacts

Changes Applied:
- Replaced getShopById(id) → getShopByAnyId(id)
- Replaced getShopById(shopId) → getShopByAnyId(shopId)
- Added clarifying comments in all locations

Verification:
- grep shows 0 remaining getShopById() calls in API endpoints
- All endpoints now consistently support custom_id
- Build successful with no TypeScript errors

Impact:
- Users can now use custom_id across ALL shop endpoints
- Complete API consistency
- No breaking changes (internal UUIDs still work)

Previous State:
- Only some endpoints supported custom_id (inconsistent UX)
- Users had to remember which endpoints needed internal UUID

Current State:
- 100% of shop endpoints support both custom_id and internal UUID
- Predictable, consistent API behavior
- Better developer experience

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

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh hace 8 meses
padre
commit
3db2118341

+ 6 - 3
src/api/components/McpEndpoint.ts

@@ -587,7 +587,8 @@ export class McpEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
       const { dateFrom, dateTo } = req.query;
 
-      const shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;
@@ -728,7 +729,8 @@ export class McpEndpoint extends BaseEndpointComponent {
       const { limit, success, tool_name } = req.query;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }
@@ -760,7 +762,8 @@ export class McpEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }

+ 18 - 9
src/api/components/QdrantEndpoint.ts

@@ -595,7 +595,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
     try {
       const { shopId } = req.params;
 
-      const shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;
@@ -636,7 +637,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
       const { enabled } = req.body;
 
-      const shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;
@@ -766,7 +768,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
       const { content_type } = req.body || {};
 
-      const shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      const shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         res.status(404).json({ error: 'Shop not found' });
         return;
@@ -885,7 +888,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }
@@ -917,7 +921,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }
@@ -954,7 +959,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }
@@ -989,7 +995,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }
@@ -1015,7 +1022,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }
@@ -1060,7 +1068,8 @@ export class QdrantEndpoint extends BaseEndpointComponent {
       const { shopId } = req.params;
 
       // Get shop from database - try both internal ID and custom ID
-      let shop = this.db.getShopById(shopId);
+      // Get shop by any ID (try custom_id first, then internal ID)
+      let shop = this.db.getShopByAnyId(shopId);
       if (!shop) {
         shop = this.db.getShopByCustomId(shopId);
       }

+ 2 - 1
src/api/components/ShopsEndpoint.ts

@@ -677,7 +677,8 @@ export class ShopsEndpoint 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;

+ 4 - 2
src/api/components/WebhooksEndpoint.ts

@@ -221,7 +221,8 @@ export class WebhooksEndpoint 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;
@@ -332,7 +333,8 @@ export class WebhooksEndpoint 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;