mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Starting update profile with checks on services.
This commit is contained in:
parent
3ac7de641f
commit
940b485273
4 changed files with 20 additions and 5 deletions
|
|
@ -34,7 +34,7 @@
|
|||
</script>
|
||||
|
||||
<div class="progress" class:visible style:--progress={progress}>
|
||||
<div class="track"></div>
|
||||
<div class="track" />
|
||||
</div>
|
||||
|
||||
<style lang="postcss">
|
||||
|
|
|
|||
|
|
@ -28,14 +28,15 @@ export class IamController implements Controller {
|
|||
})
|
||||
.post('/update/profile', requireAuth, zValidator('json', updateProfileDto), limiter({ limit: 10, minutes: 60 }), async (c) => {
|
||||
const user = c.var.user;
|
||||
console.log('user id', user.id);
|
||||
const { firstName, lastName, username } = c.req.valid('json');
|
||||
await this.iamService.updateProfile(user.id, { first_name: firstName, last_name: lastName, username });
|
||||
const updatedUser = await this.iamService.updateProfile(user.id, { firstName, lastName, username });
|
||||
return c.json({ status: 'success' });
|
||||
})
|
||||
.post('/update/email', requireAuth, zValidator('json', updateEmailDto), limiter({ limit: 10, minutes: 60 }), async (c) => {
|
||||
const user = c.var.user;
|
||||
const { email } = c.req.valid('json');
|
||||
await this.iamService.updateEmail(user.id, email);
|
||||
await this.iamService.updateEmail(user.id, { email });
|
||||
return c.json({ status: 'success' });
|
||||
})
|
||||
.post('/logout', requireAuth, async (c) => {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export type UpdateWishlist = Partial<CreateWishlist>;
|
|||
|
||||
@injectable()
|
||||
export class WishlistsRepository {
|
||||
constructor(@inject(DatabaseProvider) private readonly db: DatabaseProvider) { }
|
||||
constructor(@inject(DatabaseProvider) private readonly db: DatabaseProvider){ }
|
||||
|
||||
async findAll() {
|
||||
return this.db.query.wishlists.findMany();
|
||||
|
|
|
|||
|
|
@ -33,10 +33,24 @@ export class IamService {
|
|||
}
|
||||
|
||||
async updateProfile(userId: string, data: UpdateProfileDto) {
|
||||
const user = await this.usersService.findOneById(userId);
|
||||
if (!user) {
|
||||
return {
|
||||
error: 'User not found'
|
||||
};
|
||||
}
|
||||
|
||||
const existingUserForNewUsername = await this.usersService.findOneByUsername(data.username);
|
||||
if (existingUserForNewUsername && existingUserForNewUsername.id !== userId) {
|
||||
return {
|
||||
error: 'Username already in use'
|
||||
};
|
||||
}
|
||||
|
||||
return this.usersService.updateUser(userId, {
|
||||
first_name: data.firstName,
|
||||
last_name: data.lastName,
|
||||
username: data.username
|
||||
username: data.username !== user.username ? data.username : user.username
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue