src/blockchain/projects.js
/**
     * handle `CancelProject` events
     *
     * @param {object} event Web3 event object
     */
handle `CancelProject` events
@param {object} event Web3 event object
handle ` CancelProject ` events @param { object } event Web3 event object
async cancelProject(event) {
      if (event.event !== 'CancelProject') {
        throw new Error('cancelProject only handles CancelProject events');
      }
      const projectId = event.returnValues.idProject;
      try {
        const pledgeAdmin = await getAdmin(projectId);
        const [service, status] =
          pledgeAdmin.type === AdminTypes.CAMPAIGN
            ? [campaigns, CampaignStatus.CANCELED]
            : [traces, TraceStatus.CANCELED];
        const transaction = await getTransaction(app, event.transactionHash);
        await service.patch(
          pledgeAdmin.typeId,
          {
            status,
            mined: true,
          },
          { eventTxHash: event.transactionHash, performedByAddress: transaction.from },
        );
        if (pledgeAdmin.type === AdminTypes.CAMPAIGN) {
          await cancelCampaignMilestones(pledgeAdmin.typeId, event.transactionHash);
        }
        const query = {
          $or: [{ ownerTypeId: pledgeAdmin.typeId }, { intendedProjectTypeId: pledgeAdmin.typeId }],
          amountRemaining: { $ne: 0 },
          status: { $ne: DonationStatus.PAID },
        };
        try {
          const donationsToRevert = await donations.find({ paginate: false, query });
          await Promise.all(
            donationsToRevert.map(donation => revertDonation(donation, event.transactionHash)),
          );
        } catch (error) {
          logger.error('Revert donations of canceled project error:', error);
        }
      } catch (error) {
        if (error.name === 'NotFound') return;
        logger.error('Cancel project error:', error);
      }
    }
async cancelProject ( event ) { if ( event . event !== 'CancelProject' ) { throw new Error ( 'cancelProject only handles CancelProject events' ) ; } const projectId = event . returnValues . idProject ; try { const pledgeAdmin = await getAdmin ( projectId ) ; const [ service , status ] = pledgeAdmin . type === AdminTypes . CAMPAIGN ? [ campaigns , CampaignStatus . CANCELED ] : [ traces , TraceStatus . CANCELED ] ; const transaction = await getTransaction ( app , event . transactionHash ) ; await service . patch ( pledgeAdmin . typeId , { status , mined : true , } , { eventTxHash : event . transactionHash , performedByAddress : transaction . from } , ) ; if ( pledgeAdmin . type === AdminTypes . CAMPAIGN ) { await cancelCampaignMilestones ( pledgeAdmin . typeId , event . transactionHash ) ; } const query = { $or : [ { ownerTypeId : pledgeAdmin . typeId } , { intendedProjectTypeId : pledgeAdmin . typeId } ] , amountRemaining : { $ne : 0 } , status : { $ne : DonationStatus . PAID } , } ; try { const donationsToRevert = await donations . find ( { paginate : false , query } ) ; await Promise . all ( donationsToRevert . map ( donation => revertDonation ( donation , event . transactionHash ) ) , ) ; } catch ( error ) { logger . error ( 'Revert donations of canceled project error:' , error ) ; } } catch ( error ) { if ( error . name === 'NotFound' ) return ; logger . error ( 'Cancel project error:' , error ) ; } }
handle `CancelProject` events
 @param {object} event Web3 event object
handle ` CancelProject ` events @param { object } event Web3 event object
// update admin entity // revert donations