AWS Routes

Direct communication with AWS services using the AWS DynamoDB Document Client:

const docClient = new AWS.DynamoDB.DocumentClient();

Create New Data lock record by type and id

POST

/api/aws/data-state/{type}/{id}

builds AWS DynamoDB params object with buildPostParams:

{
  TableName: 'DataState',
  Item: {
    env_entityType_entityId: 'localhost-article-1804542',
    fieldName: 'headline',
    timestamp: 1653422860,
    userData: { name: 'CMS Admin', uid: 'XXXX' },
    payload: 'Example Tipser integration '
  },
  ConditionExpression: 'NOT(env_entityType_entityId = :type AND fieldName = :field AND userData.uid <> :uid)',
  ExpressionAttributeValues: {
    ':type': 'localhost-article-1804542',
    ':field': 'headline',
    ':uid': 'XXXX'
  }
}

The Conditional Expression here, added to the object returned from buildPutParams, is to ensure that when attempting to lock a new data field, if a record already exists and is not owned by the current user it is not overridden.

Sent with put function of the DocumentClient.
Returning:
Success:

{
  success: true,
}

Failure:

{
  success: false,
  message: errorMessage,
  error: errorObject,
}

Error message can be either:
Error: Field is locked by another user or Error: Server error

Update Data lock record by type and id

PUT

/api/aws/data-state/{type}/{id}

builds AWS DynamoDB params object with buildPutParams:

{
  TableName: 'DataState',
  Item: {
    env_entityType_entityId: 'localhost-article-1804542',
    fieldName: 'headline',
    timestamp: 1653422860,
    userData: { name: 'CMS Admin', uid: 'XXXX' },
    payload: 'Example Tipser integration '
  },
}

Sent with put function of the DocumentClient.
Returning:
Success:

{
  success: true,
}

Failure:

{
  success: false,
  message: "Error: Server error",
  error: errorObject,
}

Get Data lock record by type and id

GET

/api/aws/data-state/{type}/{id}

available query params:

Query ParameterDescription
fieldNameName of field to query for individual record
excludeUidUID of user not to include in queried records

If fieldName is included only a single record for that specific field will be returned if on exists.
If no fieldName is included then all the records of the entity of type with id are returned, excluding any records from User if excludeUid is included. This is used to exclude a current users own records.

Sent with query function of the DocumentClient.
Returning:
Success:

{
  success: true,
  data: respone,
}

Failure:

{
  success: false,
  message: "Error: Server error",
  error: errorObject,
}

Delete Data lock record by type and id

DELETE

/api/aws/data-state/{type}/{id}

available query params:

Query ParameterDescription
fieldNameName of field to query for deletion
uidUID of user to delete records for

If fieldName is included only a single record for that specific field will be deleted.
If no fieldName is included then all the records of the entity of type with id for the user with uid are first queried, then iterated over and deleted (this is due to AWS only being able to delete one record per request).

Returning:
Success:

{
  success: true,
}

Failure:

{
  success: false,
  message: "Error: Server error",
  error: errorObject,
}