Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed asd
Empty file.
17 changes: 7 additions & 10 deletions platforms/pictique-api/src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export class UserController {
// Parse and validate pagination parameters
const pageNum = parseInt(page as string) || 1;
const limitNum = Math.min(parseInt(limit as string) || 10, 50); // Cap at 50 results

if (pageNum < 1 || limitNum < 1) {
return res
.status(400)
.json({ error: "Invalid pagination parameters" });
}

// Parse verified filter
const verifiedOnly = verified === "true";

Expand Down Expand Up @@ -129,13 +129,13 @@ export class UserController {
// Parse and validate pagination parameters
const pageNum = parseInt(page as string) || 1;
const limitNum = Math.min(parseInt(limit as string) || 10, 50); // Cap at 50 results

if (pageNum < 1 || limitNum < 1) {
return res
.status(400)
.json({ error: "Invalid pagination parameters" });
}

// Parse verified filter
const verifiedOnly = verified === "true";

Expand Down Expand Up @@ -172,18 +172,15 @@ export class UserController {
updateProfile = async (req: Request, res: Response) => {
try {
const userId = req.user?.id;
const { handle, avatar, name } = req.body;
const { avatar, name } = req.body;

if (!userId) {
return res.status(401).json({ error: "Unauthorized" });
}

const user = await this.userService.findById(userId);

const updatedUser = await this.userService.updateProfile(userId, {
handle: handle ?? user?.handle,
avatarUrl: avatar ?? user?.avatarUrl,
name: name ?? user?.name,
avatarUrl: avatar,
name,
});

res.json(updatedUser);
Expand Down
5 changes: 2 additions & 3 deletions platforms/pictique-api/src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,14 @@ export class UserService {

async updateProfile(
userId: string,
data: { handle?: string; avatarUrl?: string; name?: string }
data: { avatarUrl?: string; name?: string }
): Promise<User> {
const user = await this.userRepository.findOneBy({ id: userId });
if (!user) {
throw new Error("User not found");
}

// Update only the fields that are provided
if (data.handle !== undefined) user.handle = data.handle;
// Update only the fields that are provided (handle is not updatable)
if (data.avatarUrl !== undefined) user.avatarUrl = data.avatarUrl;
if (data.name !== undefined) user.name = data.name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
async function saveProfileData() {
try {
await apiClient.patch('/api/users/', {
handle,
avatar: profileImageDataUrl,
name
name,
avatar: profileImageDataUrl
});
saved = true;
setTimeout(() => {
Expand Down Expand Up @@ -83,12 +82,12 @@
</div>

<div>
<Label>Change your username</Label>
<Input type="text" placeholder="Edit Username" bind:value={handle} />
<Label>eName</Label>
<Input type="text" placeholder="Your eName" bind:value={handle} disabled class="cursor-not-allowed opacity-70" />
</div>
<div>
<Label>Profile Name</Label>
<Input type="text" placeholder="Edit your public name" bind:value={name} />
<Input type="text" placeholder="Edit your public name" bind:value={name} />
</div>
</div>
<hr class="text-grey" />
Expand Down