Explorar el Código

bugfix of Page.api.create

Yuki Takei hace 7 años
padre
commit
892decba90
Se han modificado 1 ficheros con 4 adiciones y 10 borrados
  1. 4 10
      src/server/routes/page.js

+ 4 - 10
src/server/routes/page.js

@@ -753,19 +753,13 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error('Parameters body and path are required.'));
       return res.json(ApiResponse.error('Parameters body and path are required.'));
     }
     }
 
 
-    const ignoreNotFound = true;
-    const createdPage = await Page.findPage(pagePath, req.user, null, ignoreNotFound)
-      .then(function(data) {
-        if (data !== null) {
-          throw new Error('Page exists');
+    const isExist = await Page.count({path: pagePath}) > 0;
+    if (isExist) {
+      return res.json(ApiResponse.error('Page exists'));
         }
         }
 
 
         const options = {grant, grantUserGroupId, socketClientId};
         const options = {grant, grantUserGroupId, socketClientId};
-        return Page.create(pagePath, body, req.user, options);
-      })
-      .catch(function(err) {
-        return res.json(ApiResponse.error(err));
-      });
+    const createdPage = await Page.create(pagePath, body, req.user, options);
 
 
     const result = { page: serializeToObj(createdPage) };
     const result = { page: serializeToObj(createdPage) };
     result.page.lastUpdateUser = User.filterToPublicFields(createdPage.lastUpdateUser);
     result.page.lastUpdateUser = User.filterToPublicFields(createdPage.lastUpdateUser);