Parcourir la source

Move logic to AttachmentService

Shun Miyazawa il y a 3 ans
Parent
commit
75c904b6d4

+ 3 - 3
packages/app/src/server/middlewares/certify-brand-logo.ts

@@ -1,10 +1,10 @@
-export const generateCertifyBrandLogo = (crowi) => {
+export const generateCertifyBrandLogoMiddleware = (crowi) => {
 
   return async(req, res, next) => {
 
-    const Attachment = crowi.model('Attachment');
+    const { attachmentService } = crowi;
 
-    if (Attachment.isBrandLogoExist()) {
+    if (attachmentService.isBrandLogoExist()) {
       req.isBrandLogo = true;
     }
 

+ 0 - 4
packages/app/src/server/models/attachment.js

@@ -79,10 +79,6 @@ module.exports = function(crowi) {
     return attachment;
   };
 
-  attachmentSchema.statics.isBrandLogoExist = function() {
-    return this.findOne({ attachmentType: AttachmentType.BRAND_LOGO }) != null;
-  };
-
   attachmentSchema.methods.getValidTemporaryUrl = function() {
     if (this.temporaryUrlExpiredAt == null) {
       return null;

+ 2 - 1
packages/app/src/server/routes/index.js

@@ -3,6 +3,7 @@ import express from 'express';
 
 import { generateAddActivityMiddleware } from '../middlewares/add-activity';
 import apiV1FormValidator from '../middlewares/apiv1-form-validator';
+import { generateCertifyBrandLogoMiddleware } from '../middlewares/certify-brand-logo';
 import injectResetOrderByTokenMiddleware from '../middlewares/inject-reset-order-by-token-middleware';
 import injectUserRegistrationOrderByTokenMiddleware from '../middlewares/inject-user-registration-order-by-token-middleware';
 import * as loginFormValidator from '../middlewares/login-form-validator';
@@ -30,7 +31,7 @@ module.exports = function(crowi, app) {
   const loginRequired = require('../middlewares/login-required')(crowi, true);
   const adminRequired = require('../middlewares/admin-required')(crowi);
   const certifySharedFile = require('../middlewares/certify-shared-file')(crowi);
-  const certifyBrandLogo = require('../middlewares/certify-brand-logo')(crowi);
+  const certifyBrandLogo = generateCertifyBrandLogoMiddleware(crowi);
   const rateLimiter = require('../middlewares/rate-limiter')();
   const addActivity = generateAddActivityMiddleware(crowi);
 

+ 7 - 0
packages/app/src/server/service/attachment.js

@@ -1,5 +1,7 @@
 import loggerFactory from '~/utils/logger';
 
+import { AttachmentType } from '../interfaces/attachment';
+
 const fs = require('fs');
 
 const mongoose = require('mongoose');
@@ -77,6 +79,11 @@ class AttachmentService {
     return;
   }
 
+  isBrandLogoExist() {
+    const Attachment = this.crowi.model('Attachment');
+    return Attachment.findOne({ attachmentType: AttachmentType.BRAND_LOGO }) != null;
+  }
+
 }
 
 module.exports = AttachmentService;