From a86c2986ffbc9f0f470c8c3ab968dc247c9ae5a6 Mon Sep 17 00:00:00 2001 From: zezemanolo Date: Mon, 6 Mar 2017 11:33:11 -0800 Subject: [PATCH 1/4] adds artifact for abnormal-hyena --- artifacts/abnormal-hyena.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 artifacts/abnormal-hyena.md diff --git a/artifacts/abnormal-hyena.md b/artifacts/abnormal-hyena.md new file mode 100644 index 0000000..50ac582 --- /dev/null +++ b/artifacts/abnormal-hyena.md @@ -0,0 +1,20 @@ +# abnormal-hyena @hjbowers @zezemanolo +## Description +Working on Noob's task view interface. + +## Project Specs +- [ ] [Issue #91:](https://github.com/GuildCrafts/noob/issues/91) Create CRUD for tags +- [ ] [Issue #92:](https://github.com/GuildCrafts/noob/issues/92) Add Admin page UI for 'tags' CRUD + +## Quality +* Making sure all tests pass. +* Make sure all new code has tests. +* Test React components as well. + +* Commit messages are concise and descriptive +* Every pull request has a description summarizing the changes made. + +* Code is easily readable with descriptive variable names. +* No stray comments and console logs left in code. +* Formatting is accounted for (whitespace, etc.) +* All frontend code has basic styling From 6b7568322673636f1338b8dfd7d74d2b775f099f Mon Sep 17 00:00:00 2001 From: zezemanolo Date: Mon, 6 Mar 2017 11:45:55 -0800 Subject: [PATCH 2/4] updates md file --- artifacts/abnormal-hyena.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/artifacts/abnormal-hyena.md b/artifacts/abnormal-hyena.md index 50ac582..33e7213 100644 --- a/artifacts/abnormal-hyena.md +++ b/artifacts/abnormal-hyena.md @@ -1,6 +1,6 @@ # abnormal-hyena @hjbowers @zezemanolo ## Description -Working on Noob's task view interface. +Working on Noob's Admin page(back end and front end). ## Project Specs - [ ] [Issue #91:](https://github.com/GuildCrafts/noob/issues/91) Create CRUD for tags From 30f32975ec7031b665f35a2c827dc41fca164052 Mon Sep 17 00:00:00 2001 From: zezemanolo Date: Mon, 6 Mar 2017 17:25:30 -0800 Subject: [PATCH 3/4] adds tag migration, query, route, and test --- .gitignore | 3 +- src/database/migrations/20170306153436_tag.js | 17 ++++++++++ src/database/queries/tag.js | 18 ++++++++++ src/routes/tag.js | 33 ++++++++++++++++++ tests/queries_tests/tag_test.js | 34 +++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/database/migrations/20170306153436_tag.js create mode 100644 src/database/queries/tag.js create mode 100644 src/routes/tag.js create mode 100644 tests/queries_tests/tag_test.js diff --git a/.gitignore b/.gitignore index 19536cc..1b6fca8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules npm-debug.log src/public/dist/* .DS_Store -./idm \ No newline at end of file +./idm +.npmrc diff --git a/src/database/migrations/20170306153436_tag.js b/src/database/migrations/20170306153436_tag.js new file mode 100644 index 0000000..5033f80 --- /dev/null +++ b/src/database/migrations/20170306153436_tag.js @@ -0,0 +1,17 @@ + +exports.up = function(knex, Promise) { + + return Promise.all([ + knex.schema.createTable('tag', function(table) { + table.increments('id').primary(); + table.text('names'); + }) + ]) +}; + +exports.down = function(knex, Promise) { + + return Promise.all([ + knex.schema.dropTable('tag') + ]) +}; diff --git a/src/database/queries/tag.js b/src/database/queries/tag.js new file mode 100644 index 0000000..6bfc01a --- /dev/null +++ b/src/database/queries/tag.js @@ -0,0 +1,18 @@ +import knex from '../knex' +import * as _ from './utilities' + +const add = attributes => + _.createRecord( 'tag', attributes ) + +const getAll = () => + _.findAll( 'tag' ) + .orderBy('names', 'asc') + +const getBy = ( column, data ) => + _.findAllWhere( 'template_task', column, data ) + +const expunge = ( column, data ) => + _.deleteRecord( 'tag', column, data ) + + +export { add, getAll, getBy, expunge } diff --git a/src/routes/tag.js b/src/routes/tag.js new file mode 100644 index 0000000..b904264 --- /dev/null +++ b/src/routes/tag.js @@ -0,0 +1,33 @@ +import express from 'express' +import path from 'path' +import groupBy from 'lodash/groupBy' +import * as tag from '../database/queries/tag' +const router = express.Router() + +router.get('/', function(req, res, next){ + tag.getAll() + .then( results => { + const tags = groupBy(results, tag => tag.names) + res.json(tags) + }) +}) + +router.post('/', function(req, res, next){ + tag.add(req.body) + const newTag = { + names: req.body.names + } + tag.add(newTag) + .then(results => { + res.json(results[0]) + }) +}) + +router.delete('/:id', function(req, res, next){ + const {id} = req.params + tag.expunge('id', id).then(result => { + res.json({message: 'Successfully deleted the tag.'}); + }) +}) + +export default router diff --git a/tests/queries_tests/tag_test.js b/tests/queries_tests/tag_test.js new file mode 100644 index 0000000..6dac67b --- /dev/null +++ b/tests/queries_tests/tag_test.js @@ -0,0 +1,34 @@ +import chai, { expect } from 'chai' +import * as tag from '../../src/database/queries/tag' + +describe('tag', () => { + + const fakeTag = [ + { + names: 'Massage' + }, + { + names: 'Spa' + } + ] + + it('should exist', () => + expect(tag).to.be.a('object') + ) + + it('should return all tags ordered ascending by names', () => + tag.getAll().then( tags => { + expect( fakeTag[0].names ).to.equal('Massage') + expect( fakeTag[1].names ).to.equal('Spa') + }) + ) + + it('deletes a tag by id', () => + tag.expunge('id', 1).then( _ => + tag.getBy('id', 1).then( deletedTag => + expect(deletedTag).to.deep.equal([]) + ) + ) + ) + +}) From 7cd65aea70420fedc38e2010107d05a6079912f5 Mon Sep 17 00:00:00 2001 From: zezemanolo Date: Tue, 7 Mar 2017 11:02:52 -0800 Subject: [PATCH 4/4] finishes testing --- src/database/queries/tag.js | 7 +++++-- tests/queries_tests/tag_test.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/database/queries/tag.js b/src/database/queries/tag.js index 6bfc01a..6a3bf31 100644 --- a/src/database/queries/tag.js +++ b/src/database/queries/tag.js @@ -4,15 +4,18 @@ import * as _ from './utilities' const add = attributes => _.createRecord( 'tag', attributes ) +const deleteAll = () => + _.deleteAll( 'tag' ) + const getAll = () => _.findAll( 'tag' ) .orderBy('names', 'asc') const getBy = ( column, data ) => - _.findAllWhere( 'template_task', column, data ) + _.findAllWhere( 'tag', column, data ) const expunge = ( column, data ) => _.deleteRecord( 'tag', column, data ) -export { add, getAll, getBy, expunge } +export { add, deleteAll, getAll, getBy, expunge } diff --git a/tests/queries_tests/tag_test.js b/tests/queries_tests/tag_test.js index 6dac67b..470082f 100644 --- a/tests/queries_tests/tag_test.js +++ b/tests/queries_tests/tag_test.js @@ -3,7 +3,7 @@ import * as tag from '../../src/database/queries/tag' describe('tag', () => { - const fakeTag = [ + const fakeTags = [ { names: 'Massage' }, @@ -12,14 +12,21 @@ describe('tag', () => { } ] + beforeEach( () => + Promise.all([ + tag.deleteAll(), + tag.add(fakeTags) + ]) + ) + it('should exist', () => expect(tag).to.be.a('object') ) it('should return all tags ordered ascending by names', () => tag.getAll().then( tags => { - expect( fakeTag[0].names ).to.equal('Massage') - expect( fakeTag[1].names ).to.equal('Spa') + expect( fakeTags[0].names ).to.equal('Massage') + expect( fakeTags[1].names ).to.equal('Spa') }) )