From c2148fe9abb8b34261800e58c92d8210f6f0e54e Mon Sep 17 00:00:00 2001 From: CDevmina Date: Wed, 21 May 2025 02:05:33 +0530 Subject: [PATCH 1/2] feat: Update lookupStores endpoint to use POST method with request body for store IDs --- tapiro-api-internal/api/openapi.yaml | 23 ++++++++++++------- .../controllers/StoreProfile.js | 4 ++-- .../service/StoreProfileService.js | 16 +++++-------- web/src/api/hooks/useStoreHooks.ts | 13 +++-------- web/src/api/types/Stores.ts | 11 +++++---- web/src/api/types/data-contracts.ts | 6 ++--- 6 files changed, 35 insertions(+), 38 deletions(-) diff --git a/tapiro-api-internal/api/openapi.yaml b/tapiro-api-internal/api/openapi.yaml index 95f5db7..0791cba 100644 --- a/tapiro-api-internal/api/openapi.yaml +++ b/tapiro-api-internal/api/openapi.yaml @@ -730,18 +730,25 @@ paths: x-swagger-router-controller: UserProfile /stores/lookup: - get: + post: tags: [Store Management] summary: Lookup Store Details description: Retrieves basic details (like name) for a list of store IDs. operationId: lookupStores - parameters: - - name: ids - in: query - description: Comma-separated list of store IDs to lookup. - required: true - schema: - type: string + requestBody: # Added requestBody + required: true + content: + application/json: + schema: + type: object + required: + - ids + properties: + ids: + type: array + items: + type: string + description: An array of store IDs to lookup. responses: "200": description: Store details retrieved successfully. diff --git a/tapiro-api-internal/controllers/StoreProfile.js b/tapiro-api-internal/controllers/StoreProfile.js index 290d8ab..8a8c337 100644 --- a/tapiro-api-internal/controllers/StoreProfile.js +++ b/tapiro-api-internal/controllers/StoreProfile.js @@ -43,8 +43,8 @@ module.exports.searchStores = function searchStores(req, res, next) { }; module.exports.lookupStores = function lookupStores(req, res, next) { - const { ids } = req.query; - StoreProfile.lookupStores(req, ids) + const body = req.body; // Get body from request + StoreProfile.lookupStores(req, body) // Pass body to service .then((response) => { utils.writeJson(res, response); }) diff --git a/tapiro-api-internal/service/StoreProfileService.js b/tapiro-api-internal/service/StoreProfileService.js index 50a5df3..cde8c30 100644 --- a/tapiro-api-internal/service/StoreProfileService.js +++ b/tapiro-api-internal/service/StoreProfileService.js @@ -154,19 +154,15 @@ exports.deleteStoreProfile = async function (req) { * Lookup Store Details * Retrieves basic details (like name) for a list of store IDs. */ -exports.lookupStores = async function (req, ids) { +exports.lookupStores = async function (req, body) { // Changed signature to accept body try { - if (!ids) { - return respondWithCode(400, { code: 400, message: 'Missing required query parameter: ids' }); - } + const ids = body.ids; // Get IDs from request body - const storeIds = ids.split(','); + if (!ids || !Array.isArray(ids) || ids.length === 0) { + return respondWithCode(400, { code: 400, message: 'Missing or invalid required body parameter: ids (must be a non-empty array)' }); + } - // Optional: Validate if IDs are in ObjectId format if needed - // const validObjectIds = storeIds.filter(id => ObjectId.isValid(id)).map(id => new ObjectId(id)); - // if (validObjectIds.length !== storeIds.length) { - // return respondWithCode(400, { code: 400, message: 'One or more invalid store ID formats provided.' }); - // } + const storeIds = ids; const db = getDB(); diff --git a/web/src/api/hooks/useStoreHooks.ts b/web/src/api/hooks/useStoreHooks.ts index a43c75e..adb1adf 100644 --- a/web/src/api/hooks/useStoreHooks.ts +++ b/web/src/api/hooks/useStoreHooks.ts @@ -207,24 +207,17 @@ export function useLookupStores(storeIds: string[]) { const { apiClients, clientsReady } = useApiClients(); const { isAuthenticated, isLoading: authLoading } = useAuth(); - // Filter out empty IDs and join for the query key and API call + // Filter out empty IDs const validIds = storeIds.filter((id) => id); - const idsQueryParam = validIds.join(","); return useQuery({ - // Expect an array of StoreBasicInfo - // Include the sorted list of valid IDs in the query key queryKey: cacheKeys.stores.lookup(validIds.sort()), queryFn: () => - // Pass the comma-separated string of IDs to the API client method - apiClients.stores - .lookupStores({ ids: idsQueryParam }) - .then((res) => res.data), - // Only enable if there are valid IDs and the client is ready + apiClients.stores.lookupStores({ ids: validIds }).then((res) => res.data), enabled: validIds.length > 0 && isAuthenticated && !authLoading && clientsReady, // Cache settings can be specific or default - staleTime: CACHE_TIMES.LONG, // Store names don't change often + staleTime: CACHE_TIMES.LONG, gcTime: CACHE_TIMES.LONG * 2, }); } diff --git a/web/src/api/types/Stores.ts b/web/src/api/types/Stores.ts index d30129e..799ad15 100644 --- a/web/src/api/types/Stores.ts +++ b/web/src/api/types/Stores.ts @@ -19,7 +19,7 @@ import { Error, GetApiKeyUsagePayload, GetApiUsageLogParams, - LookupStoresParams, + LookupStoresPayload, PaginationInfo, SearchStoresParams, Store, @@ -251,19 +251,20 @@ export class Stores< * @tags Store Management * @name LookupStores * @summary Lookup Store Details - * @request GET:/stores/lookup + * @request POST:/stores/lookup * @secure * @response `200` `(StoreBasicInfo)[]` Store details retrieved successfully. * @response `400` `Error` * @response `401` `Error` * @response `500` `Error` */ - lookupStores = (query: LookupStoresParams, params: RequestParams = {}) => + lookupStores = (data: LookupStoresPayload, params: RequestParams = {}) => this.request({ path: `/stores/lookup`, - method: "GET", - query: query, + method: "POST", + body: data, secure: true, + type: ContentType.Json, format: "json", ...params, }); diff --git a/web/src/api/types/data-contracts.ts b/web/src/api/types/data-contracts.ts index 572fb6a..4978a37 100644 --- a/web/src/api/types/data-contracts.ts +++ b/web/src/api/types/data-contracts.ts @@ -636,9 +636,9 @@ export interface GetSpendingAnalyticsParams { endDate?: string; } -export interface LookupStoresParams { - /** Comma-separated list of store IDs to lookup. */ - ids: string; +export interface LookupStoresPayload { + /** An array of store IDs to lookup. */ + ids: string[]; } export interface SearchStoresParams { From a2a5b46b02af0ba5dd6b55f007c1ac6f878997b4 Mon Sep 17 00:00:00 2001 From: CDevmina Date: Wed, 21 May 2025 02:12:22 +0530 Subject: [PATCH 2/2] feat: Adjust grid layout in UserDataSharingPage for improved item alignment --- web/src/pages/UserDashboard/UserDataSharingPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/pages/UserDashboard/UserDataSharingPage.tsx b/web/src/pages/UserDashboard/UserDataSharingPage.tsx index 2ddaa4d..25ffa97 100644 --- a/web/src/pages/UserDashboard/UserDataSharingPage.tsx +++ b/web/src/pages/UserDashboard/UserDataSharingPage.tsx @@ -191,7 +191,7 @@ const UserDataSharingPage: React.FC = () => { Control Data Sharing -
+
{/* Opt-In List (Existing) */}