Skip to content

Commit

Permalink
feat(body): add abbreviation (#193)
Browse files Browse the repository at this point in the history
* feat(body): add abbreviation

Can be used to store abbreviations for bodies like JC/CD/CEWG/ITC etc.
In the frontend I will add validation so this is not for locals.
This can also be used to generate Google groups for the body

* fix(body): add abbreviation to search and remove toLowerCase
  • Loading branch information
WikiRik committed Nov 30, 2020
1 parent 9b32941 commit 7153e5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
}
},
FIELDS_TO_QUERY: {
BODY: ['code', 'name'],
BODY: ['code', 'name', 'abbreviation'],
CAMPAIGN: ['name', 'url', 'description_short', 'description_long'],
CIRCLE: ['name', 'description'],
JOIN_REQUEST: [
Expand Down
12 changes: 12 additions & 0 deletions migrations/20201125220434-add-abbreviation-to-bodies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.addColumn(
'bodies',
'abbreviation',
{
type: Sequelize.STRING,
allowNull: true,
unique: true
},
),
down: (queryInterface) => queryInterface.removeColumn('bodies', 'abbreviation')
};
7 changes: 7 additions & 0 deletions models/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const Body = sequelize.define('body', {
},
unique: true
},
abbreviation: {
type: Sequelize.STRING,
allowNull: true,
unique: true
},
email: {
type: Sequelize.STRING,
allowNull: true,
Expand Down Expand Up @@ -109,6 +114,8 @@ Body.beforeValidate(async (body) => {
// skipping these fields if they are unset, will catch it later.
if (typeof body.code === 'string') body.code = body.code.toUpperCase().trim();
if (typeof body.email === 'string') body.email = body.email.toLowerCase().trim();

if (typeof body.abbreviation === 'string') body.abbreviation = body.abbreviation.trim();
});

module.exports = Body;

0 comments on commit 7153e5a

Please sign in to comment.