Skip to content

Commit

Permalink
route for tags creation
Browse files Browse the repository at this point in the history
  • Loading branch information
imdhruvgupta committed Jul 24, 2019
1 parent 4a73f7b commit dee96c0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 29 deletions.
7 changes: 6 additions & 1 deletion framework/serializers/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ module.exports = function(included = [], type,config) {
if (type === 'deserialize') {
return {
keyForAttribute: 'camelCase',
users: {
valueForRelationship (relationship) {
return relationship.id
}
},
questions: {
valueForRelationship (relationship) {
return relationship.id
Expand All @@ -19,7 +24,7 @@ module.exports = function(included = [], type,config) {
}

const options = {
attributes: ['title', 'user', 'questions', 'createdById'],
attributes: ['title', 'user', 'questions', 'userId'],
user: {
ref: 'id',
attributes: ['firstname', 'lastname', 'email', 'role'],
Expand Down
25 changes: 0 additions & 25 deletions migrations/20180725125530-createQuiz.js

This file was deleted.

2 changes: 1 addition & 1 deletion migrations/20190704180112-tagsMechanism.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false
},
createdById: {
userId: {
type: Sequelize.INTEGER,
reference: {
model: 'users',
Expand Down
2 changes: 1 addition & 1 deletion models/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (sequelize, DataTypes) => {
});

tags.associate = function(models) {
tags.belongsTo(models.users, {foreignKey: 'createdById'}),
tags.belongsTo(models.users),
tags.belongsToMany(models.questions, {through: models.questionsTags})
}

Expand Down
3 changes: 2 additions & 1 deletion routes/api/tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const controller = new BaseController(DB.tags, DB, serializer)

routes.use(passport.authenticate('bearer', {session: false}), adminOnly)

routes.get('/',controller.handleQuery)
routes.get('/', controller.handleQuery)
routes.post('/', controller.handleCreate)

module.exports = routes

0 comments on commit dee96c0

Please sign in to comment.