Skip to content

Commit

Permalink
do update
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Dec 16, 2024
1 parent 5b7cc52 commit 35d9304
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/services/change-password/change-password.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,28 @@ export class Service {
if (!this.sequelizeClient) {
throw new Error('Sequelize client not available')
}
debug('change-password.create', data, params.user.id)
const user = await User.sequelize(this.sequelizeClient).findOne({
debug('change-password.create', params.user.id)
const userSequelize = User.sequelize(this.sequelizeClient)
const user = await userSequelize.findOne({
where: {
id: params.user.id,
},
})
if (!user) {
if (!user || user.get('id') !== params.user.id) {
throw new NotAuthenticated('User not found')
}
debug('change-password.create', user.get('password'))
const updated = await userSequelize.update(
{
password: User.buildPassword({ password: data.sanitized.password }),
},
{
// criteria
where: { id: params.user.id },
}
)
debug('change-password.create', updated)
return {
id: user.get('id'),
response: 'ok',
}
}
}

0 comments on commit 35d9304

Please sign in to comment.