Shun Miyazawa 3 лет назад
Родитель
Сommit
6951bb0a6c
1 измененных файлов с 17 добавлено и 1 удалено
  1. 17 1
      packages/app/src/pages/utils/commons.ts

+ 17 - 1
packages/app/src/pages/utils/commons.ts

@@ -4,10 +4,10 @@ import { SSRConfig, UserConfig } from 'next-i18next';
 
 
 import * as nextI18NextConfig from '^/config/next-i18next.config';
 import * as nextI18NextConfig from '^/config/next-i18next.config';
 
 
+import { SupportedActionType } from '~/interfaces/activity';
 import { CrowiRequest } from '~/interfaces/crowi-request';
 import { CrowiRequest } from '~/interfaces/crowi-request';
 import { GrowiThemes } from '~/interfaces/theme';
 import { GrowiThemes } from '~/interfaces/theme';
 
 
-
 export type CommonProps = {
 export type CommonProps = {
   namespacesRequired: string[], // i18next
   namespacesRequired: string[], // i18next
   currentPathname: string,
   currentPathname: string,
@@ -106,3 +106,19 @@ export const useCustomTitleForPage = (props: CommonProps, pagePath: string): str
     .replace('{{page}}', dPagePath.latter) // for backward compatibility
     .replace('{{page}}', dPagePath.latter) // for backward compatibility
     .replace('{{pagename}}', dPagePath.latter);
     .replace('{{pagename}}', dPagePath.latter);
 };
 };
+
+export const addActivity = async(context: GetServerSidePropsContext, action: SupportedActionType): Promise<void> => {
+  const req: CrowiRequest = context.req as CrowiRequest;
+
+  const parameter = {
+    ip:  req.ip,
+    endpoint: req.originalUrl,
+    action,
+    user: req.user?._id,
+    snapshot: {
+      username: req.user?.username,
+    },
+  };
+
+  await req.crowi.activityService.createActivity(parameter);
+};