-
Notifications
You must be signed in to change notification settings - Fork 1
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
7 changed files
with
119 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { BadRequest } = require('@feathersjs/errors'); | ||
|
||
/* eslint-disable no-unused-vars */ | ||
exports.Subjects = class Subjects { | ||
constructor (options, app) { | ||
this.options = options || {}; | ||
this.app = app; | ||
} | ||
|
||
async find (params) { | ||
const subjects = []; | ||
const groups = await this.app.service('group').find(params); | ||
if (params.query && params.query.name) { | ||
params.query.email = params.query.name; | ||
delete params.query.name; | ||
} | ||
const users = await this.app.service('user').find(params); | ||
|
||
users.data.forEach(user => { | ||
subjects.push({ | ||
type: 'user', | ||
id: user._id, | ||
name: user.email | ||
}); | ||
}); | ||
groups.data.forEach(group => { | ||
subjects.push({ | ||
type: 'group', | ||
id: group._id, | ||
name: group.name | ||
}); | ||
}); | ||
return subjects; | ||
} | ||
|
||
async get (id, params) { | ||
throw new BadRequest('Not implemented'); | ||
} | ||
|
||
async create (data, params) { | ||
throw new BadRequest('Not implemented'); | ||
} | ||
|
||
async update (id, data, params) { | ||
throw new BadRequest('Not implemented'); | ||
} | ||
|
||
async patch (id, data, params) { | ||
throw new BadRequest('Not implemented'); | ||
} | ||
|
||
async remove (id, params) { | ||
throw new BadRequest('Not implemented'); | ||
} | ||
}; |
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,33 @@ | ||
const { authenticate } = require('@feathersjs/authentication').hooks; | ||
|
||
module.exports = { | ||
before: { | ||
all: [ authenticate('jwt') ], | ||
find: [], | ||
get: [], | ||
create: [], | ||
update: [], | ||
patch: [], | ||
remove: [] | ||
}, | ||
|
||
after: { | ||
all: [], | ||
find: [], | ||
get: [], | ||
create: [], | ||
update: [], | ||
patch: [], | ||
remove: [] | ||
}, | ||
|
||
error: { | ||
all: [], | ||
find: [], | ||
get: [], | ||
create: [], | ||
update: [], | ||
patch: [], | ||
remove: [] | ||
} | ||
}; |
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,17 @@ | ||
// Initializes the `subjects` service on path `/subjects` | ||
const { Subjects } = require('./subjects.class'); | ||
const hooks = require('./subjects.hooks'); | ||
|
||
module.exports = function (app) { | ||
const options = { | ||
paginate: app.get('paginate') | ||
}; | ||
|
||
// Initialize our service with any options it requires | ||
app.use('/subjects', new Subjects(options, app)); | ||
|
||
// Get our initialized service so that we can register hooks | ||
const service = app.service('subjects'); | ||
|
||
service.hooks(hooks); | ||
}; |
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,10 @@ | ||
const assert = require('assert'); | ||
const app = require('../../src/app'); | ||
|
||
describe('\'subjects\' service', () => { | ||
it('registered the service', () => { | ||
const service = app.service('subjects'); | ||
|
||
assert.ok(service, 'Registered the service'); | ||
}); | ||
}); |