Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions tapiro-api-internal/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tapiro-api-internal/controllers/StoreProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
16 changes: 6 additions & 10 deletions tapiro-api-internal/service/StoreProfileService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 3 additions & 10 deletions web/src/api/hooks/useStoreHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreBasicInfo[], Error>({
// 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,
});
}
Expand Down
11 changes: 6 additions & 5 deletions web/src/api/types/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Error,
GetApiKeyUsagePayload,
GetApiUsageLogParams,
LookupStoresParams,
LookupStoresPayload,
PaginationInfo,
SearchStoresParams,
Store,
Expand Down Expand Up @@ -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<StoreBasicInfo[], Error>({
path: `/stores/lookup`,
method: "GET",
query: query,
method: "POST",
body: data,
secure: true,
type: ContentType.Json,
format: "json",
...params,
});
Expand Down
6 changes: 3 additions & 3 deletions web/src/api/types/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/UserDashboard/UserDataSharingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const UserDataSharingPage: React.FC = () => {
Control Data Sharing
</h2>

<div className="grid grid-cols-1 gap-8 md:grid-cols-2">
<div className="grid grid-cols-1 items-start gap-8 md:grid-cols-2">
{/* Opt-In List (Existing) */}
<Card>
<h3 className="text-xl font-semibold text-gray-900 dark:text-white">
Expand Down
Loading