Просмотр исходного кода

Merge pull request #4681 from weseek/imprv/81699-organize-types

Imprv/81699 organize types
Yuki Takei 4 лет назад
Родитель
Сommit
9abe98ae75

+ 2 - 5
packages/app/src/components/InAppNotification/InAppNotificationElm.tsx

@@ -2,16 +2,13 @@ import React, { useCallback } from 'react';
 
 import { UserPicture, PagePathLabel } from '@growi/ui';
 import { IInAppNotification } from '~/interfaces/in-app-notification';
+import { HasObjectId } from '~/interfaces/has-object-id';
 import { apiv3Post } from '~/client/util/apiv3-client';
 import FormattedDistanceDate from '../FormattedDistanceDate';
 
-import loggerFactory from '~/utils/logger';
-
-const logger = loggerFactory('growi:InAppNotificationElm');
-
 
 interface Props {
-  notification: IInAppNotification
+  notification: IInAppNotification & HasObjectId
 }
 
 const InAppNotificationElm = (props: Props): JSX.Element => {

+ 3 - 2
packages/app/src/components/InAppNotification/InAppNotificationList.tsx

@@ -1,7 +1,8 @@
 import React, { FC } from 'react';
 
 import { useTranslation } from 'react-i18next';
-import { IInAppNotification, PaginateResult } from '../../interfaces/in-app-notification';
+import { IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
+import { HasObjectId } from '~/interfaces/has-object-id';
 import InAppNotificationElm from './InAppNotificationElm';
 
 
@@ -26,7 +27,7 @@ const InAppNotificationList: FC<Props> = (props: Props) => {
   const notifications = inAppNotificationData.docs;
 
   const renderInAppNotificationList = () => {
-    const inAppNotificationList = notifications.map((notification: IInAppNotification) => {
+    const inAppNotificationList = notifications.map((notification: IInAppNotification & HasObjectId) => {
       return (
         <div className="d-flex flex-row" key={notification._id}>
           <InAppNotificationElm notification={notification} />

+ 13 - 6
packages/app/src/interfaces/in-app-notification.ts

@@ -1,14 +1,21 @@
 import { Types } from 'mongoose';
+import { IUser } from './user';
+import { IPage } from './page';
+
+export enum InAppNotificationStatuses {
+  STATUS_UNREAD = 'UNREAD',
+  STATUS_UNOPENED = 'UNOPENED',
+  STATUS_OPENED = 'OPENED',
+}
 
 export interface IInAppNotification {
-  _id: string
-  user: string
+  user: IUser
   targetModel: 'Page'
-  target: any /* Need to set "Page" as a type" */
+  target: IPage
   action: 'COMMENT' | 'LIKE'
-  status: string
-  actionUsers: any[] /* Need to set "User[]" as a type" */
-  createdAt: string
+  status: InAppNotificationStatuses
+  actionUsers: IUser[]
+  createdAt: Date
 }
 
 /*

+ 4 - 5
packages/app/src/server/models/in-app-notification.ts

@@ -7,10 +7,9 @@ import { getOrCreateModel } from '@growi/core';
 import { ActivityDocument } from './activity';
 import ActivityDefine from '../util/activityDefine';
 
-export const STATUS_UNREAD = 'UNREAD';
-export const STATUS_UNOPENED = 'UNOPENED';
-export const STATUS_OPENED = 'OPENED';
-const STATUSES = [STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED];
+import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
+
+const { STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED } = InAppNotificationStatuses;
 
 export interface InAppNotificationDocument extends Document {
   _id: Types.ObjectId
@@ -66,7 +65,7 @@ const inAppNotificationSchema = new Schema<InAppNotificationDocument, InAppNotif
   status: {
     type: String,
     default: STATUS_UNREAD,
-    enum: STATUSES,
+    enum: [STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED],
     index: true,
     require: true,
   },

+ 4 - 2
packages/app/src/server/service/in-app-notification.ts

@@ -2,10 +2,10 @@ import { Types } from 'mongoose';
 import { subDays } from 'date-fns';
 import Crowi from '../crowi';
 import {
-  InAppNotification, STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED,
+  InAppNotification,
   InAppNotificationDocument,
 } from '~/server/models/in-app-notification';
-import { PaginateResult } from '../../interfaces/in-app-notification';
+import { PaginateResult, InAppNotificationStatuses } from '../../interfaces/in-app-notification';
 
 import { ActivityDocument } from '~/server/models/activity';
 import InAppNotificationSettings from '~/server/models/in-app-notification-settings';
@@ -16,6 +16,8 @@ import { HasObjectId } from '~/interfaces/has-object-id';
 import loggerFactory from '~/utils/logger';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 
+const { STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED } = InAppNotificationStatuses;
+
 const logger = loggerFactory('growi:service:inAppNotification');