feat(references): added api routes and tests for references

This commit is contained in:
Dimitrie Stefanescu
2020-04-11 17:32:38 +01:00
parent 1527ad2e41
commit a513a7ac8d
9 changed files with 298 additions and 79 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ module.exports = {
async createCommit( req, res, next ) {
try {
let id = await createCommit( req.params.resourceId, req.user.id, req.body )
res.status( 201 ).send( { success: true, id: id } )
res.status( 201 ).send( id )
next( )
} catch ( err ) {
next( err )
@@ -37,7 +37,7 @@ module.exports = {
async createObjects( req, res, next ) {
try {
let hashes = await createObjects( req.params.resourceId, req.user.id, req.body )
let hashes = await createObjects( req.body )
res.status( 201 ).send( hashes )
next( )
} catch ( err ) {
+5 -5
View File
@@ -22,7 +22,9 @@ module.exports = {
async createCommit( streamId, userId, object ) {
object.speckle_type = 'commit'
let hash = await module.exports.createObject( streamId, userId, object )
object.author = userId
let hash = await module.exports.createObject( object )
let query = StreamCommits( ).insert( { stream_id: streamId, commit_id: hash } ).toString( ) + ' on conflict do nothing'
await knex.raw( query )
@@ -38,14 +40,13 @@ module.exports = {
/*
Objects Proper
*/
async createObject( streamId, userId, object ) {
async createObject( object ) {
// Prep tree refs
let objTreeRefs = object.hasOwnProperty( '__tree' ) && object.__tree ? object.__tree.map( entry => {
return { parent: entry.split( '.' )[ 0 ], path: entry }
} ) : [ ]
let insertionObject = prepInsertionObject( object )
insertionObject.author = userId
let q1 = Objects( ).insert( insertionObject ).toString( ) + ' on conflict do nothing'
await knex.raw( q1 )
@@ -58,7 +59,7 @@ module.exports = {
return insertionObject.hash
},
createObjects: async ( streamId, userId, objects ) => {
createObjects: async ( objects ) => {
let batches = [ ]
let maxBatchSize = process.env.MAX_BATCH_SIZE || 1000
objects = [ ...objects ]
@@ -86,7 +87,6 @@ module.exports = {
}
let insertionObject = prepInsertionObject( obj )
insertionObject.author = userId
objsToInsert.push( insertionObject )
hashes.push( insertionObject.hash )