Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.removeConstraint('organization_user_invites', 'org_user_invites_email_key')
},

async down(queryInterface, Sequelize) {
await queryInterface.addConstraint('organization_user_invites', {
fields: ['email'],
type: 'unique',
name: 'org_user_invites_email_key',
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
// Remove the current primary key constraint
await queryInterface.removeConstraint('users_credentials', 'users_credentials_pkey')

// Add the 'email' column as the new primary key
await queryInterface.addConstraint('users_credentials', {
fields: ['email'],
type: 'primary key',
name: 'users_credentials_pkey',
})
},

async down(queryInterface, Sequelize) {
// Remove the current primary key constraint
await queryInterface.removeConstraint('users_credentials', 'users_credentials_email_pkey')

// Recreate the primary key constraint on the 'id' column
await queryInterface.addConstraint('users_credentials', {
fields: ['id'],
type: 'primary key',
name: 'users_credentials_pkey',
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
// Remove the current primary key constraint
await queryInterface.removeConstraint('organization_user_invites', 'org_user_invites_pkey')

// Add the 'id' and 'organization_id' columns as the new composite primary key
await queryInterface.addConstraint('organization_user_invites', {
fields: ['id', 'organization_id'],
type: 'primary key',
name: 'org_user_invites_pkey',
})
},

async down(queryInterface, Sequelize) {
// Remove the current primary key constraint
await queryInterface.removeConstraint('organization_user_invites', 'org_user_invites_pkey')

// Recreate the primary key constraint on the 'id' column
await queryInterface.addConstraint('organization_user_invites', {
fields: ['id'],
type: 'primary key',
name: 'org_user_invites_pkey',
})
},
}
1 change: 1 addition & 0 deletions src/database/models/organizationUserInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = (sequelize, DataTypes) => {
organization_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
roles: {
type: DataTypes.ARRAY(DataTypes.INTEGER),
Expand Down
2 changes: 1 addition & 1 deletion src/database/models/userCredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module.exports = (sequelize, DataTypes) => {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
primaryKey: true,
},
password: {
type: DataTypes.STRING,
Expand Down
4 changes: 2 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"LOGGED_IN_SUCCESSFULLY": "User logged in successfully.",
"LOGGED_OUT_SUCCESSFULLY": "User logged out successfully.",
"UNAUTHORIZED_REQUEST": "Unauthorized request",
"REFRESH_TOKEN_EXPIRED": "Refresh token expired",
"REFRESH_TOKEN_EXPIRED": "Oops! Your session has expired. Please log in again.",
"ACCESS_TOKEN_EXPIRED": "Session expired. Please login again.",
"ACCESS_TOKEN_GENERATED_SUCCESSFULLY": "Access token generated successfully",
"INVALID_REFRESH_TOKEN": "Invalid refresh token",
"REFRESH_TOKEN_NOT_FOUND": "Refresh token not found",
"REFRESH_TOKEN_NOT_FOUND": "Oops! Your session has expired. Please log in again.",
"PROFILE_UPDATED_SUCCESSFULLY": "Profile updated successfully.",
"PROFILE_FETCHED_SUCCESSFULLY": "Profile fetched successfully.",
"FORM_ALREADY_EXISTS": "Form already exists",
Expand Down
6 changes: 5 additions & 1 deletion src/services/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = class AccountHelper {
if (invitedUserId) {
invitedUserMatch = await userInviteQueries.findOne({
id: invitedUserId.organization_user_invite_id,
})
}) //add org id here to optimize the query
}

let isOrgAdmin = false
Expand Down Expand Up @@ -435,6 +435,10 @@ module.exports = class AccountHelper {
const prunedEntities = removeDefaultOrgEntityTypes(validationData, user.organization_id)
user = utils.processDbResponse(user, prunedEntities)

if (user && user.image) {
user.image = await utils.getDownloadableUrl(user.image)
}

const result = { access_token: accessToken, refresh_token: refreshToken, user }

return common.successResponse({
Expand Down
2 changes: 1 addition & 1 deletion src/services/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = class AdminHelper {
const update = _.merge(removeKeys, updateParams)
await userQueries.updateUser({ email: user.email }, update)
delete update.id
await UserCredentialQueries.updateUser({ user_id: userId }, update)
await UserCredentialQueries.updateUser({ email: user.email }, update)

await utils.redisDel(common.redisUserPrefix + userId.toString())

Expand Down