jam411 3 лет назад
Родитель
Сommit
9e873df215

+ 6 - 7
packages/app/src/server/routes/apiv3/plugins.ts

@@ -29,7 +29,7 @@ module.exports = (crowi: Crowi): Router => {
 
   router.get('/', loginRequiredStrictly, adminRequired, async(req: Request, res: ApiV3Response) => {
     if (pluginService == null) {
-      return res.apiv3Err(400);
+      throw new Error('\'pluginService\' is not import.');
     }
 
     try {
@@ -43,7 +43,7 @@ module.exports = (crowi: Crowi): Router => {
 
   router.get('/:id', loginRequiredStrictly, adminRequired, validator.pluginIdisRequired, async(req: Request, res: ApiV3Response) => {
     if (pluginService == null) {
-      return res.apiv3Err(400);
+      throw new Error('\'pluginService\' is not import.');
     }
 
     const { id } = req.params;
@@ -60,7 +60,7 @@ module.exports = (crowi: Crowi): Router => {
 
   router.post('/', loginRequiredStrictly, adminRequired, validator.pluginFormValueisRequired, async(req: Request, res: ApiV3Response) => {
     if (pluginService == null) {
-      return res.apiv3Err(400);
+      throw new Error('\'pluginService\' is not import.');
     }
 
     const { pluginInstallerForm: formValue } = req.body;
@@ -76,7 +76,7 @@ module.exports = (crowi: Crowi): Router => {
 
   router.put('/:id/activate', loginRequiredStrictly, adminRequired, validator.pluginIdisRequired, async(req: Request, res: ApiV3Response) => {
     if (pluginService == null) {
-      return res.apiv3Err(400);
+      throw new Error('\'pluginService\' is not import.');
     }
 
     const { id } = req.params;
@@ -92,9 +92,8 @@ module.exports = (crowi: Crowi): Router => {
   });
 
   router.put('/:id/deactivate', loginRequiredStrictly, adminRequired, validator.pluginIdisRequired, async(req: Request, res: ApiV3Response) => {
-
     if (pluginService == null) {
-      return res.apiv3Err(400);
+      throw new Error('\'pluginService\' is not import.');
     }
 
     const { id } = req.params;
@@ -111,7 +110,7 @@ module.exports = (crowi: Crowi): Router => {
 
   router.delete('/:id/remove', loginRequiredStrictly, adminRequired, validator.pluginIdisRequired, async(req: Request, res: ApiV3Response) => {
     if (pluginService == null) {
-      return res.apiv3Err(400);
+      throw new Error('\'pluginService\' is not import.');
     }
 
     const { id } = req.params;

+ 4 - 4
packages/app/src/server/service/plugin.ts

@@ -196,7 +196,7 @@ export class PluginService implements IPluginService {
   /**
    * Get all downloaded plugins
    */
-  async getPlugins(): Promise<any> {
+  async getPlugins(): Promise<GrowiPlugin[]> {
     const entries: GrowiPlugin[] = [];
 
     const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
@@ -206,13 +206,13 @@ export class PluginService implements IPluginService {
       entries.push(growiPlugin);
     });
 
-    return JSON.parse(JSON.stringify(entries));
+    return entries;
   }
 
   /**
    * Get plugin data
    */
-  async getPlugin(pluginId: mongoose.Types.ObjectId): Promise<boolean> {
+  async getPlugin(pluginId: mongoose.Types.ObjectId): Promise<GrowiPlugin> {
     const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
     const growiPlugin = await GrowiPlugin.findById(pluginId);
 
@@ -220,7 +220,7 @@ export class PluginService implements IPluginService {
       throw new Error('No plugin found for this ID.');
     }
 
-    return JSON.parse(JSON.stringify(growiPlugin as GrowiPlugin));
+    return growiPlugin;
   }
 
   /**