Browse Source

create api V3

itizawa 6 năm trước cách đây
mục cha
commit
0858219a81

+ 5 - 1
src/client/js/components/Me/ExternalAccountLinkedMe.jsx

@@ -10,6 +10,10 @@ import ExternalAccountRow from './ExternalAccountRow';
 
 class ExternalAccountLinkedMe extends React.Component {
 
+  async componentDidMount() {
+    this.props.personalContainer.retrieveExternalAccounts();
+  }
+
   render() {
     const { t, personalContainer } = this.props;
     const { externalAccounts } = personalContainer.state;
@@ -38,7 +42,7 @@ class ExternalAccountLinkedMe extends React.Component {
                 </tr>
               </thead>
               <tbody>
-                {externalAccounts !== 0 && externalAccounts.map(account => <ExternalAccountRow account={account} />)}
+                {externalAccounts !== 0 && externalAccounts.map(account => <ExternalAccountRow account={account} key={account._id} />)}
               </tbody>
             </table>
           </div>

+ 17 - 0
src/client/js/services/PersonalContainer.js

@@ -60,6 +60,23 @@ export default class PersonalContainer extends Container {
     }
   }
 
+  /**
+   * retrieve external accounts that linked me
+   */
+  async retrieveExternalAccounts() {
+    try {
+      const response = await this.appContainer.apiv3.get('/personal-setting/external-accounts');
+      const { externalAccounts } = response.data;
+
+      this.setState({ externalAccounts });
+    }
+    catch (err) {
+      this.setState({ retrieveError: err.message });
+      logger.error(err);
+      toastError(new Error('Failed to fetch data'));
+    }
+  }
+
   /**
    * Change name
    */

+ 16 - 1
src/server/routes/apiv3/personal-setting.js

@@ -21,7 +21,7 @@ module.exports = (crowi) => {
   const csrf = require('../../middleware/csrf')(crowi);
   const { customizeService } = crowi;
 
-  const { User } = crowi.models;
+  const { User, ExternalAccount } = crowi.models;
 
 
   const { ApiV3FormValidator } = crowi.middlewares;
@@ -54,5 +54,20 @@ module.exports = (crowi) => {
     return res.apiv3({ personalParams });
   });
 
+  // TODO swagger
+  router.get('/external-accounts', loginRequiredStrictly, async(req, res) => {
+    const userData = req.user;
+
+    try {
+      const externalAccounts = await ExternalAccount.find({ user: userData });
+      return res.apiv3({ externalAccounts });
+    }
+    catch (err) {
+      logger.error(err);
+      return res.apiv3Err('get-external-accounts-failed');
+    }
+
+  });
+
   return router;
 };