in src/dataServices/dynamoDbHelper.ts [71:102]
async getMostRecentUserReadableResource(
resourceType: string,
id: string,
tenantId?: string,
): Promise<GenericResponse> {
const items = await this.getMostRecentResources(resourceType, id, 2, undefined, tenantId);
const latestItemDocStatus: DOCUMENT_STATUS = <DOCUMENT_STATUS>items[0][DOCUMENT_STATUS_FIELD];
if (latestItemDocStatus === DOCUMENT_STATUS.DELETED) {
throw new ResourceNotFoundError(resourceType, id);
}
let item: any = {};
// Latest version that are in LOCKED/PENDING_DELETE/AVAILABLE are valid to be read from
if (
[DOCUMENT_STATUS.AVAILABLE, DOCUMENT_STATUS.PENDING_DELETE, DOCUMENT_STATUS.LOCKED].includes(
latestItemDocStatus,
)
) {
// eslint-disable-next-line prefer-destructuring
item = items[0];
} else if (latestItemDocStatus === DOCUMENT_STATUS.PENDING && items.length > 1) {
// If the latest version of the resource is in PENDING, grab the previous version
// eslint-disable-next-line prefer-destructuring
item = items[1];
} else {
throw new ResourceNotFoundError(resourceType, id);
}
item = DynamoDbUtil.cleanItem(item);
return {
message: 'Resource found',
resource: item,
};
}