Sfoglia il codice sorgente

refactor validation

itizawa 5 anni fa
parent
commit
0c5f35e60e

+ 2 - 1
src/client/js/components/ShareLinkForm.jsx

@@ -72,10 +72,11 @@ class ShareLinkForm extends React.Component {
   async handleIssueShareLink() {
     const { t, pageContainer } = this.props;
     const { pageId } = pageContainer.state;
+    const { description } = this.state;
 
     try {
       console.log(this.state);
-      await this.props.appContainer.apiv3.post('/share-links/', { relatedPage: pageId });
+      await this.props.appContainer.apiv3.post('/share-links/', { relatedPage: pageId, description });
       toastSuccess(t('toaster.issue_share_link'));
     }
     catch (err) {

+ 1 - 3
src/server/routes/apiv3/share-links.js

@@ -64,10 +64,8 @@ module.exports = (crowi) => {
   validator.shareLinkStatus = [
     // validate the page id is null
     body('relatedPage').not().isEmpty().withMessage('Page Id is null'),
-
     // validate expireation date is not empty, is not before today and is date.
-    body('expiredAt').isAfter(today.toString()).withMessage('Your Selected date is past'),
-
+    body('expiredAt').if(value => value != null).isAfter(today.toString()).withMessage('Your Selected date is past'),
     // validate the length of description is max 100.
     body('description').isLength({ min: 0, max: 100 }).withMessage('Max length is 100'),