Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor(account): read the replaced avatar with the narrow user reader
naveenkash124c1bbef067
diff --git a/apps/erp/app/routes/x+/account+/profile.test.ts b/apps/erp/app/routes/x+/account+/profile.test.tsindex d53c737f2e..ebf380e618 100644--- a/apps/erp/app/routes/x+/account+/profile.test.ts+++ b/apps/erp/app/routes/x+/account+/profile.test.ts@@ -4,7 +4,7 @@import { requirePermissions } from "@carbon/auth/auth.server";import { beforeEach, describe, expect, it, vi } from "vitest";-import { getAccount, updateAvatar } from "~/modules/account";+import { getCurrentUser, updateAvatar } from "~/modules/account";import { action } from "./profile";// The photo intent saves the new avatar value, then deletes the photo it@@ -24,6 +24,7 @@ vi.mock("~/modules/account/ui/Profile", () => ({ ProfileForm: () => null }));vi.mock("~/modules/account", () => ({accountProfileValidator: {},getAccount: vi.fn(),+ getCurrentUser: vi.fn(),updateAvatar: vi.fn(),updatePublicAccount: vi.fn()}));@@ -76,7 +77,7 @@ describe("profile action, photo intent", () => {calls.push(`update:${value}`);return { error: null };}) as never);- vi.mocked(getAccount).mockResolvedValue({+ vi.mocked(getCurrentUser).mockResolvedValue({data: { avatarUrl: `${USER_ID}.webp` },error: null} as never);@@ -97,7 +98,7 @@ describe("profile action, photo intent", () => {});it("deletes nothing when the previous avatar was generated", async () => {- vi.mocked(getAccount).mockResolvedValue({+ vi.mocked(getCurrentUser).mockResolvedValue({data: { avatarUrl: "dicebear:croodles-neutral:abc" },error: null} as never);diff --git a/apps/erp/app/routes/x+/account+/profile.tsx b/apps/erp/app/routes/x+/account+/profile.tsxindex fae143c0ca..787c637043 100644--- a/apps/erp/app/routes/x+/account+/profile.tsx+++ b/apps/erp/app/routes/x+/account+/profile.tsx@@ -19,6 +19,7 @@ import { data, useLoaderData } from "react-router";import {accountProfileValidator,getAccount,+ getCurrentUser,updateAvatar,updatePublicAccount} from "~/modules/account";@@ -94,7 +95,8 @@ export async function action({ request }: ActionFunctionArgs) {);}- const previous = await getAccount(client, userId);+ // Only the replaced avatar is needed: the narrow reader, not `select("*")`.+ const previous = await getCurrentUser(client, userId);if (previous.error) {logger.error("Failed to read the avatar being replaced", {userId,