Futa Arai 5 месяцев назад
Родитель
Сommit
4676b4e364

+ 4 - 1
apps/app/src/server/models/attachment.ts

@@ -85,6 +85,9 @@ attachmentSchema.statics.createWithoutSave = function (
   fileSize: number,
   fileSize: number,
   attachmentType: AttachmentType,
   attachmentType: AttachmentType,
 ) {
 ) {
+  // biome-ignore lint/complexity/noUselessThisAlias: ignore
+  const Attachment = this;
+
   const extname = path.extname(originalName);
   const extname = path.extname(originalName);
   let fileName = generateFileHash(originalName);
   let fileName = generateFileHash(originalName);
   if (extname.length > 1) {
   if (extname.length > 1) {
@@ -92,7 +95,7 @@ attachmentSchema.statics.createWithoutSave = function (
     fileName = `${fileName}${extname}`;
     fileName = `${fileName}${extname}`;
   }
   }
 
 
-  const attachment = new this();
+  const attachment = new Attachment();
   attachment.page = pageId;
   attachment.page = pageId;
   attachment.creator = user._id;
   attachment.creator = user._id;
   attachment.originalName = originalName;
   attachment.originalName = originalName;

+ 12 - 3
apps/app/src/server/models/bookmark.js

@@ -64,7 +64,10 @@ const factory = (crowi) => {
   };
   };
 
 
   bookmarkSchema.statics.add = async function (page, user) {
   bookmarkSchema.statics.add = async function (page, user) {
-    const newBookmark = new this({ page, user });
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const Bookmark = this;
+
+    const newBookmark = new Bookmark({ page, user });
 
 
     try {
     try {
       const bookmark = await newBookmark.save();
       const bookmark = await newBookmark.save();
@@ -86,8 +89,11 @@ const factory = (crowi) => {
    * @param {string} pageId
    * @param {string} pageId
    */
    */
   bookmarkSchema.statics.removeBookmarksByPageId = async function (pageId) {
   bookmarkSchema.statics.removeBookmarksByPageId = async function (pageId) {
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const Bookmark = this;
+
     try {
     try {
-      const data = await this.remove({ page: pageId });
+      const data = await Bookmark.remove({ page: pageId });
       bookmarkEvent.emit('delete', pageId);
       bookmarkEvent.emit('delete', pageId);
       return data;
       return data;
     } catch (err) {
     } catch (err) {
@@ -97,8 +103,11 @@ const factory = (crowi) => {
   };
   };
 
 
   bookmarkSchema.statics.removeBookmark = async function (pageId, user) {
   bookmarkSchema.statics.removeBookmark = async function (pageId, user) {
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const Bookmark = this;
+
     try {
     try {
-      const data = await this.findOneAndRemove({ page: pageId, user });
+      const data = await Bookmark.findOneAndRemove({ page: pageId, user });
       bookmarkEvent.emit('delete', pageId);
       bookmarkEvent.emit('delete', pageId);
       return data;
       return data;
     } catch (err) {
     } catch (err) {

+ 22 - 8
apps/app/src/server/models/user.js

@@ -521,10 +521,12 @@ const factory = (crowi) => {
   };
   };
 
 
   userSchema.statics.countListByStatus = async function (status) {
   userSchema.statics.countListByStatus = async function (status) {
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const User = this;
     const conditions = { status };
     const conditions = { status };
 
 
     // TODO count は非推奨。mongoose のバージョンアップ後に countDocuments に変更する。
     // TODO count は非推奨。mongoose のバージョンアップ後に countDocuments に変更する。
-    return this.count(conditions);
+    return User.count(conditions);
   };
   };
 
 
   userSchema.statics.isRegisterableUsername = async function (username) {
   userSchema.statics.isRegisterableUsername = async function (username) {
@@ -548,17 +550,19 @@ const factory = (crowi) => {
   };
   };
 
 
   userSchema.statics.isRegisterable = function (email, username, callback) {
   userSchema.statics.isRegisterable = function (email, username, callback) {
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const User = this;
     let emailUsable = true;
     let emailUsable = true;
     let usernameUsable = true;
     let usernameUsable = true;
 
 
     // username check
     // username check
-    this.findOne({ username }, (err, userData) => {
+    User.findOne({ username }, (err, userData) => {
       if (userData) {
       if (userData) {
         usernameUsable = false;
         usernameUsable = false;
       }
       }
 
 
       // email check
       // email check
-      this.findOne({ email }, (err, userData) => {
+      User.findOne({ email }, (err, userData) => {
         if (userData) {
         if (userData) {
           emailUsable = false;
           emailUsable = false;
         }
         }
@@ -590,7 +594,9 @@ const factory = (crowi) => {
   };
   };
 
 
   userSchema.statics.createUserByEmail = async function (email) {
   userSchema.statics.createUserByEmail = async function (email) {
-    const newUser = new this();
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const User = this;
+    const newUser = new User();
 
 
     /* eslint-disable newline-per-chained-call */
     /* eslint-disable newline-per-chained-call */
     const tmpUsername = `temp_${Math.random().toString(36).slice(-16)}`;
     const tmpUsername = `temp_${Math.random().toString(36).slice(-16)}`;
@@ -622,8 +628,11 @@ const factory = (crowi) => {
   };
   };
 
 
   userSchema.statics.createUsersByEmailList = async function (emailList) {
   userSchema.statics.createUsersByEmailList = async function (emailList) {
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const User = this;
+
     // check exists and get list of try to create
     // check exists and get list of try to create
-    const existingUserList = await this.find({
+    const existingUserList = await User.find({
       email: { $in: emailList },
       email: { $in: emailList },
       userStatus: { $ne: STATUS_DELETED },
       userStatus: { $ne: STATUS_DELETED },
     });
     });
@@ -663,11 +672,13 @@ const factory = (crowi) => {
     status,
     status,
     callback,
     callback,
   ) {
   ) {
-    const newUser = new this();
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const User = this;
+    const newUser = new User();
 
 
     // check user upper limit
     // check user upper limit
     const isUserCountExceedsUpperLimit =
     const isUserCountExceedsUpperLimit =
-      await this.isUserCountExceedsUpperLimit();
+      await User.isUserCountExceedsUpperLimit();
     if (isUserCountExceedsUpperLimit) {
     if (isUserCountExceedsUpperLimit) {
       const err = new UserUpperLimitException();
       const err = new UserUpperLimitException();
       return callback(err);
       return callback(err);
@@ -751,8 +762,11 @@ const factory = (crowi) => {
     lang,
     lang,
     status,
     status,
   ) {
   ) {
+    // biome-ignore lint/complexity/noUselessThisAlias: ignore
+    const User = this;
+
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
-      this.createUserByEmailAndPasswordAndStatus(
+      User.createUserByEmailAndPasswordAndStatus(
         name,
         name,
         username,
         username,
         email,
         email,