Skip to content

Commit

Permalink
fix(gsuite): add gsuite model (#184)
Browse files Browse the repository at this point in the history
* feat: add gsuite model

* fix(gsuite): fix lint and add to bodies

* chore(body): remove TODO

* chore(circle): remove TODO

* chore(user): remove TODO

Co-authored-by: Rik Smale <wikirik000@gmail.com>
Co-authored-by: Rik Smale <WikiRik@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 9, 2020
1 parent 01163bb commit d5c5534
Show file tree
Hide file tree
Showing 7 changed files with 65 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 @@ -52,7 +52,7 @@ module.exports = {
'user.last_name',
'user.email',
],
MEMBER: ['first_name', 'last_name', 'email'],
MEMBER: ['first_name', 'last_name', 'email', 'gsuite_id'],
PERMISSION: ['combined', 'description']
},
FIELDS_TO_FIND: {
Expand Down
12 changes: 12 additions & 0 deletions migrations/20201025145040-add-gsuiteID-to-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.addColumn(
'users',
'gsuite_id',
{
type: Sequelize.STRING,
allowNull: true,
unique: true
},
),
down: (queryInterface) => queryInterface.removeColumn('users', 'gsuite_id')
};
12 changes: 12 additions & 0 deletions migrations/20201027145040-add-gsuiteID-to-circles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.addColumn(
'circles',
'gsuite_id',
{
type: Sequelize.STRING,
allowNull: true,
unique: true
},
),
down: (queryInterface) => queryInterface.removeColumn('circles', 'gsuite_id')
};
12 changes: 12 additions & 0 deletions migrations/20201125200123-add-gsuiteID-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',
'gsuite_id',
{
type: Sequelize.STRING,
allowNull: true,
unique: true
},
),
down: (queryInterface) => queryInterface.removeColumn('bodies', 'gsuite_id')
};
9 changes: 9 additions & 0 deletions models/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ const Body = sequelize.define('body', {
type: Sequelize.STRING,
allowNull: true
},
gsuite_id: {
type: Sequelize.STRING,
allowNull: true,
validate: {
isEmail: { msg: 'GSuite ID should be a valid email.' }
},
unique: true
}
}, {
underscored: true,
tableName: 'bodies',
Expand All @@ -114,6 +122,7 @@ 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.gsuite_id === 'string') body.gsuite_id = body.gsuite_id.toLowerCase().trim();

if (typeof body.abbreviation === 'string') body.abbreviation = body.abbreviation.trim();
});
Expand Down
10 changes: 10 additions & 0 deletions models/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const Circle = sequelize.define('circle', {
validate: {
notEmpty: { msg: 'Description should be set.' },
},
},
gsuite_id: {
type: Sequelize.STRING,
allowNull: true,
validate: {
isEmail: { msg: 'GSuite ID should be a valid email.' }
},
unique: true
}
}, {
underscored: true,
Expand All @@ -26,6 +34,8 @@ const Circle = sequelize.define('circle', {

Circle.beforeValidate(async (circle) => {
// skipping these fields if they are unset, will catch it later.
if (typeof circle.gsuite_id === 'string') circle.gsuite_id = circle.gsuite_id.toLowerCase().trim();

if (typeof circle.name === 'string') circle.name = circle.name.trim();
if (typeof circle.description === 'string') circle.description = circle.description.trim();
});
Expand Down
9 changes: 9 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ const User = sequelize.define('user', {
last_active: {
type: Sequelize.DATE,
allowNull: true
},
gsuite_id: {
type: Sequelize.STRING,
allowNull: true,
validate: {
isEmail: { msg: 'GSuite ID should be a valid email.' }
},
unique: true
}
}, {
underscored: true,
Expand All @@ -161,6 +169,7 @@ User.beforeValidate(async (user) => {
// skipping these fields if they are unset, will catch it later.
if (typeof user.email === 'string') user.email = user.email.toLowerCase().trim();
if (typeof user.username === 'string') user.username = user.username.toLowerCase().trim();
if (typeof user.gsuite_id === 'string') user.gsuite_id = user.gsuite_id.toLowerCase().trim();

if (typeof user.first_name === 'string') user.first_name = user.first_name.trim();
if (typeof user.last_name === 'string') user.last_name = user.last_name.trim();
Expand Down

0 comments on commit d5c5534

Please sign in to comment.