2020-11-28 - User Contact Manager - Functions

From Izara Wiki
Jump to navigation Jump to search

Service - User Contact Manager

Lambda Functions

ContactMethodCreated

/**
 * Triggered when a contact method handler creates a new contact
 * @param {string} userId
 * @param {string} methodTag
 * @param {string} uniqueId
 * @param {string} contactTag
 *
 */

HdrSqs

Validator:

  • userId cannot be empty string
  • methodTag cannot be empty string
  • uniqueId cannot be empty string
  • contactTag cannot be empty string

logic

  1. put record into UserContacts table
  2. send message to OutUserContactCreated topic:
    1. userId = {userId}
    2. methodTag = {methodTag}
    3. uniqueId = {uniqueId}
    4. contactTag = {contactTag}

CreateNotificationGroup

/**
 * 
 * @param {string} userId
 * @param {string} userContactId
 * @param {string} notificationGroupName
 * @param (boolean} consolidated
 * @param {string} consolidatedType
 * @param {..?} consolidatedFrequency
 * @param {boolean} consolidatedSendIfEmpty
 *
 * @returns {string} notificationGroupUniqueId
 */

HdrApi

Authorizer: User level

Validator:

  • targetUserId cannot be empty string
  • userContactId cannot be empty string

handler logic

when invoking createNotificationGroup targetUserId => userId param

logic

  1. get matching UserContacts record, if none return error to client Save into userContact variable
  2. explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
  3. create notificationGroupUniqueId = userContactId + "_" + new uuid
  4. send message to Service - Notification Manager InCreateNotificationGroup topic:
    1. receiverTag = {methodTag}
    2. groupingId = {userId}
    3. uniqueId = {notificationGroupUniqueId}
    4. notificationGroupName = {notificationGroupName}
    5. consolidated = {consolidated}
    6. consolidatedType = {consolidatedType}
    7. consolidatedFrequency = {consolidatedFrequency}
    8. consolidatedSendIfEmpty = {consolidatedSendIfEmpty}
    9. additionalData = object {userId: userId}
  5. return notificationGroupUniqueId

CreateNotifications

/**
 * 
 * @param {string} userId
 * @param {string} userContactId
 * @param {string} notificationGroupUniqueId
 * @param {Object[]} notifications
 * @param {string} [notifications.notificationName]
 * @param {Object[]} notifications.triggers
 * @param {string} [notifications.triggers.propertyName]
 * @param {string} notifications.triggers.valueType - property|attribute|serviceName|topicName
 * @param {string} [notifications.triggers.value] - either value or values will be set
 * @param {string[]} [notifications.triggers.values] - either value or values will be set
 *
 */

HdrApi

Authorizer: User level

Validator:

  • targetUserId cannot be empty string
  • userContactId cannot be empty string
  • notificationGroupUniqueId cannot be empty string
  • notifications cannot be an empty array? Can limit number of notifications in array?

handler logic

when invoking createNotifications targetUserId => userId param

logic

  1. get matching UserContacts record, if none return error to client. Save into userContact variable
  2. explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
  3. send message to Service - Notification Manager InCreateNotifications topic:
    1. receiverTag = {methodTag}
    2. groupingId = {userId}
    3. uniqueId = {notificationGroupUniqueId}
    4. notifications = {notifications}

UpdateNotificationGroup

/**
 * Updates one notification group
 * @param {string} userId
 * @param {string} userContactId
 * @param {string} notificationGroupUniqueId
 * @param {string} notificationGroupName
 * @param {boolean} consolidated
 * @param {string} consolidatedType
 * @param {..?} consolidatedFrequency
 * @param {boolean} consolidatedSendIfEmpty
 * @param {boolean} enabled
 *
 */

HdrApi

Authorizer: User level

Validator:

  • targetUserId cannot be empty string
  • userContactId cannot be empty string
  • notificationGroupUniqueId cannot be empty string

handler logic

targetUserId > userId param

logic

  1. get matching UserContacts record, if none return error to client. Save into userContact variable
  2. explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
  3. send message to Service - Notification Manager InUpdateNotificationGroup topic:
    1. receiverTag = {methodTag}
    2. groupingId = {userId}
    3. uniqueId = {notificationGroupUniqueId}
    4. notificationGroupName
    5. consolidated
    6. consolidatedType
    7. consolidatedFrequency
    8. consolidatedSendIfEmpty
    9. enabled

DisableNotifications

/**
 * 
 * @param {string} userId
 * @param {string} userContactId
 * @param {string} notificationGroupUniqueId
 * @param {string[]} notificationIds
 *
 */

HdrApi

Authorizer: User level

Validator:

  • targetUserId cannot be empty string
  • userContactId cannot be empty string
  • notificationGroupUniqueId cannot be empty string
  • notificationIds cannot be an empty array? Can limit number of notificationIds in array?

handler logic

when invoking disableNotifications targetUserId => userId param

logic

  1. get matching UserContacts record, if none return error to client. Save into userContact variable
  2. explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
  3. send message to Service - Notification Manager InDisableNotifications topic:
    1. receiverTag = {methodTag}
    2. groupingId = {userId}
    3. uniqueId = {notificationGroupUniqueId}
    4. notificationIds = {notificationIds}

ContactMethod/List

/**
 * Lists all available contact methods for User Contact Manager service
 * 
 * @returns {Object[]} array of objects, each object is one available contact method
 */

HdrApi

Authorizer: App level

Validator:

  • (none)

handler logic

(none)

logic

Query Config table for all ContactMethodServiceName records and return. Client will link to Create endpoint when choose to create a new user contact for a contact method.

UserContact/List

/**
 * Lists all available user contacts for one user
 * @param {string} userId
 *
 * @returns {Object[]} array of objects, each object is one user contact
 */

HdrApi

Authorizer: App level

Validator:

  • targetUserId

handler logic

targetUserId becomes userId param

logic

Query UserContacts table for all records that match userId and return.

Functions

createUserContactId

/**
 * Creates userContactId from its elements
 * @param {string} methodTag
 * @param {string} uniqueId
 *
 * @returns {string} userContactId
 */

module: libs/UserContacts

logic

  1. Concatenate methodTag + "_" + uniqueId

explodeUserContactId

/**
 * Explodes userContactId into its elements
 * @param {string} userContactId
 *
 * @returns {string[]} methodTag and uniqueId
 */

module: libs/UserContacts

logic

  1. Explode userContactId using "_"
  2. Check count of elements = 2
  3. return array of elements