Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
931 additions
and
718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Returns stats relating to the collection. | ||
* | ||
* @param {Object} client - client to check permissions for | ||
* @param {String} documentId - ID of the object to get versions for | ||
* @return {Promise<Stats>} | ||
*/ | ||
function getVersions ({ | ||
client, | ||
documentId | ||
} = {}) { | ||
if (!this.connection.db) { | ||
return Promise.reject( | ||
new Error('DB_DISCONNECTED') | ||
) | ||
} | ||
|
||
let response = { | ||
results: [] | ||
} | ||
|
||
return this.validateAccess({ | ||
client, | ||
type: 'read' | ||
}).then(() => { | ||
if (!this.history) { | ||
const error = new Error('History not enabled for collection') | ||
|
||
error.statusCode = 404 | ||
|
||
return Promise.reject(error) | ||
} | ||
|
||
return this.history.getVersions(documentId).then(({results}) => { | ||
if (results.length === 0) { | ||
return this.count({ | ||
client, | ||
query: { | ||
_id: documentId | ||
} | ||
}).then(({metadata}) => { | ||
if (metadata.totalCount === 0) { | ||
const error = new Error('Document not found') | ||
|
||
error.statusCode = 404 | ||
|
||
return Promise.reject(error) | ||
} | ||
|
||
return results | ||
}) | ||
} | ||
|
||
return results | ||
}).then(results => { | ||
response.results = results | ||
|
||
return response | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = getVersions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.