Przeglądaj źródła

configure biome for comment feature

Futa Arai 7 miesięcy temu
rodzic
commit
6df959b117

+ 1 - 0
apps/app/.eslintrc.js

@@ -31,6 +31,7 @@ module.exports = {
     'src/linter-checker/**',
     'src/migrations/**',
     'src/features/callout/**',
+    'src/features/comment/**',
   ],
   settings: {
     // resolve path aliases by eslint-import-resolver-typescript

+ 1 - 1
apps/app/src/features/comment/server/events/consts.ts

@@ -3,4 +3,4 @@ export const CommentEvent = {
   UPDATE: 'update',
   DELETE: 'delete',
 } as const;
-export type CommentEvent = typeof CommentEvent[keyof typeof CommentEvent];
+export type CommentEvent = (typeof CommentEvent)[keyof typeof CommentEvent];

+ 48 - 43
apps/app/src/features/comment/server/models/comment.ts

@@ -1,7 +1,5 @@
 import type { IUser } from '@growi/core/dist/interfaces';
-import type {
-  Types, Document, Model, Query,
-} from 'mongoose';
+import type { Document, Model, Query, Types } from 'mongoose';
 import { Schema } from 'mongoose';
 
 import type { IComment } from '~/interfaces/comment';
@@ -11,11 +9,10 @@ import loggerFactory from '~/utils/logger';
 const logger = loggerFactory('growi:models:comment');
 
 export interface CommentDocument extends IComment, Document {
-  removeWithReplies: () => Promise<void>
-  findCreatorsByPage: (pageId: Types.ObjectId) => Promise<CommentDocument[]>
+  removeWithReplies: () => Promise<void>;
+  findCreatorsByPage: (pageId: Types.ObjectId) => Promise<CommentDocument[]>;
 }
 
-
 type Add = (
   pageId: Types.ObjectId,
   creatorId: Types.ObjectId,
@@ -24,38 +21,45 @@ type Add = (
   commentPosition: number,
   replyTo?: Types.ObjectId | null,
 ) => Promise<CommentDocument>;
-type FindCommentsByPageId = (pageId: Types.ObjectId) => Query<CommentDocument[], CommentDocument>;
-type FindCommentsByRevisionId = (revisionId: Types.ObjectId) => Query<CommentDocument[], CommentDocument>;
-type FindCreatorsByPage = (pageId: Types.ObjectId) => Promise<IUser[]>
-type CountCommentByPageId = (pageId: Types.ObjectId) => Promise<number>
+type FindCommentsByPageId = (
+  pageId: Types.ObjectId,
+) => Query<CommentDocument[], CommentDocument>;
+type FindCommentsByRevisionId = (
+  revisionId: Types.ObjectId,
+) => Query<CommentDocument[], CommentDocument>;
+type FindCreatorsByPage = (pageId: Types.ObjectId) => Promise<IUser[]>;
+type CountCommentByPageId = (pageId: Types.ObjectId) => Promise<number>;
 
 export interface CommentModel extends Model<CommentDocument> {
-  add: Add
-  findCommentsByPageId: FindCommentsByPageId
-  findCommentsByRevisionId: FindCommentsByRevisionId
-  findCreatorsByPage: FindCreatorsByPage
-  countCommentByPageId: CountCommentByPageId
+  add: Add;
+  findCommentsByPageId: FindCommentsByPageId;
+  findCommentsByRevisionId: FindCommentsByRevisionId;
+  findCreatorsByPage: FindCreatorsByPage;
+  countCommentByPageId: CountCommentByPageId;
 }
 
-const commentSchema = new Schema<CommentDocument, CommentModel>({
-  page: { type: Schema.Types.ObjectId, ref: 'Page', index: true },
-  creator: { type: Schema.Types.ObjectId, ref: 'User', index: true },
-  revision: { type: Schema.Types.ObjectId, ref: 'Revision', index: true },
-  comment: { type: String, required: true },
-  commentPosition: { type: Number, default: -1 },
-  replyTo: { type: Schema.Types.ObjectId },
-}, {
-  timestamps: true,
-});
+const commentSchema = new Schema<CommentDocument, CommentModel>(
+  {
+    page: { type: Schema.Types.ObjectId, ref: 'Page', index: true },
+    creator: { type: Schema.Types.ObjectId, ref: 'User', index: true },
+    revision: { type: Schema.Types.ObjectId, ref: 'Revision', index: true },
+    comment: { type: String, required: true },
+    commentPosition: { type: Number, default: -1 },
+    replyTo: { type: Schema.Types.ObjectId },
+  },
+  {
+    timestamps: true,
+  },
+);
 
-const add: Add = async function(
-    this: CommentModel,
-    pageId,
-    creatorId,
-    revisionId,
-    comment,
-    commentPosition,
-    replyTo?,
+const add: Add = async function (
+  this: CommentModel,
+  pageId,
+  creatorId,
+  revisionId,
+  comment,
+  commentPosition,
+  replyTo?,
 ): Promise<CommentDocument> {
   try {
     const data = await this.create({
@@ -69,35 +73,36 @@ const add: Add = async function(
     logger.debug('Comment saved.', data);
 
     return data;
-  }
-  catch (err) {
+  } catch (err) {
     logger.debug('Error on saving comment.', err);
     throw err;
   }
 };
 commentSchema.statics.add = add;
 
-commentSchema.statics.findCommentsByPageId = function(id) {
+commentSchema.statics.findCommentsByPageId = function (id) {
   return this.find({ page: id }).sort({ createdAt: -1 });
 };
 
-commentSchema.statics.findCommentsByRevisionId = function(id) {
+commentSchema.statics.findCommentsByRevisionId = function (id) {
   return this.find({ revision: id }).sort({ createdAt: -1 });
 };
 
-commentSchema.statics.findCreatorsByPage = async function(page) {
+commentSchema.statics.findCreatorsByPage = async function (page) {
   return this.distinct('creator', { page }).exec();
 };
 
-commentSchema.statics.countCommentByPageId = async function(page) {
+commentSchema.statics.countCommentByPageId = async function (page) {
   return this.count({ page });
 };
 
-commentSchema.statics.removeWithReplies = async function(comment) {
+commentSchema.statics.removeWithReplies = async function (comment) {
   await this.deleteMany({
-    $or:
-      [{ replyTo: comment._id }, { _id: comment._id }],
+    $or: [{ replyTo: comment._id }, { _id: comment._id }],
   });
 };
 
-export const Comment = getOrCreateModel<CommentDocument, CommentModel>('Comment', commentSchema);
+export const Comment = getOrCreateModel<CommentDocument, CommentModel>(
+  'Comment',
+  commentSchema,
+);

+ 0 - 1
biome.json

@@ -27,7 +27,6 @@
       "!apps/app/public/**",
       "!apps/app/src/client/**",
       "!apps/app/src/components/**",
-      "!apps/app/src/features/comment/**",
       "!apps/app/src/features/external-user-group/**",
       "!apps/app/src/features/growi-plugin/**",
       "!apps/app/src/features/mermaid/**",