Skip to content

Commit

Permalink
Fix #1293 : Telegram messages should be formatted with the right user…
Browse files Browse the repository at this point in the history
… unit preferences
  • Loading branch information
Pierre-Gilles committed Nov 12, 2021
1 parent 7ed2d52 commit a78af0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 15 additions & 3 deletions server/lib/user/user.getByTelegramUserId.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ const { NotFoundError } = require('../../utils/coreErrors');
async function getByTelegramUserId(telegramUserId) {
const user = await db.User.findOne({
where: { telegram_user_id: telegramUserId },
attributes: ['id', 'language'],
raw: true,
attributes: [
'id',
'firstname',
'lastname',
'selector',
'email',
'language',
'birthdate',
'role',
'temperature_unit_preference',
'distance_unit_preference',
'created_at',
'updated_at',
],
});
if (user === null) {
throw new NotFoundError(`User with telegram_user_id "${telegramUserId}" not found`);
}
return user;
return user.get({ plain: true });
}

module.exports = {
Expand Down
10 changes: 10 additions & 0 deletions server/test/lib/user/user.getByTelegramUserId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ describe('user.getByTelegramUserId', () => {
const userFound = await user.getByTelegramUserId('555555555');
expect(userFound).to.deep.equal({
id: '0cd30aef-9c4e-4a23-88e3-3547971296e5',
firstname: 'John',
lastname: 'Doe',
selector: 'john',
email: 'demo@demo.com',
language: 'en',
birthdate: '12/12/1990',
temperature_unit_preference: 'celsius',
distance_unit_preference: 'metric',
role: 'admin',
created_at: new Date('2019-02-12T07:49:07.556Z'),
updated_at: new Date('2019-02-12T07:49:07.556Z'),
});
});
it('should throw notFound error', async () => {
Expand Down

0 comments on commit a78af0a

Please sign in to comment.