getDocumentForVersion

The getDocumentForVersion method retrieves a document version when version control is enabled and the versions list doesn't provide documents.

Return Value

Promise<{ version: DocumentVersionWithDocument }>

The version property is a DocumentVersionWithDocument object, which is the same as DocumentVersion, but requires the document property.

This method is only used when getDocumentVersions does not return a document object for each version.

When a version is selected, the getDocumentForVersion method is called to retrieve the document for the provide version ID and document ID.

Parameters

documentId

string

ID value of the document you want to get versions for.

versionId

string

ID value of the version provided from getDocumentVersions.

Example

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
async function getDocumentForVersion({
  documentId,
  versionId,
}: {
  documentId: string
  versionId: string
}): Promise<{ version: DocumentVersionWithDocument }> {
  this.logger.debug('getDocumentForVersion', { documentId, versionId })
  const version = await fetchEntityVersion(this.plainClient, {
    environment: this.environment,
    entityId: documentId,
    versionId,
  })
  const parsedVersion = this.convertVersions([version])[0]
  if (!parsedVersion) {
    throw new Error(
      `Could not parse version ${versionId} for entity ${documentId}`,
    )
  }
  return { version: parsedVersion }
}