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: services for multi-tenant - resources
Brad Barbin4ebf7e4ad53e
diff --git a/apps/carbon/app/modules/account/account.service.ts b/apps/carbon/app/modules/account/account.service.tsindex f7cec4b29d..4df002ca60 100644--- a/apps/carbon/app/modules/account/account.service.ts+++ b/apps/carbon/app/modules/account/account.service.ts@@ -25,12 +25,13 @@ export async function getAccount(client: SupabaseClient<Database>, id: string) {export async function getAttributes(client: SupabaseClient<Database>,userId: string,+ companyId: number,isPublic: boolean) {return client.from("userAttributeCategory").select(- `id, name, id,+ `id, name, companyId,userAttribute(id, name, listOptions, canSelfManage,attributeDataType(id, isBoolean, isDate, isNumeric, isText, isUser),userAttributeValue(@@ -38,6 +39,7 @@ export async function getAttributes())`)+ .eq("companyId", companyId).eq("public", isPublic).eq("active", true).eq("userAttribute.active", true)@@ -47,16 +49,18 @@ export async function getAttributes(export async function getPrivateAttributes(client: SupabaseClient<Database>,- userId: string+ userId: string,+ companyId: number) {- return getAttributes(client, userId, false);+ return getAttributes(client, userId, companyId, false);}export async function getPublicAttributes(client: SupabaseClient<Database>,- userId: string+ userId: string,+ companyId: number) {- return getAttributes(client, userId, true);+ return getAttributes(client, userId, companyId, true);}export async function updateAvatar(diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.tsindex ff242ca12f..d1808c5b21 100644--- a/apps/carbon/app/modules/resources/resources.service.ts+++ b/apps/carbon/app/modules/resources/resources.service.ts@@ -142,6 +142,7 @@ export async function deleteWorkCellType(export async function getAbilities(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & { search: string | null }) {let query = client@@ -149,6 +150,7 @@ export async function getAbilities(.select(`*, employeeAbility(user(id, fullName, avatarUrl))`, {count: "exact",})+ .eq("companyId", companyId).eq("active", true).eq("employeeAbility.active", true).eq("employeeAbility.user.active", true);@@ -163,8 +165,15 @@ export async function getAbilities(return query;}-export async function getAbilitiesList(client: SupabaseClient<Database>) {- return client.from("ability").select(`id, name`).order("name");+export async function getAbilitiesList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("ability")+ .select(`id, name`)+ .eq("companyId", companyId)+ .order("name");}export async function getAbility(@@ -286,9 +295,14 @@ export async function getContractor(export async function getContractors(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("contractors").select("*").eq("active", true);+ let query = client+ .from("contractors")+ .select("*")+ .eq("companyId", companyId)+ .eq("active", true);if (args?.search) {query = query.or(@@ -314,11 +328,15 @@ export async function getDepartment(export async function getDepartments(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("department").select(`*, department(id, name)`, {- count: "exact",- });+ let query = client+ .from("department")+ .select(`*, department(id, name)`, {+ count: "exact",+ })+ .eq("companyId", companyId);if (args?.search) {query = query.ilike("name", `%${args.search}%`);@@ -333,8 +351,15 @@ export async function getDepartments(return query;}-export async function getDepartmentsList(client: SupabaseClient<Database>) {- return client.from("department").select(`id, name`).order("name");+export async function getDepartmentsList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("department")+ .select(`id, name`)+ .eq("companyId", companyId)+ .order("name");}export async function getEmployeeAbility(@@ -408,6 +433,7 @@ export async function getEquipmentType(export async function getEquipmentTypes(client: SupabaseClient<Database>,+ companyId: number,args?: { search: string | null } & GenericQueryFilters) {let query = client@@ -415,6 +441,7 @@ export async function getEquipmentTypes(.select("*, equipment(id, name)", {count: "exact",})+ .eq("companyId", companyId).eq("active", true).eq("equipment.active", true);@@ -431,8 +458,15 @@ export async function getEquipmentTypes(return query;}-export async function getEquipmentTypesList(client: SupabaseClient<Database>) {- return client.from("equipmentType").select("id, name").order("name");+export async function getEquipmentTypesList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("equipmentType")+ .select("id, name")+ .eq("companyId", companyId)+ .order("name");}export async function getHoliday(@@ -444,11 +478,15 @@ export async function getHoliday(export async function getHolidays(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("holiday").select("*", {- count: "exact",- });+ let query = client+ .from("holiday")+ .select("*", {+ count: "exact",+ })+ .eq("companyId", companyId);if (args?.search) {query = query.ilike("name", `%${args.search}%`);@@ -463,8 +501,11 @@ export async function getHolidays(return query;}-export function getHolidayYears(client: SupabaseClient<Database>) {- return client.from("holidayYears").select("year");+export function getHolidayYears(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client.from("holidayYears").select("year").eq("companyId", companyId);}export async function getLocation(@@ -476,9 +517,13 @@ export async function getLocation(export async function getLocations(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("location").select("*", { count: "exact" });+ let query = client+ .from("location")+ .select("*", { count: "exact" })+ .eq("companyId", companyId);if (args?.search) {query = query.ilike("name", `%${args.search}%`);@@ -493,8 +538,15 @@ export async function getLocations(return query;}-export async function getLocationsList(client: SupabaseClient<Database>) {- return client.from("location").select(`id, name`).order("name");+export async function getLocationsList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("location")+ .select(`id, name`)+ .eq("companyId", companyId)+ .order("name");}export async function getPartnerBySupplierId(@@ -523,9 +575,14 @@ export async function getPartner(export async function getPartners(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("partners").select("*").eq("active", true);+ let query = client+ .from("partners")+ .select("*")+ .eq("companyId", companyId)+ .eq("active", true);if (args?.search) {query = query.ilike("supplierName", `%${args.search}%`);@@ -656,6 +713,7 @@ export async function getShift(export async function getShifts(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & { search: string | null }) {let query = client@@ -663,6 +721,7 @@ export async function getShifts(.select("*", {count: "exact",})+ .eq("companyId", companyId).eq("active", true);if (args?.search) {@@ -734,6 +793,7 @@ export async function getWorkCellType(export async function getWorkCellTypes(client: SupabaseClient<Database>,+ companyId: number,args?: { search: string | null } & GenericQueryFilters) {let query = client@@ -741,6 +801,7 @@ export async function getWorkCellTypes(.select("*, workCell(id, name)", {count: "exact",})+ .eq("companyId", companyId).eq("active", true).eq("workCell.active", true);@@ -757,8 +818,15 @@ export async function getWorkCellTypes(return query;}-export async function getWorkCellTypesList(client: SupabaseClient<Database>) {- return client.from("workCellType").select("id, name").order("name");+export async function getWorkCellTypesList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("workCellType")+ .select("id, name")+ .eq("companyId", companyId)+ .order("name");}export async function insertAbility(@@ -772,6 +840,7 @@ export async function insertAbility(}[];};shadowWeeks: number;+ companyId: number;createdBy: string;}) {@@ -922,6 +991,20 @@ export async function updateAttributeSortOrder(return Promise.all(updatePromises);}+export async function updateEmployeeJob(+ client: SupabaseClient<Database>,+ employeeId: string,+ employeeJob: z.infer<typeof employeeJobValidator> & {+ updatedBy: string;+ customFields?: Json;+ }+) {+ return client+ .from("employeeJob")+ .update(sanitize(employeeJob))+ .eq("id", employeeId);+}+export async function upsertContractor(client: SupabaseClient<Database>,contractorWithAbilities:@@ -929,6 +1012,7 @@ export async function upsertContractor(id: string;hoursPerWeek?: number;abilities: string[];+ companyId: number;createdBy: string;customFields?: Json;}@@ -981,6 +1065,7 @@ export async function upsertDepartment(client: SupabaseClient<Database>,department:| (Omit<z.infer<typeof departmentValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -1036,23 +1121,11 @@ export async function upsertEmployeeAbility(.single();}-export async function upsertEmployeeJob(- client: SupabaseClient<Database>,- employeeId: string,- employeeJob: z.infer<typeof employeeJobValidator> & {- updatedBy: string;- customFields?: Json;- }-) {- return client- .from("employeeJob")- .upsert([{ id: employeeId, ...sanitize(employeeJob) }]);-}-export async function upsertEquipment(client: SupabaseClient<Database>,equipment:| (Omit<z.infer<typeof equipmentValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -1074,6 +1147,7 @@ export async function upsertEquipmentType(client: SupabaseClient<Database>,equipmentType:| (Omit<z.infer<typeof equipmentTypeValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -1098,6 +1172,7 @@ export async function upsertHoliday(client: SupabaseClient<Database>,holiday:| (Omit<z.infer<typeof holidayValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -1140,6 +1215,7 @@ export async function upsertPartner(client: SupabaseClient<Database>,partner:| (Omit<z.infer<typeof partnerValidator>, "supplierId"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -1183,6 +1259,7 @@ export async function upsertWorkCell(client: SupabaseClient<Database>,workCell:| (Omit<z.infer<typeof workCellValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -1205,6 +1282,7 @@ export async function upsertWorkCellType(client: SupabaseClient<Database>,workCellType:| (Omit<z.infer<typeof workCellTypeValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})diff --git a/apps/carbon/app/modules/settings/settings.service.ts b/apps/carbon/app/modules/settings/settings.service.tsindex d35072be70..9e434574a4 100644--- a/apps/carbon/app/modules/settings/settings.service.ts+++ b/apps/carbon/app/modules/settings/settings.service.ts@@ -99,10 +99,14 @@ export async function getIntegration(.single();}-export async function getIntegrations(client: SupabaseClient<Database>) {+export async function getIntegrations(+ client: SupabaseClient<Database>,+ companyId: number+) {return client.from("integration").select("*")+ .eq("companyId", companyId).eq("visible", true).order("title");}diff --git a/apps/carbon/app/modules/shared/shared.server.ts b/apps/carbon/app/modules/shared/shared.server.tsindex ac95eb95f5..26082ef180 100644--- a/apps/carbon/app/modules/shared/shared.server.ts+++ b/apps/carbon/app/modules/shared/shared.server.ts@@ -13,22 +13,29 @@ export async function assign() {const { id, table, assignee } = args;- return client- .from(table)- .update({ assignee: assignee ? assignee : null })- .eq("id", id);+ return (+ client+ // @ts-expect-error+ .from(table)+ .update({ assignee: assignee ? assignee : null })+ .eq("id", id)+ );}-export async function getCustomFieldsCacheKey(args?: {+export async function getCustomFieldsCacheKey(args: {+ companyId?: number;module?: string;table?: string;}) {- return `customFields:${args?.module ?? ""}:${args?.table ?? ""}`;+ return `customFields:${args?.companyId}:${args?.module ?? ""}:${+ args?.table ?? ""+ }`;}export async function getCustomFieldsSchemas(client: SupabaseClient<Database>,- args?: {+ args: {+ companyId: number;module?: string;table?: string;}@@ -48,6 +55,10 @@ export async function getCustomFieldsSchemas(const query = client.from("customFieldTables").select("*");+ if (args?.companyId) {+ query.eq("companyId", args.companyId);+ }+if (args?.module) {query.eq("module", args.module);}diff --git a/apps/carbon/app/modules/users/users.server.ts b/apps/carbon/app/modules/users/users.server.tsindex 3e35445c0c..3c1dbf77bb 100644--- a/apps/carbon/app/modules/users/users.server.ts+++ b/apps/carbon/app/modules/users/users.server.ts@@ -119,11 +119,13 @@ export async function createEmployeeAccount(firstName,lastName,employeeType,+ companyId,}: {email: string;firstName: string;lastName: string;employeeType: string;+ companyId: number;}): Promise<Result> {const employeeTypePermissions = await getPermissionsByEmployeeType(@@ -171,6 +173,7 @@ export async function createEmployeeAccount(const createEmployee = await insertEmployee(client, {id: insertUser.data[0].id,employeeTypeId: employeeType,+ companyId,});if (createEmployee.error)diff --git a/apps/carbon/app/routes/api+/resources.abilities.ts b/apps/carbon/app/routes/api+/resources.abilities.tsindex df7a65b584..47d6ee504b 100644--- a/apps/carbon/app/routes/api+/resources.abilities.ts+++ b/apps/carbon/app/routes/api+/resources.abilities.ts@@ -4,9 +4,9 @@ import { getAbilitiesList } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",});- return json(await getAbilitiesList(authorized.client));+ return json(await getAbilitiesList(client, companyId));}diff --git a/apps/carbon/app/routes/api+/resources.departments.ts b/apps/carbon/app/routes/api+/resources.departments.tsindex 4a7b072f88..b4dbca19e9 100644--- a/apps/carbon/app/routes/api+/resources.departments.ts+++ b/apps/carbon/app/routes/api+/resources.departments.ts@@ -4,7 +4,7 @@ import { getDepartmentsList } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});+ const { client, companyId } = await requirePermissions(request, {});- return json(await getDepartmentsList(authorized.client));+ return json(await getDepartmentsList(client, companyId));}diff --git a/apps/carbon/app/routes/api+/resources.equipment-types.ts b/apps/carbon/app/routes/api+/resources.equipment-types.tsindex c2b9a5a8db..1d39e0dc97 100644--- a/apps/carbon/app/routes/api+/resources.equipment-types.ts+++ b/apps/carbon/app/routes/api+/resources.equipment-types.ts@@ -4,7 +4,7 @@ import { getEquipmentTypesList } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});+ const { client, companyId } = await requirePermissions(request, {});- return json(await getEquipmentTypesList(authorized.client));+ return json(await getEquipmentTypesList(client, companyId));}diff --git a/apps/carbon/app/routes/api+/resources.work-cell-types.tsx b/apps/carbon/app/routes/api+/resources.work-cell-types.tsxindex d0464667f9..ea5cdbfba2 100644--- a/apps/carbon/app/routes/api+/resources.work-cell-types.tsx+++ b/apps/carbon/app/routes/api+/resources.work-cell-types.tsx@@ -4,7 +4,7 @@ import { getWorkCellTypesList } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});+ const { client, companyId } = await requirePermissions(request, {});- return json(await getWorkCellTypesList(authorized.client));+ return json(await getWorkCellTypesList(client, companyId));}diff --git a/apps/carbon/app/routes/onboarding+/_layout.tsx b/apps/carbon/app/routes/onboarding+/_layout.tsxindex cf0a2cdfd8..f0822d63a0 100644--- a/apps/carbon/app/routes/onboarding+/_layout.tsx+++ b/apps/carbon/app/routes/onboarding+/_layout.tsx@@ -17,7 +17,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const [company, locations] = await Promise.all([getCompany(client, companyId),- getLocationsList(client),+ getLocationsList(client, companyId),]);// we don't need to do onboarding if we have a company name or locationsif (company.data?.name && locations.data?.length) {diff --git a/apps/carbon/app/routes/onboarding+/company.tsx b/apps/carbon/app/routes/onboarding+/company.tsxindex 762afd46fb..3733f0df09 100644--- a/apps/carbon/app/routes/onboarding+/company.tsx+++ b/apps/carbon/app/routes/onboarding+/company.tsx@@ -78,7 +78,7 @@ export async function action({ request }: ActionFunctionArgs) {const [company, locations] = await Promise.all([getCompany(client, 1),- getLocationsList(client),+ getLocationsList(client, 1),]);const location = locations?.data?.[0];diff --git a/apps/carbon/app/routes/x+/_layout.tsx b/apps/carbon/app/routes/x+/_layout.tsxindex 8397da7dbc..bf3e4081a7 100644--- a/apps/carbon/app/routes/x+/_layout.tsx+++ b/apps/carbon/app/routes/x+/_layout.tsx@@ -48,8 +48,8 @@ export async function loader({ request }: LoaderFunctionArgs) {const [company, customFields, integrations, user, claims, groups, defaults] =await Promise.all([getCompany(client, companyId),- getCustomFieldsSchemas(client, {}),- getIntegrations(client),+ getCustomFieldsSchemas(client, { companyId }),+ getIntegrations(client, companyId),getUser(client, userId),getUserClaims(request),getUserGroups(client, userId),@@ -84,6 +84,7 @@ export async function loader({ request }: LoaderFunctionArgs) {export default function AuthenticatedRoute() {const { session } = useLoaderData<typeof loader>();+const transition = useNavigation();/* NProgress */diff --git a/apps/carbon/app/routes/x+/account+/personal.tsx b/apps/carbon/app/routes/x+/account+/personal.tsxindex 8e5009cf91..1089cdf385 100644--- a/apps/carbon/app/routes/x+/account+/personal.tsx+++ b/apps/carbon/app/routes/x+/account+/personal.tsx@@ -22,10 +22,10 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client, userId } = await requirePermissions(request, {});+ const { client, companyId, userId } = await requirePermissions(request, {});const [privateAttributes] = await Promise.all([- getPrivateAttributes(client, userId),+ getPrivateAttributes(client, userId, companyId),]);if (privateAttributes.error) {diff --git a/apps/carbon/app/routes/x+/account+/profile.tsx b/apps/carbon/app/routes/x+/account+/profile.tsxindex a4f3389f6a..0ddb992c62 100644--- a/apps/carbon/app/routes/x+/account+/profile.tsx+++ b/apps/carbon/app/routes/x+/account+/profile.tsx@@ -33,11 +33,11 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client, userId } = await requirePermissions(request, {});+ const { client, companyId, userId } = await requirePermissions(request, {});const [user, publicAttributes] = await Promise.all([getAccount(client, userId),- getPublicAttributes(client, userId),+ getPublicAttributes(client, userId, companyId),]);if (user.error || !user.data) {diff --git a/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsx b/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsxindex d6a2d0caec..3102afb0fd 100644--- a/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsx+++ b/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsx@@ -23,7 +23,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: ["accounting", "inventory"],});@@ -41,7 +41,7 @@ export async function loader({ request }: LoaderFunctionArgs) {filters,}),getPartGroupsList(client),- getLocationsList(client),+ getLocationsList(client, companyId),]);if (inventoryGroups.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/inventory+/receipts.tsx b/apps/carbon/app/routes/x+/inventory+/receipts.tsxindex 4854a17e97..6977fd3f9f 100644--- a/apps/carbon/app/routes/x+/inventory+/receipts.tsx+++ b/apps/carbon/app/routes/x+/inventory+/receipts.tsx@@ -17,7 +17,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "inventory",});@@ -35,7 +35,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getLocationsList(client),+ getLocationsList(client, companyId),]);if (receipts.error) {diff --git a/apps/carbon/app/routes/x+/part+/$partId.inventory.tsx b/apps/carbon/app/routes/x+/part+/$partId.inventory.tsxindex 8f21678f45..0ae6539269 100644--- a/apps/carbon/app/routes/x+/part+/$partId.inventory.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.inventory.tsx@@ -22,7 +22,7 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {view: "parts",});@@ -34,7 +34,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {let locationId = searchParams.get("location");if (!locationId) {- const userDefaults = await getUserDefaults(client, userId);+ const userDefaults = await getUserDefaults(client, userId, companyId);if (userDefaults.error) {throw redirect(path.to.part(partId),@@ -49,7 +49,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}if (!locationId) {- const locations = await getLocationsList(client);+ const locations = await getLocationsList(client, companyId);if (locations.error || !locations.data?.length) {throw redirect(path.to.part(partId),diff --git a/apps/carbon/app/routes/x+/part+/$partId.planning.tsx b/apps/carbon/app/routes/x+/part+/$partId.planning.tsxindex c07e702950..ac15a16a9d 100644--- a/apps/carbon/app/routes/x+/part+/$partId.planning.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.planning.tsx@@ -32,7 +32,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {let locationId = searchParams.get("location");if (!locationId) {- const userDefaults = await getUserDefaults(client, userId);+ const userDefaults = await getUserDefaults(client, userId, companyId);if (userDefaults.error) {throw redirect(path.to.part(partId),@@ -47,7 +47,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}if (!locationId) {- const locations = await getLocationsList(client);+ const locations = await getLocationsList(client, companyId);if (locations.error || !locations.data?.length) {throw redirect(path.to.part(partId),diff --git a/apps/carbon/app/routes/x+/part+/_layout.tsx b/apps/carbon/app/routes/x+/part+/_layout.tsxindex 10e0b3a1e3..0c3139c090 100644--- a/apps/carbon/app/routes/x+/part+/_layout.tsx+++ b/apps/carbon/app/routes/x+/part+/_layout.tsx@@ -18,13 +18,13 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const [unitOfMeasures, locations] = await Promise.all([getUnitOfMeasuresList(client),- getLocationsList(client),+ getLocationsList(client, companyId),]);return {diff --git a/apps/carbon/app/routes/x+/person+/$personId.job.tsx b/apps/carbon/app/routes/x+/person+/$personId.job.tsxindex 5792c11ea0..4bfed5be7c 100644--- a/apps/carbon/app/routes/x+/person+/$personId.job.tsx+++ b/apps/carbon/app/routes/x+/person+/$personId.job.tsx@@ -11,7 +11,7 @@ import {PersonJob,employeeJobValidator,getEmployeeJob,- upsertEmployeeJob,+ updateEmployeeJob,} from "~/modules/resources";import { getCustomFields, setCustomFields } from "~/utils/form";import { assertIsPost } from "~/utils/http";@@ -52,7 +52,7 @@ export async function action({ request, params }: ActionFunctionArgs) {return validationError(validation.error);}- const updateJob = await upsertEmployeeJob(client, personId, {+ const updateJob = await updateEmployeeJob(client, personId, {...validation.data,updatedBy: userId,customFields: setCustomFields(formData),diff --git a/apps/carbon/app/routes/x+/person+/$personId.private.tsx b/apps/carbon/app/routes/x+/person+/$personId.private.tsxindex 502bf65fa1..dcaceacfc0 100644--- a/apps/carbon/app/routes/x+/person+/$personId.private.tsx+++ b/apps/carbon/app/routes/x+/person+/$personId.private.tsx@@ -6,7 +6,7 @@ import { useLoaderData } from "@remix-run/react";import { validationError, validator } from "@carbon/remix-validated-form";import type { PrivateAttributes } from "~/modules/account";import { UserAttributesForm, getPrivateAttributes } from "~/modules/account";-import { employeeJobValidator, upsertEmployeeJob } from "~/modules/resources";+import { employeeJobValidator, updateEmployeeJob } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";import { assertIsPost } from "~/utils/http";@@ -14,14 +14,18 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",});const { personId } = params;if (!personId) throw new Error("Could not find personId");- const privateAttributes = await getPrivateAttributes(client, personId);+ const privateAttributes = await getPrivateAttributes(+ client,+ personId,+ companyId+ );if (privateAttributes.error) {throw redirect(path.to.people,@@ -39,7 +43,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client } = await requirePermissions(request, {+ const { client, userId } = await requirePermissions(request, {update: "resources",});const { personId } = params;@@ -53,7 +57,10 @@ export async function action({ request, params }: ActionFunctionArgs) {return validationError(validation.error);}- const updateJob = await upsertEmployeeJob(client, personId, validation.data);+ const updateJob = await updateEmployeeJob(client, personId, {+ ...validation.data,+ updatedBy: userId,+ });if (updateJob.error) {throw redirect(path.to.personJob(personId),diff --git a/apps/carbon/app/routes/x+/person+/$personId.public.tsx b/apps/carbon/app/routes/x+/person+/$personId.public.tsxindex 43a601f635..eb565ada15 100644--- a/apps/carbon/app/routes/x+/person+/$personId.public.tsx+++ b/apps/carbon/app/routes/x+/person+/$personId.public.tsx@@ -6,7 +6,7 @@ import { useLoaderData } from "@remix-run/react";import { validationError, validator } from "@carbon/remix-validated-form";import type { PublicAttributes } from "~/modules/account";import { UserAttributesForm, getPublicAttributes } from "~/modules/account";-import { employeeJobValidator, upsertEmployeeJob } from "~/modules/resources";+import { employeeJobValidator, updateEmployeeJob } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";import { assertIsPost } from "~/utils/http";@@ -14,14 +14,18 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",});const { personId } = params;if (!personId) throw new Error("Could not find personId");- const publicAttributes = await getPublicAttributes(client, personId);+ const publicAttributes = await getPublicAttributes(+ client,+ personId,+ companyId+ );if (publicAttributes.error) {throw redirect(path.to.people,@@ -39,7 +43,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client } = await requirePermissions(request, {+ const { client, userId } = await requirePermissions(request, {update: "resources",});const { personId } = params;@@ -53,7 +57,10 @@ export async function action({ request, params }: ActionFunctionArgs) {return validationError(validation.error);}- const updateJob = await upsertEmployeeJob(client, personId, validation.data);+ const updateJob = await updateEmployeeJob(client, personId, {+ ...validation.data,+ updatedBy: userId,+ });if (updateJob.error) {throw redirect(path.to.personJob(personId),diff --git a/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.tsx b/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.tsxindex 9146edee6f..ae8fef8583 100644--- a/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.tsx+++ b/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.tsx@@ -22,7 +22,7 @@ export const handle: Handle = {};export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -32,7 +32,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const [purchaseInvoice, purchaseInvoiceLines, locations] = await Promise.all([getPurchaseInvoice(client, invoiceId),getPurchaseInvoiceLines(client, invoiceId),- getLocationsList(client),+ getLocationsList(client, companyId),]);if (purchaseInvoice.error) {diff --git a/apps/carbon/app/routes/x+/purchase-order+/$orderId.tsx b/apps/carbon/app/routes/x+/purchase-order+/$orderId.tsxindex b438332eaa..8529845e61 100644--- a/apps/carbon/app/routes/x+/purchase-order+/$orderId.tsx+++ b/apps/carbon/app/routes/x+/purchase-order+/$orderId.tsx@@ -24,7 +24,7 @@ export const handle: Handle = {};export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "purchasing",});@@ -40,9 +40,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) {] = await Promise.all([getPurchaseOrder(client, orderId),getPurchaseOrderLines(client, orderId),- getPurchaseOrderExternalDocuments(client, orderId),- getPurchaseOrderInternalDocuments(client, orderId),- getLocationsList(client),+ getPurchaseOrderExternalDocuments(client, companyId, orderId),+ getPurchaseOrderInternalDocuments(client, companyId, orderId),+ getLocationsList(client, companyId),]);if (purchaseOrder.error) {diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsxindex 38959fe3ed..7f9f798be6 100644--- a/apps/carbon/app/routes/x+/quote+/$id.tsx+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx@@ -31,8 +31,8 @@ import {getQuoteOperations,useQuotation,} from "~/modules/sales";-import QuotationReleaseModal from "~/modules/sales/ui/Quotation/QuotationReleaseModal";import ConvertToSalesOrderModal from "~/modules/sales/ui/Quotation/ConvertToSalesOrderModal";+import QuotationReleaseModal from "~/modules/sales/ui/Quotation/QuotationReleaseModal";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";@@ -47,7 +47,7 @@ export const handle: Handle = {};export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "sales",});@@ -69,9 +69,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) {getQuoteAssemblies(client, id),getQuoteMaterials(client, id),getQuoteOperations(client, id),- getQuoteExternalDocuments(client, id),- getQuoteInternalDocuments(client, id),- getLocationsList(client),+ getQuoteExternalDocuments(client, companyId, id),+ getQuoteInternalDocuments(client, companyId, id),+ getLocationsList(client, companyId),]);if (quotation.error) {diff --git a/apps/carbon/app/routes/x+/receipt+/_layout.tsx b/apps/carbon/app/routes/x+/receipt+/_layout.tsxindex aead98e339..3cf45ce2a9 100644--- a/apps/carbon/app/routes/x+/receipt+/_layout.tsx+++ b/apps/carbon/app/routes/x+/receipt+/_layout.tsx@@ -18,13 +18,13 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "inventory",});const [unitOfMeasures, locations] = await Promise.all([getUnitOfMeasuresList(client),- getLocationsList(client),+ getLocationsList(client, companyId),]);return {diff --git a/apps/carbon/app/routes/x+/receipt+/new.tsx b/apps/carbon/app/routes/x+/receipt+/new.tsxindex 85587aef75..5ba872c704 100644--- a/apps/carbon/app/routes/x+/receipt+/new.tsx+++ b/apps/carbon/app/routes/x+/receipt+/new.tsx@@ -8,7 +8,7 @@ import { path } from "~/utils/path";import { error } from "~/utils/result";export async function loader({ request }: LoaderFunctionArgs) {- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "inventory",});@@ -18,7 +18,7 @@ export async function loader({ request }: LoaderFunctionArgs) {undefined;const sourceDocumentId = url.searchParams.get("sourceDocumentId") ?? "";- const defaults = await getUserDefaults(client, userId);+ const defaults = await getUserDefaults(client, userId, companyId);const serviceRole = getSupabaseServiceRole();switch (sourceDocument) {diff --git a/apps/carbon/app/routes/x+/resources+/abilities.new.tsx b/apps/carbon/app/routes/x+/resources+/abilities.new.tsxindex 72f2552eec..59687bac49 100644--- a/apps/carbon/app/routes/x+/resources+/abilities.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/abilities.new.tsx@@ -39,7 +39,7 @@ function makeCurve(startingPoint: number, weeks: number) {export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -58,6 +58,7 @@ export async function action({ request }: ActionFunctionArgs) {name,curve: makeCurve(startingPoint, weeks),shadowWeeks,+ companyId,createdBy: userId,});if (createAbility.error) {diff --git a/apps/carbon/app/routes/x+/resources+/abilities.tsx b/apps/carbon/app/routes/x+/resources+/abilities.tsxindex 7ecf93dfea..764f2cfac4 100644--- a/apps/carbon/app/routes/x+/resources+/abilities.tsx+++ b/apps/carbon/app/routes/x+/resources+/abilities.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const abilities = await getAbilities(client, {+ const abilities = await getAbilities(client, companyId, {search,limit,offset,diff --git a/apps/carbon/app/routes/x+/resources+/attributes.tsx b/apps/carbon/app/routes/x+/resources+/attributes.tsxindex c689916e47..4e3644115a 100644--- a/apps/carbon/app/routes/x+/resources+/attributes.tsx+++ b/apps/carbon/app/routes/x+/resources+/attributes.tsx@@ -20,7 +20,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -32,7 +32,13 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [categories, dataTypes] = await Promise.all([- getAttributeCategories(client, { search, limit, offset, sorts, filters }),+ getAttributeCategories(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters,+ }),getAttributeDataTypes(client),]);diff --git a/apps/carbon/app/routes/x+/resources+/contractors.new.tsx b/apps/carbon/app/routes/x+/resources+/contractors.new.tsxindex f594d95ce2..6dab5f5e35 100644--- a/apps/carbon/app/routes/x+/resources+/contractors.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/contractors.new.tsx@@ -16,7 +16,7 @@ import { error, success } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -34,6 +34,7 @@ export async function action({ request }: ActionFunctionArgs) {hoursPerWeek,abilities: abilities ?? [],customFields: setCustomFields(formData),+ companyId,createdBy: userId,});diff --git a/apps/carbon/app/routes/x+/resources+/contractors.tsx b/apps/carbon/app/routes/x+/resources+/contractors.tsxindex f4dbf6817d..be8b7e3389 100644--- a/apps/carbon/app/routes/x+/resources+/contractors.tsx+++ b/apps/carbon/app/routes/x+/resources+/contractors.tsx@@ -20,7 +20,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -32,14 +32,14 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [contractors, abilities] = await Promise.all([- getContractors(client, {+ getContractors(client, companyId, {search,limit,offset,sorts,filters,}),- getAbilitiesList(client),+ getAbilitiesList(client, companyId),]);if (contractors.error) {diff --git a/apps/carbon/app/routes/x+/resources+/departments.new.tsx b/apps/carbon/app/routes/x+/resources+/departments.new.tsxindex f880b59377..41798f642a 100644--- a/apps/carbon/app/routes/x+/resources+/departments.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/departments.new.tsx@@ -16,7 +16,7 @@ import { error, success } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -33,6 +33,7 @@ export async function action({ request }: ActionFunctionArgs) {const createDepartment = await upsertDepartment(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/departments.tsx b/apps/carbon/app/routes/x+/resources+/departments.tsxindex e84b9dd045..31f1c84bda 100644--- a/apps/carbon/app/routes/x+/resources+/departments.tsx+++ b/apps/carbon/app/routes/x+/resources+/departments.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const departments = await getDepartments(client, {+ const departments = await getDepartments(client, companyId, {search,limit,offset,diff --git a/apps/carbon/app/routes/x+/resources+/equipment.new.tsx b/apps/carbon/app/routes/x+/resources+/equipment.new.tsxindex 47053ed385..2c887e3383 100644--- a/apps/carbon/app/routes/x+/resources+/equipment.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/equipment.new.tsx@@ -16,7 +16,7 @@ import { error } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {update: "resources",});@@ -33,6 +33,7 @@ export async function action({ request }: ActionFunctionArgs) {const createEquipmentType = await upsertEquipmentType(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/equipment.tsx b/apps/carbon/app/routes/x+/resources+/equipment.tsxindex c8b82cf27f..57b87fb9ab 100644--- a/apps/carbon/app/routes/x+/resources+/equipment.tsx+++ b/apps/carbon/app/routes/x+/resources+/equipment.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const equipmentTypes = await getEquipmentTypes(client, {+ const equipmentTypes = await getEquipmentTypes(client, companyId, {search,limit,offset,diff --git a/apps/carbon/app/routes/x+/resources+/equipment.unit.new.tsx b/apps/carbon/app/routes/x+/resources+/equipment.unit.new.tsxindex 917fdb1fd1..6e152ee9b9 100644--- a/apps/carbon/app/routes/x+/resources+/equipment.unit.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/equipment.unit.new.tsx@@ -11,7 +11,7 @@ import { error } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -26,6 +26,7 @@ export async function action({ request }: ActionFunctionArgs) {const insertEquipment = await upsertEquipment(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/holidays.new.tsx b/apps/carbon/app/routes/x+/resources+/holidays.new.tsxindex 900fc580e2..c38f2db72a 100644--- a/apps/carbon/app/routes/x+/resources+/holidays.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/holidays.new.tsx@@ -15,7 +15,7 @@ import { error, success } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -26,11 +26,11 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { name, date } = validation.data;+ const { id, ...data } = validation.data;const createHoliday = await upsertHoliday(client, {- name,- date,+ ...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/holidays.tsx b/apps/carbon/app/routes/x+/resources+/holidays.tsxindex 2a5320ef4f..038dd72a28 100644--- a/apps/carbon/app/routes/x+/resources+/holidays.tsx+++ b/apps/carbon/app/routes/x+/resources+/holidays.tsx@@ -20,7 +20,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -32,14 +32,14 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [holidays, years] = await Promise.all([- getHolidays(client, {+ getHolidays(client, companyId, {search,limit,offset,sorts,filters,}),- getHolidayYears(client),+ getHolidayYears(client, companyId),]);if (holidays.error) {diff --git a/apps/carbon/app/routes/x+/resources+/locations.tsx b/apps/carbon/app/routes/x+/resources+/locations.tsxindex ffbd6e7b45..560718386b 100644--- a/apps/carbon/app/routes/x+/resources+/locations.tsx+++ b/apps/carbon/app/routes/x+/resources+/locations.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const locations = await getLocations(client, {+ const locations = await getLocations(client, companyId, {search,limit,offset,diff --git a/apps/carbon/app/routes/x+/resources+/partners.new.tsx b/apps/carbon/app/routes/x+/resources+/partners.new.tsxindex 5fd90c4670..34b3e3691d 100644--- a/apps/carbon/app/routes/x+/resources+/partners.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/partners.new.tsx@@ -16,7 +16,7 @@ import { error, success } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -31,6 +31,7 @@ export async function action({ request }: ActionFunctionArgs) {const createPartner = await upsertPartner(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/partners.tsx b/apps/carbon/app/routes/x+/resources+/partners.tsxindex 93d8d28689..a2a31d5113 100644--- a/apps/carbon/app/routes/x+/resources+/partners.tsx+++ b/apps/carbon/app/routes/x+/resources+/partners.tsx@@ -20,7 +20,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -32,14 +32,14 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [partners, abilities] = await Promise.all([- getPartners(client, {+ getPartners(client, companyId, {search,limit,offset,sorts,filters,}),- getAbilitiesList(client),+ getAbilitiesList(client, companyId),]);if (partners.error) {diff --git a/apps/carbon/app/routes/x+/resources+/shifts.tsx b/apps/carbon/app/routes/x+/resources+/shifts.tsxindex e9ce5b59bb..1a52cf115f 100644--- a/apps/carbon/app/routes/x+/resources+/shifts.tsx+++ b/apps/carbon/app/routes/x+/resources+/shifts.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -28,8 +28,8 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [shifts, locations] = await Promise.all([- getShifts(client, { search, limit, offset, sorts, filters }),- getLocations(client),+ getShifts(client, companyId, { search, limit, offset, sorts, filters }),+ getLocations(client, companyId),]);if (shifts.error) {diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsxindex dc38a10b45..e37d115894 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsx@@ -11,7 +11,7 @@ import { error } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "resources",});@@ -26,6 +26,7 @@ export async function action({ request }: ActionFunctionArgs) {const insertWorkCell = await upsertWorkCell(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsxindex a7f77a5aa1..cf792fb221 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx@@ -16,7 +16,7 @@ import { error } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {update: "resources",});@@ -33,6 +33,7 @@ export async function action({ request }: ActionFunctionArgs) {const createWorkCellType = await upsertWorkCellType(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.tsxindex 422364cb86..c16014b7ea 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const workCellTypes = await getWorkCellTypes(client, {+ const workCellTypes = await getWorkCellTypes(client, companyId, {search,limit,offset,diff --git a/apps/carbon/app/routes/x+/sales-order+/$orderId.tsx b/apps/carbon/app/routes/x+/sales-order+/$orderId.tsxindex 4aac94a9dd..2fbaecbeea 100644--- a/apps/carbon/app/routes/x+/sales-order+/$orderId.tsx+++ b/apps/carbon/app/routes/x+/sales-order+/$orderId.tsx@@ -2,6 +2,7 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";import { json, redirect } from "@remix-run/node";import { Outlet, useLoaderData } from "@remix-run/react";import { useEffect } from "react";+import { getLocationsList } from "~/modules/resources";import {SalesOrderHeader,SalesOrderSidebar,@@ -11,7 +12,6 @@ import {getSalesOrderLines,useSalesOrderTotals,} from "~/modules/sales";-import { getLocationsList } from "~/modules/resources";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";import type { Handle } from "~/utils/handle";@@ -24,7 +24,7 @@ export const handle: Handle = {};export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "sales",});@@ -40,9 +40,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) {] = await Promise.all([getSalesOrder(client, orderId),getSalesOrderLines(client, orderId),- //getSalesOrderExternalDocuments(client, orderId),- //getSalesOrderInternalDocuments(client, orderId),- getLocationsList(client),+ //getSalesOrderExternalDocuments(client, companyId, orderId),+ //getSalesOrderInternalDocuments(client, companyId, orderId),+ getLocationsList(client, companyId),]);if (salesOrder.error) {@@ -75,7 +75,7 @@ export default function SalesOrderRoute() {useEffect(() => {const totals = salesOrderLines.reduce((acc, line) => {- acc.total += (line.salesQuantity ?? 0) * (line.unitPrice ?? 0);+ acc.total += (line.saleQuantity ?? 0) * (line.unitPrice ?? 0);return acc;},diff --git a/apps/carbon/app/routes/x+/service+/_layout.tsx b/apps/carbon/app/routes/x+/service+/_layout.tsxindex 627b151b6e..fc8e375449 100644--- a/apps/carbon/app/routes/x+/service+/_layout.tsx+++ b/apps/carbon/app/routes/x+/service+/_layout.tsx@@ -18,13 +18,13 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const [partGroups, locations] = await Promise.all([getPartGroupsList(client),- getLocationsList(client),+ getLocationsList(client, companyId),]);return {diff --git a/apps/carbon/app/routes/x+/users+/employees.new.tsx b/apps/carbon/app/routes/x+/users+/employees.new.tsxindex 1701918c20..5b57fb7f90 100644--- a/apps/carbon/app/routes/x+/users+/employees.new.tsx+++ b/apps/carbon/app/routes/x+/users+/employees.new.tsx@@ -10,7 +10,7 @@ import { path } from "~/utils/path";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {create: "users",});@@ -28,6 +28,7 @@ export async function action({ request }: ActionFunctionArgs) {firstName,lastName,employeeType,+ companyId,});throw redirect(path.to.employeeAccounts, await flash(request, result));diff --git a/apps/docs/pages/core-concepts/fetching.mdx b/apps/docs/pages/core-concepts/fetching.mdxindex d04785ab0b..4bde6f4023 100644--- a/apps/docs/pages/core-concepts/fetching.mdx+++ b/apps/docs/pages/core-concepts/fetching.mdx@@ -28,7 +28,7 @@ Here's an example of simple route that fetches data from a service and displays// loader is run on the serverexport async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "resources",role: "employee",});@@ -38,11 +38,12 @@ export async function loader({ request }: LoaderFunctionArgs) {const name = searchParams.get("name");const { limit, offset, sorts } = getGenericQueryFilters(searchParams);- const partners = await getPartners(client, {- name,+ const partners = await getPartners(client, companyId, {+ search,limit,offset,sorts,+ filters,});if (partners.error) {diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 4e795e423c..21d9233b53 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -16083,9 +16083,18 @@ export type Database = {}holidayYears: {Row: {+ companyId: number | nullyear: number | null}- Relationships: []+ Relationships: [+ {+ foreignKeyName: "holiday_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },+ ]}partners: {Row: {diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 4e795e423c..21d9233b53 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -16083,9 +16083,18 @@ export type Database = {}holidayYears: {Row: {+ companyId: number | nullyear: number | null}- Relationships: []+ Relationships: [+ {+ foreignKeyName: "holiday_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },+ ]}partners: {Row: {diff --git a/packages/database/supabase/migrations/20230123004632_groups.sql b/packages/database/supabase/migrations/20230123004632_groups.sqlindex 42bc565747..7328bfd0d9 100644--- a/packages/database/supabase/migrations/20230123004632_groups.sql+++ b/packages/database/supabase/migrations/20230123004632_groups.sql@@ -278,6 +278,7 @@ CREATE OR REPLACE FUNCTION groups_for_user(uid text) RETURNS TEXT[]SELECT g1."groupId", g1."memberGroupId", g1."memberUserId" FROM "membership" g1INNER JOIN "groupsForUser" g2 ON g2."groupId" = g1."memberGroupId") SELECT array_agg("groupId") INTO retval AS groups FROM "groupsForUser";+RETURN retval;END;$$;diff --git a/packages/database/supabase/migrations/20230315222231_holidays.sql b/packages/database/supabase/migrations/20230315222231_holidays.sqlindex 105ab676bc..6246fada9c 100644--- a/packages/database/supabase/migrations/20230315222231_holidays.sql+++ b/packages/database/supabase/migrations/20230315222231_holidays.sql@@ -19,7 +19,7 @@ CREATE TABLE "holiday" (CREATE INDEX "holiday_companyId_idx" ON "holiday" ("companyId");-CREATE OR REPLACE VIEW "holidayYears" AS SELECT DISTINCT "year" FROM "holiday";+CREATE OR REPLACE VIEW "holidayYears" AS SELECT DISTINCT "year", "companyId" FROM "holiday";ALTER TABLE "holiday" ENABLE ROW LEVEL SECURITY;