feat(services): added public streams only filter for getting user's commits
This commit is contained in:
@@ -133,8 +133,10 @@ module.exports = {
|
||||
return { commits: rows, cursor: rows.length > 0 ? rows[ rows.length - 1 ].createdAt : null }
|
||||
},
|
||||
|
||||
async getCommitsByUserId( { userId, limit, cursor } ) {
|
||||
async getCommitsByUserId( { userId, limit, cursor, publicOnly } ) {
|
||||
limit = limit || 20
|
||||
publicOnly = publicOnly !== false
|
||||
|
||||
let query =
|
||||
Commits( )
|
||||
.columns( [ 'commitId', 'message', 'referencedObject', 'commits.createdAt', { streamId: 'stream_commits.streamId' }, { streamName: 'streams.name' } ] ).select( )
|
||||
@@ -142,10 +144,14 @@ module.exports = {
|
||||
.join( 'streams', 'stream_commits.streamId', 'streams.id' )
|
||||
.where( 'author', userId )
|
||||
|
||||
if ( publicOnly )
|
||||
query.andWhere( 'streams.isPublic', true )
|
||||
|
||||
if ( cursor )
|
||||
query.andWhere( 'commits.createdAt', '<', cursor )
|
||||
|
||||
query.orderBy( 'commits.createdAt', 'desc' ).limit( limit )
|
||||
|
||||
let rows = await query
|
||||
return { commits: rows, cursor: rows.length > 0 ? rows[ rows.length - 1 ].createdAt : null }
|
||||
},
|
||||
|
||||
@@ -152,14 +152,22 @@ describe( 'Commits', ( ) => {
|
||||
let { commits, cursor } = await getCommitsByUserId( { userId: user.id, limit: 3 } )
|
||||
|
||||
let { commits: commits2, cursor: cursor2 } = await getCommitsByUserId( { userId: user.id, limit: 100, cursor: cursor } )
|
||||
|
||||
|
||||
expect( commits.length ).to.equal( 3 )
|
||||
expect( commits2.length ).to.equal( 20 )
|
||||
} )
|
||||
|
||||
it( 'Should get the public commits of an user only', async ( ) => {
|
||||
let privateStreamId = await createStream( { name: 'private', isPublic: false, ownerId: user.id } )
|
||||
let commitId = await createCommitByBranchName( { streamId: privateStreamId, branchName: 'master', message: 'first commit', objectId: testObject.id, authorId: user.id } )
|
||||
|
||||
let { commits, cursor } = await getCommitsByUserId( { userId: user.id, limit: 1000 } )
|
||||
expect( commits.length ).to.equal( 23 )
|
||||
} )
|
||||
|
||||
it( 'Should get the commit count of an user', async ( ) => {
|
||||
let c = await getCommitsTotalCountByUserId( { userId: user.id } )
|
||||
expect( c ).to.equal( 23 )
|
||||
expect( c ).to.equal( 24 )
|
||||
} )
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user