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
7 changes: 6 additions & 1 deletion apps/api/src/modules/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export const usersService = {
});
}

const updated = await usersRepository.updateUser(userId, patch);
// Role-only updates mutate membership only; `patch` stays empty. Running
// `updateUser` with `{}` produces invalid SQL (UPDATE … SET with no columns).
const updated =
Object.keys(patch).length > 0
? await usersRepository.updateUser(userId, patch)
: await usersRepository.getUserById(userId);
if (!updated) {
throw new NotFoundError("User not found");
}
Expand Down
22 changes: 22 additions & 0 deletions apps/api/tests/integration/users.endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ describe("PUT /api/v1/users/:userId", () => {
});
expect(res.body.createdAt).toBeDefined();
});

it("returns 200 when only role changes (no user row patch)", async () => {
const admin = await registerUser(adminEmail);
adminId = admin.id;
const other = await registerUser(otherEmail);
otherId = other.id;
const adminSession = await loginUser(adminEmail);

const res = await request(app)
.put(`${paths.users}/${other.id}`)
.set("Authorization", `Bearer ${adminSession.token}`)
.send({ role: "tutor" })
.expect("Content-Type", /json/)
.expect(200);

expect(res.body).toMatchObject({
id: other.id,
email: other.email,
role: "tutor",
});
expect(res.body.createdAt).toBeDefined();
});
});

describe("DELETE /api/v1/users/:userId", () => {
Expand Down
7 changes: 3 additions & 4 deletions apps/api/tests/unit/users.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ describe("usersService updateUser", () => {
vi.mocked(usersRepository.getUserByIdInOrganization).mockResolvedValue(
existingUser,
);
vi.mocked(usersRepository.updateUser).mockResolvedValue({
...existingUser,
});
vi.mocked(usersRepository.getUserById).mockResolvedValue(existingUser);
vi.mocked(organizationsRepository.findMembership)
.mockResolvedValueOnce({
organizationId: "org-1",
Expand Down Expand Up @@ -152,7 +150,8 @@ describe("usersService updateUser", () => {
role: "tutor",
});

expect(usersRepository.updateUser).toHaveBeenCalledWith("user-1", {});
expect(usersRepository.updateUser).not.toHaveBeenCalled();
expect(usersRepository.getUserById).toHaveBeenCalledWith("user-1");
expect(organizationsRepository.createMembership).toHaveBeenCalledWith({
organizationId: "org-1",
userId: "user-1",
Expand Down
5 changes: 5 additions & 0 deletions apps/web/app/t/[tenantSlug]/(workspace)/organization/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TenantOrganizationAdminPage } from "./tenant-organization-admin-page";

export default function OrganizationRoutePage() {
return <TenantOrganizationAdminPage />;
}
Loading
Loading