Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gsuite): add gsuite model #184

Merged
merged 5 commits into from
Dec 9, 2020
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 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