Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Breeds and species closes #21 #23

Merged
merged 2 commits into from
Jul 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/models/animals.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function (app) {
type: Schema.Types.ObjectId,
required: true
},
race: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Race is a different, quite uglier concept 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already changed that, its not race anymore.

breed: {
type: Schema.Types.ObjectId,
required: false
},
Expand Down
23 changes: 23 additions & 0 deletions src/models/breeds.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


module.exports = function (app) {
const mongooseClient = app.get('mongooseClient');
const { Schema } = mongooseClient;
const breeds = new Schema({
displayName: {
type: String,
required: true
},
default: {
type: Boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some kind of restriction so that only one can be default? I don't know if Mongo (of sql!) has something like this.

I'm thinking about Updates too, if another breed is selected as default, the previous default should be changed to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to do that later. Im gonna create an issue for that.
We need to do that on the breed and species "before" hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#24

default: false,
required: true
}
}, {
collection: 'breeds',
versionKey: false,
timestamp: true
});

return mongooseClient.model('breeds', breeds);
};
23 changes: 23 additions & 0 deletions src/models/species.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


module.exports = function (app) {
const mongooseClient = app.get('mongooseClient');
const { Schema } = mongooseClient;
const species = new Schema({
displayName: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have an ID for breed and species or am I being to relational-SQL style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has an autogenerated id

type: String,
required: true
},
default: {
type: Boolean,
default: false,
required: true
}
}, {
collection: 'species',
versionKey: false,
timestamp: true
});

return mongooseClient.model('species', species);
};
40 changes: 40 additions & 0 deletions src/services/breeds/breeds.hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const local = require('@feathersjs/authentication-local');
const { authenticate } = require('@feathersjs/authentication').hooks;

module.exports = {
before: {
all: [
// authenticate('jwt')
],
find: [],
get: [],
create: [
// local.hooks.hashPassword()
],
update: [],
patch: [],
remove: []
},

after: {
all: [
// local.hooks.protect('password')
],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},

error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
33 changes: 33 additions & 0 deletions src/services/breeds/breeds.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


// Initializes the `Breed` service on path `/breeds`
const createService = require('feathers-mongoose');
const createModel = require('../../models/breeds.model');
const hooks = require('./breeds.hooks');
const m2s = require('mongoose-to-swagger');

module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');

const options = {
Model,
paginate
};

const service = createService(options);

service.docs = {
description: 'A service to manage breeds',
definitions: {
breeds: m2s(Model)
},
'breeds list': {
type: 'array',
items: { $ref: '#definitions/breeds' }
}
};

app.use('/breeds', service);
app.service('breeds').hooks(hooks);
};
4 changes: 4 additions & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
const animals = require('./animals/animals.service.js');
const contracts = require('./contracts/contracts.service.js');
const humans = require('./humans/humans.service.js');
const species = require('./species/species.service.js');
const breeds = require('./breeds/breeds.service.js');
// eslint-disable-next-line no-unused-vars
module.exports = function (app) {
app.configure(animals);
app.configure(contracts);
app.configure(humans);
app.configure(species);
app.configure(breeds);
};
40 changes: 40 additions & 0 deletions src/services/species/species.hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const local = require('@feathersjs/authentication-local');
const { authenticate } = require('@feathersjs/authentication').hooks;

module.exports = {
before: {
all: [
// authenticate('jwt')
],
find: [],
get: [],
create: [
// local.hooks.hashPassword()
],
update: [],
patch: [],
remove: []
},

after: {
all: [
// local.hooks.protect('password')
],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},

error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
33 changes: 33 additions & 0 deletions src/services/species/species.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


// Initializes the `Species` service on path `/species`
const createService = require('feathers-mongoose');
const createModel = require('../../models/species.model');
const hooks = require('./species.hooks');
const m2s = require('mongoose-to-swagger');

module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');

const options = {
Model,
paginate
};

const service = createService(options);

service.docs = {
description: 'A service to manage species',
definitions: {
species: m2s(Model)
},
'species list': {
type: 'array',
items: { $ref: '#definitions/species' }
}
};

app.use('/species', service);
app.service('species').hooks(hooks);
};