refactor(naming): renamed queries to services
This commit is contained in:
Родитель
4f8a27434a
Коммит
5947385682
|
@ -0,0 +1,30 @@
|
|||
'use strict'
|
||||
const bcrypt = require( 'bcrypt' )
|
||||
const crs = require( 'crypto-random-string' )
|
||||
const root = require( 'app-root-path' )
|
||||
const knex = require( `${root}/db/knex` )
|
||||
|
||||
const Users = ( ) => knex( 'references' )
|
||||
const Streams = ( ) => knex( 'streams' )
|
||||
|
||||
module.exports = {
|
||||
createReference: async ( streamId, reference ) => {
|
||||
|
||||
},
|
||||
|
||||
getReference: async ( ) => {
|
||||
|
||||
},
|
||||
|
||||
getStreamReferences: async ( ) => {
|
||||
|
||||
},
|
||||
|
||||
updateReference: async ( ) => {
|
||||
|
||||
},
|
||||
|
||||
deleteReference: async ( ) => {
|
||||
|
||||
},
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const { getStream, createStream, updateStream } = require( './queries' )
|
||||
const { getStream, createStream, updateStream } = require( './services' )
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ const Streams = ( ) => knex( 'streams' )
|
|||
const Acl = ( ) => knex( 'stream_acl' )
|
||||
|
||||
module.exports = {
|
||||
|
||||
createStream: async ( stream, ownerId ) => {
|
||||
delete stream.id
|
||||
delete stream.created_at
|
||||
|
@ -22,11 +23,6 @@ module.exports = {
|
|||
return Streams( ).where( { id: streamId } ).first( )
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} The streamId you want to update
|
||||
* @param {object} The stream fields you want to update
|
||||
* @return {string} the id of the updated stream
|
||||
*/
|
||||
updateStream: async ( streamId, stream ) => {
|
||||
delete stream.id
|
||||
delete stream.created_at
|
||||
|
@ -44,8 +40,6 @@ module.exports = {
|
|||
let query = Acl( ).insert( { user_id: userId, stream_id: streamId, role: role } ).toString( ) + ` on conflict on constraint stream_acl_pkey do update set role=excluded.role`
|
||||
|
||||
await knex.raw( query )
|
||||
|
||||
|
||||
},
|
||||
|
||||
revokePermissionsStream: async ( streamId, userId ) => {
|
|
@ -10,7 +10,7 @@ chai.use( chaiHttp )
|
|||
|
||||
const knex = require( `${root}/db/knex` )
|
||||
|
||||
const { createUser, getUser, updateUser, deleteUser, validatePasssword, createToken, revokeToken, revokeTokenById, validateToken, getUserTokens } = require( '../users/queries' )
|
||||
const { createUser, getUser, updateUser, deleteUser, validatePasssword, createToken, revokeToken, revokeTokenById, validateToken, getUserTokens } = require( '../users/services' )
|
||||
|
||||
describe( 'Actors & Tokens', ( ) => {
|
||||
let myTestActor = {
|
||||
|
|
|
@ -10,8 +10,8 @@ const expect = chai.expect
|
|||
chai.use( chaiHttp )
|
||||
|
||||
|
||||
const { createUser, createToken, revokeToken, revokeTokenById, validateToken, getUserTokens } = require( '../users/queries' )
|
||||
const { createStream, getStream, updateStream, deleteStream, getStreamsUser, grantPermissionsStream, revokePermissionsStream } = require( '../streams/queries' )
|
||||
const { createUser, createToken, revokeToken, revokeTokenById, validateToken, getUserTokens } = require( '../users/services' )
|
||||
const { createStream, getStream, updateStream, deleteStream, getStreamsUser, grantPermissionsStream, revokePermissionsStream } = require( '../streams/services' )
|
||||
|
||||
describe( 'Streams', ( ) => {
|
||||
|
||||
|
@ -46,30 +46,32 @@ describe( 'Streams', ( ) => {
|
|||
|
||||
} )
|
||||
|
||||
it( 'Should create a stream', async ( ) => {
|
||||
testStream.id = await createStream( testStream, userOne.id )
|
||||
expect( testStream ).to.have.property( 'id' )
|
||||
expect( testStream.id ).to.not.be.null
|
||||
describe( 'Base CRUD', ( ) => {
|
||||
it( 'Should create a stream', async ( ) => {
|
||||
testStream.id = await createStream( testStream, userOne.id )
|
||||
expect( testStream ).to.have.property( 'id' )
|
||||
expect( testStream.id ).to.not.be.null
|
||||
|
||||
secondTestStream.id = await createStream( secondTestStream, userOne.id )
|
||||
expect( secondTestStream.id ).to.not.be.null
|
||||
} )
|
||||
secondTestStream.id = await createStream( secondTestStream, userOne.id )
|
||||
expect( secondTestStream.id ).to.not.be.null
|
||||
} )
|
||||
|
||||
it( 'Should get a stream', async ( ) => {
|
||||
let stream = await getStream( testStream.id )
|
||||
expect( stream ).to.not.be.null
|
||||
} )
|
||||
it( 'Should get a stream', async ( ) => {
|
||||
let stream = await getStream( testStream.id )
|
||||
expect( stream ).to.not.be.null
|
||||
} )
|
||||
|
||||
it( 'Should update a stream', async ( ) => {
|
||||
let sid = await updateStream( testStream.id, { name: "Modified Name", description: 'Wooot' } )
|
||||
let stream = await getStream( testStream.id )
|
||||
expect( stream.name ).to.equal( 'Modified Name' )
|
||||
expect( stream.description ).to.equal( 'Wooot' )
|
||||
} )
|
||||
it( 'Should update a stream', async ( ) => {
|
||||
let sid = await updateStream( testStream.id, { name: "Modified Name", description: 'Wooot' } )
|
||||
let stream = await getStream( testStream.id )
|
||||
expect( stream.name ).to.equal( 'Modified Name' )
|
||||
expect( stream.description ).to.equal( 'Wooot' )
|
||||
} )
|
||||
|
||||
it( 'Should get all streams for a user', async ( ) => {
|
||||
let all = await getStreamsUser( userOne.id )
|
||||
expect( all ).to.have.lengthOf( 2 )
|
||||
it( 'Should get all streams for a user', async ( ) => {
|
||||
let all = await getStreamsUser( userOne.id )
|
||||
expect( all ).to.have.lengthOf( 2 )
|
||||
} )
|
||||
} )
|
||||
|
||||
describe( 'Sharing', ( ) => {
|
||||
|
@ -127,11 +129,9 @@ describe( 'Streams', ( ) => {
|
|||
|
||||
} )
|
||||
|
||||
|
||||
|
||||
} )
|
||||
|
||||
describe( 'Integration', ( ) => {
|
||||
describe( 'Integration (API)', ( ) => {
|
||||
|
||||
// The express app
|
||||
let app = null
|
||||
|
|
Загрузка…
Ссылка в новой задаче