github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/www/routers/police.router.js (about)

     1  import express from 'express';
     2  
     3  import * as PolicePeer from '../blockchain/policePeer';
     4  
     5  const router = express.Router();
     6  
     7  router.get('/', (req, res) => {
     8    res.render('police', { policeActive: true });
     9  });
    10  
    11  router.post('/api/claims', async (req, res) => {
    12    try {
    13      const theftClaims = await PolicePeer.listTheftClaims();
    14      res.json(theftClaims || []);
    15    } catch (e) {
    16      res.json({ error: 'Error accessing blockchain.' });
    17    }
    18  });
    19  
    20  router.post('/api/process-claim', async (req, res) => {
    21    const { contractUuid, uuid, isTheft, fileReference } = req.body;
    22    if (typeof contractUuid !== 'string'
    23      || typeof uuid !== 'string'
    24      || typeof isTheft !== 'boolean'
    25      || typeof fileReference !== 'string') {
    26      res.json({ error: 'Invalid request.' });
    27      return;
    28    }
    29  
    30    try {
    31      await PolicePeer.processTheftClaim({
    32        contractUuid, uuid, isTheft, fileReference
    33      });
    34      res.json({ success: true, uuid });
    35    } catch (e) {
    36      res.json({ error: 'Error accessing blockchain.' });
    37    }
    38  });
    39  
    40  function wsConfig(io) {
    41    PolicePeer.on('block', block => { io.emit('block', block); });
    42  }
    43  
    44  export default router;
    45  export { wsConfig };