Roughing in users resource
This commit is contained in:
parent
3f0b074619
commit
5048fb7695
11 changed files with 154 additions and 2 deletions
8
app/adapters/user.js
Normal file
8
app/adapters/user.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import DS from 'ember-data';
|
||||
import config from '../config/environment';
|
||||
|
||||
export default DS.RESTAdapter.reopen({
|
||||
namespace: 'api',
|
||||
host: config.apiURL,
|
||||
coalesceFindRequests: true,
|
||||
});
|
10
app/models/user.js
Normal file
10
app/models/user.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
import DS from 'ember-data';
|
||||
|
||||
export default DS.Model.extend({
|
||||
email: DS.attr('string'),
|
||||
name: DS.attr('string'),
|
||||
role: DS.attr('string'),
|
||||
createdAt: DS.attr('date'),
|
||||
updatedAt: DS.attr('date'),
|
||||
deletedAt: DS.attr('date')
|
||||
});
|
|
@ -14,6 +14,7 @@ Router.map(function() {
|
|||
});
|
||||
});
|
||||
this.resource('characteristics', function() {});
|
||||
this.resource('users', function() {});
|
||||
});
|
||||
|
||||
export default Router;
|
||||
|
|
4
app/routes/users.js
Normal file
4
app/routes/users.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
|
7
app/routes/users/index.js
Normal file
7
app/routes/users/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model: function() {
|
||||
return this.store.findAll('user');
|
||||
}
|
||||
});
|
3
app/templates/users/index.hbs
Normal file
3
app/templates/users/index.hbs
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{#each user in model}}
|
||||
{{user.email}}<br>
|
||||
{{/each}}
|
|
@ -21,6 +21,7 @@
|
|||
"devDependencies": {
|
||||
"body-parser": "^1.12.2",
|
||||
"broccoli-asset-rev": "^2.0.2",
|
||||
"connect-restreamer": "^1.0.2",
|
||||
"ember-cli": "0.2.2",
|
||||
"ember-cli-app-version": "0.3.3",
|
||||
"ember-cli-babel": "^4.0.0",
|
||||
|
@ -38,7 +39,7 @@
|
|||
"ember-export-application-global": "^1.0.2",
|
||||
"express": "^4.12.3",
|
||||
"glob": "^4.5.3",
|
||||
"morgan": "^1.5.2",
|
||||
"jsonwebtoken": "^4.2.1"
|
||||
"jsonwebtoken": "^4.2.1",
|
||||
"morgan": "^1.5.2"
|
||||
}
|
||||
}
|
||||
|
|
75
server/mocks/users.js
Normal file
75
server/mocks/users.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
module.exports = function(app) {
|
||||
var express = require('express');
|
||||
var usersRouter = express.Router();
|
||||
|
||||
var USERS = [
|
||||
{
|
||||
id: 1,
|
||||
email: 'testA',
|
||||
name: 'Test Admin User',
|
||||
role: 'A',
|
||||
createdAt: "0001-01-01T00:00:00Z",
|
||||
updatedAt: "0001-01-01T00:00:00Z",
|
||||
deletedAt: null
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
email: 'testR',
|
||||
name: 'Test Read User',
|
||||
role: 'R',
|
||||
createdAt: "0001-01-01T00:00:00Z",
|
||||
updatedAt: "0001-01-01T00:00:00Z",
|
||||
deletedAt: null
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
email: 'testW',
|
||||
name: 'Test Write User',
|
||||
role: 'W',
|
||||
createdAt: "0001-01-01T00:00:00Z",
|
||||
updatedAt: "0001-01-01T00:00:00Z",
|
||||
deletedAt: null
|
||||
}
|
||||
]
|
||||
|
||||
usersRouter.get('/', function(req, res) {
|
||||
var users;
|
||||
if (req.query.ids) {
|
||||
users = USERS.filter(function(u) {
|
||||
return req.query.ids.indexOf(u.id.toString()) > -1;
|
||||
});
|
||||
} else {
|
||||
users = USERS;
|
||||
}
|
||||
res.send({
|
||||
'users': users
|
||||
});
|
||||
});
|
||||
|
||||
usersRouter.post('/', function(req, res) {
|
||||
res.status(201).end();
|
||||
});
|
||||
|
||||
usersRouter.get('/:id', function(req, res) {
|
||||
var user = USERS.filter(function(u) {
|
||||
return u.id == req.params.id;
|
||||
});
|
||||
res.send({
|
||||
'user': user
|
||||
});
|
||||
});
|
||||
|
||||
usersRouter.put('/:id', function(req, res) {
|
||||
res.send({
|
||||
'users': {
|
||||
id: req.params.id
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
usersRouter.delete('/:id', function(req, res) {
|
||||
res.status(204).end();
|
||||
});
|
||||
|
||||
app.use('/api/users', usersRouter);
|
||||
};
|
15
tests/unit/models/user-test.js
Normal file
15
tests/unit/models/user-test.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {
|
||||
moduleForModel,
|
||||
test
|
||||
} from 'ember-qunit';
|
||||
|
||||
moduleForModel('user', {
|
||||
// Specify the other units that are required for this test.
|
||||
needs: []
|
||||
});
|
||||
|
||||
test('it exists', function(assert) {
|
||||
var model = this.subject();
|
||||
// var store = this.store();
|
||||
assert.ok(!!model);
|
||||
});
|
14
tests/unit/routes/users-test.js
Normal file
14
tests/unit/routes/users-test.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import {
|
||||
moduleFor,
|
||||
test
|
||||
} from 'ember-qunit';
|
||||
|
||||
moduleFor('route:users', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['controller:foo']
|
||||
});
|
||||
|
||||
test('it exists', function(assert) {
|
||||
var route = this.subject();
|
||||
assert.ok(route);
|
||||
});
|
14
tests/unit/routes/users/index-test.js
Normal file
14
tests/unit/routes/users/index-test.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import {
|
||||
moduleFor,
|
||||
test
|
||||
} from 'ember-qunit';
|
||||
|
||||
moduleFor('route:users/index', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['controller:foo']
|
||||
});
|
||||
|
||||
test('it exists', function(assert) {
|
||||
var route = this.subject();
|
||||
assert.ok(route);
|
||||
});
|
Reference in a new issue