Explorar o código

create isBrandLogoExist method

Shun Miyazawa %!s(int64=3) %!d(string=hai) anos
pai
achega
478d8e5089

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

@@ -1,13 +1,10 @@
-import { AttachmentType } from '~/server/interfaces/attachment';
-
-module.exports = (crowi) => {
+export const generateCertifyBrandLogo = (crowi) => {
 
   return async(req, res, next) => {
 
     const Attachment = crowi.model('Attachment');
-    const attachment = await Attachment.findOne({ attachmentType: AttachmentType.BRAND_LOGO });
 
-    if (attachment != null) {
+    if (Attachment.isBrandLogoExist()) {
       req.isBrandLogo = true;
     }
 

+ 3 - 8
packages/app/src/server/models/attachment.js

@@ -51,10 +51,6 @@ module.exports = function(crowi) {
     return `/attachment/${this._id}`;
   });
 
-  attachmentSchema.virtual('brandLogoFilePathProxied').get(function() {
-    return `/attachment/brand-logo/${this._id}`;
-  });
-
   attachmentSchema.virtual('downloadPathProxied').get(function() {
     return `/download/${this._id}`;
   });
@@ -83,6 +79,9 @@ 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) {
@@ -105,9 +104,5 @@ module.exports = function(crowi) {
     return this.save();
   };
 
-  attachmentSchema.methods.isBrandLogo = function() {
-    return this.attachmentType === AttachmentType.BRAND_LOGO;
-  };
-
   return mongoose.model('Attachment', attachmentSchema);
 };