UCDavisLibrary / ucdlib-travel

Travel Request Application for the UC Davis Library
0 stars 0 forks source link

Sb email notification #78

Closed sbagg closed 2 months ago

sbagg commented 3 months ago

This is an initial working notification. It is all functional just want to make sure if there is a better way of doing it. I used this data setup below as how I imagine a payload would be inserted but it probably has too much information. Let me know what changes are needed!

 let ar = await this.ApprovalRequestModel.query({revisionIds:[1]});

    let subject = `Requestor: {{requesterFullName}} Submitted Status`

    let content = `
    Hi {{requesterFirstName}},

    Your travel, training, or professional development request has been successfully submitted. 
    It has been sent to {{nextApproverFullName}} for approval.

    You may cancel, resubmit, or view the status of this request at anytime by going to the following url: 
    {{approvalRequestUrl}}
    `;

    const payload = {
      "emailContent": {
        from: 'ucdlib-travel@example.com',
        to: 'sabaggett@ucdavis.edu',
        subject: subject,
        text: content
      },
      "requests": {
        approvalRequest: ar.payload.data[0],
        reimbursementRequest: {},
        token: this.AuthModel.getToken().token,
        type: 'approval-requested'
      }
    }

    const promises = [

      this.NotificationModel.createNotificationComments(payload),
      this.NotificationModel.getNotificationHistory()

    ]
    const resolvedPromises = await Promise.allSettled(promises);
    return promiseUtils.flattenAllSettledResults(resolvedPromises);
  }

  _onNotificationComments(e) {
    if ( e.state !== 'loaded' ) return;

    console.log("Created Notification:", e);
  }

     _onNotificationHistory(e) {
      if ( e.state !== 'loaded' ) return;

      console.log("Retrieved Notifications:", e);
    }
sbagg commented 3 months ago

Here is some way of testing the commands I put it in the home page. Not how it will work in final

let ar = await this.ApprovalRequestModel.query({revisionIds:[1]}); let subject =Sample Subject; let content =Sample Question`;

const payloadSystem = {
  "requests": {
    approvalRequest: ar.payload.data[0],
    reimbursementRequest: {},
  }, //requests could be replaced with id
  notificationType: 'request' //notification type
}

const payloadComments = {
  "emailContent": {
    subject: subject,
    text: content
  }, //email content 
  "url": "approval-request/1", //url
  "requests": {
    approvalRequest: ar.payload.data[0],
    reimbursementRequest: {},
  }, //requests could be replaced with id
  notificationType: 'request' //notification type
}

  this.NotificationModel.createSystemNotification(payloadSystem),
  this.NotificationModel.createNotificationComments(payloadComments),
  this.NotificationModel.getNotificationHistory()

_onNotificationSystems(e) { if ( e.state !== 'loaded' ) return;

console.log("Created Notification System:", e);

}

_onNotificationComments(e) { if ( e.state !== 'loaded' ) return;

console.log("Created Notification Comments:", e);

}

_onNotificationHistory(e) { if ( e.state !== 'loaded' ) return;

  console.log("Retrieved No:", e);

} `