-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat 🎸 (be): prepare service and controllers for the users settings * styles 💅 : add setting page and apply layout tweaks * feat 🎸 (wip): progress * feat 🎸 : upload screen functionalities, and update user response shared props * fix ✅ (fe): correct cast * fix ✅ : improve readibility * refactor ✨ : improve routing middlewares * refactor ✨ : improve auth validator and other nits * styles 💅 : improvements on user profile display * fix ✅ (be): delete associations on post delete * test 🧪 : add minimal browser tests for user profile settings * fix ✅ : type correction * fix ✅ (be): review upload external key handling logic
- Loading branch information
1 parent
7076823
commit 1d52657
Showing
29 changed files
with
835 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,57 @@ | ||
import User from '#models/user' | ||
import PostsService from '#services/posts_service' | ||
import { inject } from '@adonisjs/core' | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import { HttpContext } from '@adonisjs/core/http' | ||
import { updateUserValidator } from '#validators/user' | ||
import { errors } from '@vinejs/vine' | ||
import { errorsReducer } from '#utils/index' | ||
import { UserService } from '#services/user_service' | ||
import { UserResponse } from '#interfaces/user' | ||
import { PageObject } from '@adonisjs/inertia/types' | ||
|
||
@inject() | ||
export default class UsersController { | ||
constructor(public readonly service: PostsService) { } | ||
|
||
async show(ctx: HttpContext) { | ||
const currentUserId = ctx.auth.user?.id!; | ||
const profileId = ctx.params.id | ||
const page = ctx.request.qs().page || 1 | ||
const posts = await this.service.findMany(currentUserId, profileId, { page }) | ||
const profile = await User.find(profileId) | ||
return ctx.inertia.render('users/show', { posts, profile }) | ||
constructor(private readonly service: UserService) {} | ||
|
||
async show(ctx: HttpContext): Promise< | ||
| string | ||
| PageObject<{ | ||
user: UserResponse | ||
}> | ||
> { | ||
const user = await this.service.serialize(ctx.auth.user!) | ||
return ctx.inertia.render('users/settings', { user }) | ||
} | ||
|
||
async update(ctx: HttpContext) { | ||
const user = ctx.auth.user! | ||
|
||
try { | ||
const data = await ctx.request.validateUsing(updateUserValidator, { | ||
meta: { | ||
userId: user.id, | ||
}, | ||
}) | ||
|
||
await this.service.update(user, { | ||
name: data.name, | ||
surname: data.surname, | ||
username: data.username, | ||
email: data.email, | ||
}) | ||
|
||
await this.service.storeAttachments(ctx) | ||
|
||
return ctx.inertia.render('users/settings') | ||
} catch (error) { | ||
if (error instanceof errors.E_VALIDATION_ERROR) { | ||
const reducedErrors = errorsReducer(error.messages) | ||
ctx.session.flash('errors', reducedErrors) | ||
} | ||
|
||
return ctx.response.redirect().back() | ||
} | ||
} | ||
|
||
async delete() { | ||
// TODO: Implement. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import { AttachmentResponse } from '#interfaces/attachment' | ||
import { AccountRole } from '#models/user' | ||
import { BaseEntity } from 'app/interfaces/base-entity' | ||
import { UUID } from 'crypto' | ||
|
||
export interface UserResponse extends BaseEntity { | ||
id: UUID | ||
role: AccountRole | ||
name: string | ||
surname: string | ||
name: string | null | ||
surname: string | null | ||
username: string | ||
email: string | ||
attachments: { | ||
cover: AttachmentResponse | null | ||
avatar: AttachmentResponse | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.