فهرست منبع

Use current user id when target id is not provided

arvid-e 5 ماه پیش
والد
کامیت
d4e484499a
2فایلهای تغییر یافته به همراه8 افزوده شده و 4 حذف شده
  1. 6 3
      apps/app/src/server/routes/apiv3/user-activities.ts
  2. 2 1
      apps/app/src/stores/recent-activity.ts

+ 6 - 3
apps/app/src/server/routes/apiv3/user-activities.ts

@@ -180,11 +180,14 @@ module.exports = (crowi: Crowi): Router => {
 
       const limit = req.query.limit || defaultLimit || 10;
       const offset = req.query.offset || 0;
-      const targetUserId = req.query.targetUserId;
+      let targetUserId = req.query.targetUserId;
 
       if (typeof targetUserId !== 'string') {
-        logger.error('Bad request: targetUserId must be of type string.');
-        return res.apiv3Err('Bad request.', 400);
+        targetUserId = req.user?._id;
+      }
+
+      if (!targetUserId) {
+        return res.apiv3Err('Target user ID is missing and authenticated user ID is unavailable.', 400);
       }
 
 

+ 2 - 1
apps/app/src/stores/recent-activity.ts

@@ -11,7 +11,8 @@ export const useSWRxRecentActivity = (
     targetUserId?: string,
 ): SWRResponse<PaginateResult<IActivityHasId>, Error> => {
 
-  const key = ['/user-activities', limit, offset, targetUserId];
+  const shouldFetch = targetUserId && targetUserId.length > 0;
+  const key = shouldFetch ? ['/user-activities', limit, offset, targetUserId] : null;
 
   const fetcher = ([
     endpoint,