Skip to content

Commit

Permalink
fix: issue-3447-redundant-fields-in-session-api (#3664)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihar Tsykala <tsykalaihar@gmail.com>
Co-authored-by: Ihar <igor.tsykala@envisionblockchain.com>
  • Loading branch information
ihar-tsykala and Ihar committed May 30, 2024
1 parent dd846d3 commit d77993f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api-gateway/src/api/service/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class AccountApi {
} catch (error) {
new Logger().error(error, ['API_GATEWAY']);
if (error.message.includes('already exists')) {
throw new HttpException('An account with the same name already exists.', HttpStatus.CONFLICT);
throw new HttpException(error.message, HttpStatus.CONFLICT);
}
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand Down
8 changes: 8 additions & 0 deletions auth-service/src/api/account-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
UserDefaultPermission,
UserRole
} from '@guardian/interfaces';
import { USER_REQUIRED_PROPS } from '../constants/index.js';

const { sign, verify } = pkg;

Expand Down Expand Up @@ -124,6 +125,13 @@ export class AccountService extends NatsService {
}

const user = await new DataBaseHelper(User).findOne({ username: decryptedToken.username });

const userRequiredProps = {}

for(const prop of Object.values(USER_REQUIRED_PROPS)) {
userRequiredProps[prop] = user[prop];
}

return new MessageResponse(setDefaultPermissions(user));
} catch (error) {
return new MessageError(error);
Expand Down
1 change: 1 addition & 0 deletions auth-service/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { REQUIRED_PROPS as USER_REQUIRED_PROPS } from './user.js';
10 changes: 10 additions & 0 deletions auth-service/src/constants/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const REQUIRED_PROPS = {
STATUS_CODE: 'status_code',
REASON: 'reason',
USER_NAME: 'username',
DID: 'did',
PARENT: 'parent',
HEDERA_ACCOUNT_ID: 'hederaAccountId',
ROLE: 'role',
ID: 'id',
};
3 changes: 0 additions & 3 deletions e2e-tests/cypress/e2e/api-tests/accounts/getSession.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ context('Accounts', { tags: '@accounts' }, () => {
expect(response.status).to.eq(STATUS_CODE.OK)
expect(response.body).to.have.property('id')
expect(response.body).to.have.property('username', 'StandardRegistry')
expect(response.body).to.have.property('password')
expect(response.body).to.have.property('did')
expect(response.body).to.have.property('walletToken')
expect(response.body).to.have.property('hederaAccountId')
expect(response.body).to.have.property('role')
})
Expand Down Expand Up @@ -50,7 +48,6 @@ context('Accounts', { tags: '@accounts' }, () => {
}).then((response) => {
expect(response.status).to.eq(200)
expect(response.body).to.have.property('id')
expect(response.body).to.have.property('password')
expect(response.body.role).eq('USER')
})
})
Expand Down

0 comments on commit d77993f

Please sign in to comment.