2021-03-03 - Catalog Standard- Functions

From Izara Wiki
Jump to navigation Jump to search

Service - Catalog Standard

Lambda Functions

Catalog/Get

/**
 * Get details of one catalog record
 * @param {string} catalogId
 *
 * @returns {Object} catalog object
 */

HdrApi

  • Validator: (standard)

Authorizer

  • AppLevel

handler logic

  • (standard)

logic

  1. const catalogGraphServiceName = {from Config table: CatalogGraphServiceName}
  2. const catalog = NPM module - izara-shared#graphSharedLib.getVertexByVertexTagAndVertexUniqueId
    1. graphServiceName: catalogGraphServiceName
    2. vertexTag: NPM module - izara-market-shared#CatalogStandardLib.catalogGraphTag
    3. vertexUniqueId: catalogId
  3. return catalog

Catalog/Create

/**
 * Create a catalog in the category tree
 * @param {string} categoryTreeServiceNameTag
 * @param {string} searchType
 * @param {string (or object?)} filter
 * @param {string (or object?)} requiredData
 * @param {numeric} defaultBrowseQuantity
 * @param {string} catalogName
 * @param {string} languageCode
 * @param {string} userId
 *
 */

Authorizer

  • App level

HdrApi

  • Validator: (standard)

handler logic

  • userId = ?_izContext.authorized/signedInUser..?

logic

  1. const catalogGraphServiceName = {from Config table: CatalogGraphServiceName}
  2. const catalogServiceNameTag = {from Config table: CatalogServiceNameTag}
  3. const translationsGraphServiceName = {from Config table: TranslationsServiceName}
  4. // create the catalog vertex with settings
  5. const catalogId = random uuid
  6. const catalogSettingsVertexProperties =
    1. catalogServiceNameTag: catalogServiceNameTag
    2. categoryTreeServiceNameTag: categoryTreeServiceNameTag
    3. searchType: searchType
    4. filter: filter
    5. requiredData: requiredData
    6. defaultBrowseQuantity: defaultBrowseQuantity
  7. publish message to catalogGraphServiceName InCreateNodeWithVersionedData topic:
    1. vertexTag: NPM module - izara-market-shared#CatalogStandardLib.catalogGraphTag
    2. vertexUniqueId: catalogId
    3. createdByUserId: userId
    4. versionedDataTag: NPM module - izara-shared#graphSharedLib.settingsVersionedDataTag
    5. dataVertexProperties: catalogSettingsVertexProperties
  8. // create catalog name translation
  9. publish message to translationsGraphServiceName InCreateNewSubjectAndTranslation topic:
    1. subjectVertexTag: NPM module - izara-market-shared#CatalogStandardLib.catalogNameGraphTag
    2. subjectVertexUniqueId: catalogId
    3. languageCode: languageCode
    4. translation: catalogName
    5. createdByUserId: userId
  10. // report the new catalog
  11. send message to own OutCatalogCreated topic
    1. catalogId: catalogId
    2. catalogName: catalogName
    3. languageCode: languageCode
    4. userId: userId

Catalog/UpdateSettings

/**
 * Create a catalog in the category tree
 * @param {string} catalogId
 * @param {string} searchType
 * @param {string (or object?)} filter
 * @param {string (or object?)} requiredData
 * @param {numeric} defaultBrowseQuantity
 * @param {string} categoryTreeServiceNameTag
 * @param {string} userId
 *
 */

Authorizer

  • App level

HdrApi

  • Validator: (standard)

handler logic

  • userId = ?_izContext.authorized/signedInUser..?

logic

  1. const catalogGraphServiceName = {from Config table: CatalogGraphServiceName}
  2. const catalogServiceNameTag = {from Config table: CatalogServiceNameTag}
  3. // get existing settings
  4. existingSettings = NPM module - izara-shared#graphSharedLib.getCurrentVersionedDataByVertexTagAndVertexUniqueId
    1. graphServiceName: catalogGraphServiceName
    2. vertexTag: NPM module - izara-market-shared#CatalogStandardLib.catalogGraphTag
    3. vertexUniqueId: catalogId
    4. versionedDataTag: NPM module - izara-shared#graphSharedLib.settingsVersionedDataTag
  5. if data in existingSettings matches new settings
    1. return
  6. // setup the new dataVertexProperties
  7. const dataVertexProperties =
    1. catalogServiceNameTag: catalogServiceNameTag
    2. categoryTreeServiceNameTag: categoryTreeServiceNameTag
    3. searchType: searchType
    4. filter: filter
    5. requiredData: requiredData
    6. defaultBrowseQuantity: defaultBrowseQuantity
  8. // set the timestamp here so we can use this to avoid race conditions when recalculating categoryNode settings
  9. const timestamp = current timestamp
  10. // create new versioned data vertex and edges
  11. publish message to catalogGraphServiceName InCreateVersionedData topic:
    1. vertexTag: NPM module - izara-market-shared#CatalogStandardLib.catalogGraphTag
    2. vertexUniqueId: catalogId
    3. createdByUserId: userId
    4. versionedDataTag: NPM module - izara-shared#graphSharedLib.settingsVersionedDataTag
    5. dataVertexProperties: dataVertexProperties
    6. timestamp: timestamp
  12. // **** start process to rebuild/regenerate other nodes according to these changes, not yet worked out how to do this serverless and avoid race conditions
  13. // report this catalog updated
  14. send message to own OutCatalogUpdated topic
    1. catalogId: catalogId
    2. userId: userId

Functions

...