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>
|
</script>
|
||||||
|
|
||||||
<div class="progress" class:visible style:--progress={progress}>
|
<div class="progress" class:visible style:--progress={progress}>
|
||||||
<div class="track"></div>
|
<div class="track" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
<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) => {
|
.post('/update/profile', requireAuth, zValidator('json', updateProfileDto), limiter({ limit: 10, minutes: 60 }), async (c) => {
|
||||||
const user = c.var.user;
|
const user = c.var.user;
|
||||||
|
console.log('user id', user.id);
|
||||||
const { firstName, lastName, username } = c.req.valid('json');
|
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' });
|
return c.json({ status: 'success' });
|
||||||
})
|
})
|
||||||
.post('/update/email', requireAuth, zValidator('json', updateEmailDto), limiter({ limit: 10, minutes: 60 }), async (c) => {
|
.post('/update/email', requireAuth, zValidator('json', updateEmailDto), limiter({ limit: 10, minutes: 60 }), async (c) => {
|
||||||
const user = c.var.user;
|
const user = c.var.user;
|
||||||
const { email } = c.req.valid('json');
|
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' });
|
return c.json({ status: 'success' });
|
||||||
})
|
})
|
||||||
.post('/logout', requireAuth, async (c) => {
|
.post('/logout', requireAuth, async (c) => {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export type UpdateWishlist = Partial<CreateWishlist>;
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class WishlistsRepository {
|
export class WishlistsRepository {
|
||||||
constructor(@inject(DatabaseProvider) private readonly db: DatabaseProvider) { }
|
constructor(@inject(DatabaseProvider) private readonly db: DatabaseProvider){ }
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return this.db.query.wishlists.findMany();
|
return this.db.query.wishlists.findMany();
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,24 @@ export class IamService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateProfile(userId: string, data: UpdateProfileDto) {
|
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, {
|
return this.usersService.updateUser(userId, {
|
||||||
first_name: data.firstName,
|
first_name: data.firstName,
|
||||||
last_name: data.lastName,
|
last_name: data.lastName,
|
||||||
username: data.username
|
username: data.username !== user.username ? data.username : user.username
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue