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,6 +46,7 @@ describe( 'Streams', ( ) => {
|
|||
|
||||
} )
|
||||
|
||||
describe( 'Base CRUD', ( ) => {
|
||||
it( 'Should create a stream', async ( ) => {
|
||||
testStream.id = await createStream( testStream, userOne.id )
|
||||
expect( testStream ).to.have.property( 'id' )
|
||||
|
@ -71,6 +72,7 @@ describe( 'Streams', ( ) => {
|
|||
let all = await getStreamsUser( userOne.id )
|
||||
expect( all ).to.have.lengthOf( 2 )
|
||||
} )
|
||||
} )
|
||||
|
||||
describe( 'Sharing', ( ) => {
|
||||
let userTwo = {
|
||||
|
@ -127,11 +129,9 @@ describe( 'Streams', ( ) => {
|
|||
|
||||
} )
|
||||
|
||||
|
||||
|
||||
} )
|
||||
|
||||
describe( 'Integration', ( ) => {
|
||||
describe( 'Integration (API)', ( ) => {
|
||||
|
||||
// The express app
|
||||
let app = null
|
||||
|
|
Загрузка…
Ссылка в новой задаче