Skip to content

Commit

Permalink
Merge pull request #304 from labzero/develop
Browse files Browse the repository at this point in the history
Merge to master
  • Loading branch information
JeffreyATW authored May 8, 2023
2 parents a0d6e22 + 3a82e64 commit bd9e356
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
15 changes: 15 additions & 0 deletions db/migrations/20230508195724-ChangeUserEmailToCitext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS citext;');
await queryInterface.changeColumn('users', 'email', {
type: Sequelize.CITEXT,
});
},

async down(queryInterface, Sequelize) {
await queryInterface.changeColumn('users', 'email', {
type: Sequelize.STRING
});
await queryInterface.sequelize.query('DROP EXTENSION citext;');
}
};
13 changes: 13 additions & 0 deletions db/migrations/20230508203447-ChangeInvitationEmailToCitext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.changeColumn('invitations', 'email', {
type: Sequelize.CITEXT,
});
},

async down(queryInterface, Sequelize) {
await queryInterface.changeColumn('invitations', 'email', {
type: Sequelize.STRING
});
}
};
3 changes: 3 additions & 0 deletions src/api/main/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export default () => {

return res.status(200).json({ error: false, data: user });
} catch (err) {
if (err.name === 'SequelizeUniqueConstraintError') {
return res.status(422).json({ error: true, data: { message: 'Email is already taken.' } });
}
return next(err);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sequelize, DataTypes } from './db';

const Invitation = sequelize.define('invitation', {
email: {
type: DataTypes.STRING,
type: DataTypes.CITEXT,
allowNull: false,
unique: true
},
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ User.init({
},
googleId: DataTypes.STRING,
name: DataTypes.STRING,
email: DataTypes.STRING,
email: DataTypes.CITEXT,
encryptedPassword: DataTypes.STRING,
resetPasswordToken: DataTypes.STRING,
resetPasswordSentAt: DataTypes.DATE,
Expand Down

0 comments on commit bd9e356

Please sign in to comment.