Skip to content

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.

refactor: move maintenance to resources module

Brad Barbin435484542aa1
diff --git a/apps/erp/app/components/Form/Process.tsx b/apps/erp/app/components/Form/Process.tsx
index b6e2fe00c9..0f1ac86105 100644
--- a/apps/erp/app/components/Form/Process.tsx
+++ b/apps/erp/app/components/Form/Process.tsx
@@ -16,10 +16,10 @@ type ProcessSelectProps = Omit<ComboboxProps, "options" | "inline"> & {
const ProcessPreview = (
value: string,
- options: { value: string; label: string }[]
+ options: { value: string; label: string | JSX.Element }[]
) => {
const process = options.find((o) => o.value === value);
- return <Enumerable value={process?.label ?? null} />;
+ return process?.label ?? null;
};
const Process = (props: ProcessSelectProps) => {
@@ -33,7 +33,10 @@ const Process = (props: ProcessSelectProps) => {
<>
<CreatableCombobox
ref={triggerRef}
- options={options}
+ options={options.map((o) => ({
+ value: o.value,
+ label: <Enumerable value={o.label} />
+ }))}
{...props}
inline={props.inline ? ProcessPreview : undefined}
label={props?.label ?? "Work Center"}
diff --git a/apps/erp/app/components/Form/WorkCenter.tsx b/apps/erp/app/components/Form/WorkCenter.tsx
index 8b1b81ea6b..5a11be66e7 100644
--- a/apps/erp/app/components/Form/WorkCenter.tsx
+++ b/apps/erp/app/components/Form/WorkCenter.tsx
@@ -3,6 +3,7 @@ import { CreatableCombobox } from "@carbon/form";
import { useDisclosure, useMount } from "@carbon/react";
import { useMemo, useRef, useState } from "react";
import { useFetcher } from "react-router";
+import { Enumerable } from "~/components/Enumerable";
import { useUser } from "~/hooks";
import type { getWorkCentersList } from "~/modules/resources";
import WorkCenterForm from "~/modules/resources/ui/WorkCenters/WorkCenterForm";
@@ -37,7 +38,10 @@ const WorkCenter = (props: WorkCenterSelectProps) => {
workCenterFetcher.state === "idle"
}
ref={triggerRef}
- options={options}
+ options={options.map((o) => ({
+ value: o.value,
+ label: <Enumerable value={o.label} />
+ }))}
{...props}
label={props?.label ?? "Work Center"}
onCreateOption={(option) => {
diff --git a/apps/erp/app/modules/production/ui/Maintenance/Untitled b/apps/erp/app/modules/production/ui/Maintenance/Untitled
deleted file mode 100644
index 10b979c5ce..0000000000
--- a/apps/erp/app/modules/production/ui/Maintenance/Untitled
+++ /dev/null
@@ -1,46 +0,0 @@
-import { Status } from "@carbon/react";
-import type { maintenanceDispatchStatus } from "../../production.models";
-
-type MaintenanceStatusProps = {
- status?: (typeof maintenanceDispatchStatus)[number] | null;
- className?: string;
-};
-
-function MaintenanceStatus({ status, className }: MaintenanceStatusProps) {
- switch (status) {
- case "Open":
- return (
- <Status color="gray" className={className}>
- {status}
- </Status>
- );
- case "Assigned":
- return (
- <Status color="yellow" className={className}>
- {status}
- </Status>
- );
- case "In Progress":
- return (
- <Status color="blue" className={className}>
- {status}
- </Status>
- );
- case "Completed":
- return (
- <Status color="green" className={className}>
- {status}
- </Status>
- );
- case "Cancelled":
- return (
- <Status color="red" className={className}>
- {status}
- </Status>
- );
- default:
- return null;
- }
-}
-
-export default MaintenanceStatus;
diff --git a/apps/erp/app/modules/production/ui/useProductionSubmodules.tsx b/apps/erp/app/modules/production/ui/useProductionSubmodules.tsx
index b1f3394216..cbc669bc24 100644
--- a/apps/erp/app/modules/production/ui/useProductionSubmodules.tsx
+++ b/apps/erp/app/modules/production/ui/useProductionSubmodules.tsx
@@ -55,24 +55,6 @@ const productionRoutes: AuthenticatedRouteGroup[] = [
}
]
},
- {
- name: "Maintenance",
- routes: [
- {
- name: "Dispatches",
- to: path.to.maintenanceDispatches,
- icon: <LuWrench />,
- table: "maintenanceDispatch"
- },
- {
- name: "Schedules",
- to: path.to.maintenanceSchedules,
- icon: <LuCalendarClock />,
- table: "maintenanceSchedule",
- role: "employee"
- }
- ]
- },
{
name: "Configure",
routes: [
@@ -81,12 +63,6 @@ const productionRoutes: AuthenticatedRouteGroup[] = [
to: path.to.scrapReasons,
role: "employee",
icon: <LuTrash />
- },
- {
- name: "Failure Modes",
- to: path.to.failureModes,
- role: "employee",
- icon: <LuCircleAlert />
}
]
}
diff --git a/apps/erp/app/modules/resources/resources.models.ts b/apps/erp/app/modules/resources/resources.models.ts
index 8633dd5523..5408bd58a7 100644
--- a/apps/erp/app/modules/resources/resources.models.ts
+++ b/apps/erp/app/modules/resources/resources.models.ts
@@ -2,6 +2,20 @@ import { z } from "zod/v3";
import { zfd } from "zod-form-data";
import { processTypes, standardFactorType } from "../shared";
+export const abilityCurveValidator = z.object({
+ data: z
+ .string()
+ .startsWith("[", { message: "Invalid JSON" })
+ .endsWith("]", { message: "Invalid JSON" }),
+ shadowWeeks: zfd.numeric(
+ z.number().min(0, { message: "Time shadowing is required" })
+ )
+});
+
+export const abilityNameValidator = z.object({
+ name: z.string().min(1, { message: "Name is required" })
+});
+
export const abilityValidator = z
.object({
name: z.string().min(1, { message: "Name is required" }),
@@ -21,20 +35,6 @@ export const abilityValidator = z
message: "name is required when you send color on request"
});
-export const abilityCurveValidator = z.object({
- data: z
- .string()
- .startsWith("[", { message: "Invalid JSON" })
- .endsWith("]", { message: "Invalid JSON" }),
- shadowWeeks: zfd.numeric(
- z.number().min(0, { message: "Time shadowing is required" })
- )
-});
-
-export const abilityNameValidator = z.object({
- name: z.string().min(1, { message: "Name is required" })
-});
-
export const contractorValidator = z.object({
id: z.string().min(1, { message: "Supplier Contact is required" }),
supplierId: z.string().min(1, { message: "Supplier is required" }),
@@ -54,6 +54,11 @@ export const employeeAbilityValidator = z.object({
trainingDays: zfd.numeric(z.number().optional())
});
+export const failureModeValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ name: z.string().min(1, { message: "Name is required" })
+});
+
export const locationValidator = z
.object({
id: zfd.text(z.string().optional()),
@@ -79,6 +84,139 @@ export const locationValidator = z
}
});
+export const maintenanceDispatchCommentValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ maintenanceDispatchId: z.string().min(1, { message: "Dispatch is required" }),
+ comment: z.string().min(1, { message: "Comment is required" })
+});
+
+export const maintenanceDispatchEventValidator = z
+ .object({
+ id: zfd.text(z.string().optional()),
+ maintenanceDispatchId: z
+ .string()
+ .min(1, { message: "Dispatch is required" }),
+ employeeId: z.string().min(1, { message: "Employee is required" }),
+ workCenterId: z.string().min(1, { message: "Work center is required" }),
+ startTime: z.string().min(1, { message: "Start time is required" }),
+ endTime: zfd.text(z.string().optional()),
+ notes: zfd.text(z.string().optional())
+ })
+ .refine(
+ (data) => {
+ if (data.endTime) {
+ return new Date(data.startTime) < new Date(data.endTime);
+ }
+ return true;
+ },
+ {
+ message: "Start time must be before end time",
+ path: ["endTime"]
+ }
+ );
+
+export const maintenanceDispatchItemValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ maintenanceDispatchId: z.string().min(1, { message: "Dispatch is required" }),
+ itemId: z.string().min(1, { message: "Item is required" }),
+ quantity: zfd.numeric(z.number().min(1)),
+ unitOfMeasureCode: z
+ .string()
+ .min(1, { message: "Unit of measure is required" }),
+ unitCost: zfd.numeric(z.number().min(0).optional())
+});
+
+export const maintenanceDispatchPriority = [
+ "Low",
+ "Medium",
+ "High",
+ "Critical"
+] as const;
+
+export const maintenanceDispatchStatus = [
+ "Open",
+ "Assigned",
+ "In Progress",
+ "Completed",
+ "Cancelled"
+] as const;
+
+export const maintenanceDispatchValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ status: z.enum(maintenanceDispatchStatus),
+ priority: z.enum(maintenanceDispatchPriority),
+ severity: z
+ .enum([
+ "Preventive",
+ "Operator Performed",
+ "Maintenance Required",
+ "OEM Required"
+ ] as const)
+ .optional(),
+ source: z
+ .enum(["Scheduled", "Reactive", "Non-Conformance"] as const)
+ .optional(),
+ oeeImpact: z
+ .enum(["Down", "Planned", "Impact", "No Impact"] as const)
+ .optional(),
+ workCenterId: zfd.text(z.string().optional()),
+ suspectedFailureModeId: zfd.text(z.string().optional()),
+ plannedStartTime: zfd.text(z.string().optional()),
+ plannedEndTime: zfd.text(z.string().optional()),
+ assignee: zfd.text(z.string().optional()),
+ content: zfd.text(z.string().optional())
+});
+
+export const maintenanceDispatchWorkCenterValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ maintenanceDispatchId: z.string().min(1, { message: "Dispatch is required" }),
+ workCenterId: z.string().min(1, { message: "Work center is required" })
+});
+
+export const maintenanceFrequency = [
+ "Daily",
+ "Weekly",
+ "Monthly",
+ "Quarterly",
+ "Annual"
+] as const;
+
+export const maintenanceScheduleItemValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ maintenanceScheduleId: z.string().min(1, { message: "Schedule is required" }),
+ itemId: z.string().min(1, { message: "Item is required" }),
+ quantity: zfd.numeric(z.number().min(1)),
+ unitOfMeasureCode: z
+ .string()
+ .min(1, { message: "Unit of measure is required" })
+});
+
+export const maintenanceScheduleValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ name: z.string().min(1, { message: "Name is required" }),
+ description: zfd.text(z.string().optional()),
+ workCenterId: z.string().min(1, { message: "Work center is required" }),
+ frequency: z.enum(maintenanceFrequency),
+ priority: z.enum(maintenanceDispatchPriority),
+ estimatedDuration: zfd.numeric(z.number().optional()),
+ active: zfd.checkbox()
+});
+
+export const maintenanceSeverity = [
+ "Preventive",
+ "Operator Performed",
+ "Maintenance Required",
+ "OEM Required"
+] as const;
+
+export const maintenanceSource = [
+ "Scheduled",
+ "Reactive",
+ "Non-Conformance"
+] as const;
+
+export const oeeImpact = ["Down", "Planned", "Impact", "No Impact"] as const;
+
export const partnerValidator = z.object({
id: z.string().min(1, { message: "Supplier Location is required" }),
supplierId: zfd.text(z.string().optional()),
@@ -118,26 +256,31 @@ export const processValidator = z
return true;
});
-export const workCenterValidator = z.object({
+export const trainingAssignmentStatusOptions = [
+ "Completed",
+ "Pending",
+ "Overdue",
+ "Not Required"
+] as const;
+
+export const trainingAssignmentValidator = z.object({
id: zfd.text(z.string().optional()),
- name: z.string().min(1, { message: "Name is required" }),
- description: z.string(),
- defaultStandardFactor: z.enum(standardFactorType, {
- errorMap: (issue, ctx) => ({ message: "Standard factor is required" })
- }),
- laborRate: zfd.numeric(z.number().min(0)),
- locationId: z.string().min(1, { message: "Location is required" }),
- machineRate: zfd.numeric(z.number().min(0)),
- overheadRate: zfd.numeric(z.number().min(0)),
- processes: z
- .array(z.string().min(1, { message: "Invalid process" }))
- .optional()
- // requiredAbilityId: zfd.text(z.string().optional()),
+ trainingId: z.string().min(1, { message: "Training is required" }),
+ groupIds: z
+ .array(z.string())
+ .min(1, { message: "At least one group is required" })
+});
+
+export const trainingCompletionValidator = z.object({
+ trainingAssignmentId: z
+ .string()
+ .min(1, { message: "Training assignment is required" }),
+ employeeId: z.string().min(1, { message: "Employee is required" }),
+ period: zfd.text(z.string().optional())
});
-export const trainingStatus = ["Draft", "Active", "Archived"] as const;
export const trainingFrequency = ["Once", "Quarterly", "Annual"] as const;
-export const trainingType = ["Mandatory", "Optional"] as const;
+
export const trainingQuestionType = [
"MultipleChoice",
"TrueFalse",
@@ -146,12 +289,6 @@ export const trainingQuestionType = [
"Numerical"
] as const;
-export const trainingValidator = z.object({
- id: zfd.text(z.string().optional()),
- name: z.string().min(1, { message: "Name is required" }),
- content: zfd.text(z.string().optional())
-});
-
export const trainingQuestionValidator = z
.object({
id: zfd.text(z.string().optional()),
@@ -270,25 +407,29 @@ export const trainingQuestionValidator = z
}
);
-export const trainingAssignmentValidator = z.object({
+export const trainingStatus = ["Draft", "Active", "Archived"] as const;
+
+export const trainingType = ["Mandatory", "Optional"] as const;
+
+export const trainingValidator = z.object({
id: zfd.text(z.string().optional()),
- trainingId: z.string().min(1, { message: "Training is required" }),
- groupIds: z
- .array(z.string())
- .min(1, { message: "At least one group is required" })
+ name: z.string().min(1, { message: "Name is required" }),
+ content: zfd.text(z.string().optional())
});
-export const trainingCompletionValidator = z.object({
- trainingAssignmentId: z
- .string()
- .min(1, { message: "Training assignment is required" }),
- employeeId: z.string().min(1, { message: "Employee is required" }),
- period: zfd.text(z.string().optional())
+export const workCenterValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ name: z.string().min(1, { message: "Name is required" }),
+ description: z.string(),
+ defaultStandardFactor: z.enum(standardFactorType, {
+ errorMap: () => ({ message: "Standard factor is required" })
+ }),
+ laborRate: zfd.numeric(z.number().min(0)),
+ locationId: z.string().min(1, { message: "Location is required" }),
+ machineRate: zfd.numeric(z.number().min(0)),
+ overheadRate: zfd.numeric(z.number().min(0)),
+ processes: z
+ .array(z.string().min(1, { message: "Invalid process" }))
+ .optional()
+ // requiredAbilityId: zfd.text(z.string().optional()),
});
-
-export const trainingAssignmentStatusOptions = [
- "Completed",
- "Pending",
- "Overdue",
- "Not Required"
-] as const;
diff --git a/apps/erp/app/modules/resources/resources.service.ts b/apps/erp/app/modules/resources/resources.service.ts
index 71493777d7..2ebdb3627e 100644
--- a/apps/erp/app/modules/resources/resources.service.ts
+++ b/apps/erp/app/modules/resources/resources.service.ts
@@ -5,7 +5,15 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import type {
+ failureModeValidator,
locationValidator,
+ maintenanceDispatchCommentValidator,
+ maintenanceDispatchEventValidator,
+ maintenanceDispatchItemValidator,
+ maintenanceDispatchValidator,
+ maintenanceDispatchWorkCenterValidator,
+ maintenanceScheduleItemValidator,
+ maintenanceScheduleValidator,
partnerValidator,
processValidator,
trainingQuestionValidator,
@@ -47,6 +55,13 @@ export async function deleteEmployeeAbility(
.eq("id", employeeAbilityId);
}
+export async function deleteFailureMode(
+ client: SupabaseClient<Database>,
+ failureModeId: string
+) {
+ return client.from("maintenanceFailureMode").delete().eq("id", failureModeId);
+}
+
export async function deleteLocation(
client: SupabaseClient<Database>,
locationId: string
@@ -54,6 +69,58 @@ export async function deleteLocation(
return client.from("location").delete().eq("id", locationId);
}
+export async function deleteMaintenanceDispatch(
+ client: SupabaseClient<Database>,
+ dispatchId: string
+) {
+ return client.from("maintenanceDispatch").delete().eq("id", dispatchId);
+}
+
+export async function deleteMaintenanceDispatchComment(
+ client: SupabaseClient<Database>,
+ commentId: string
+) {
+ return client.from("maintenanceDispatchComment").delete().eq("id", commentId);
+}
+
+export async function deleteMaintenanceDispatchEvent(
+ client: SupabaseClient<Database>,
+ eventId: string
+) {
+ return client.from("maintenanceDispatchEvent").delete().eq("id", eventId);
+}
+
+export async function deleteMaintenanceDispatchItem(
+ client: SupabaseClient<Database>,
+ itemId: string
+) {
+ return client.from("maintenanceDispatchItem").delete().eq("id", itemId);
+}
+
+export async function deleteMaintenanceDispatchWorkCenter(
+ client: SupabaseClient<Database>,
+ workCenterId: string
+) {
+ return client
+ .from("maintenanceDispatchWorkCenter")
+ .delete()
+ .eq("id", workCenterId);
+}
+
+export async function deleteMaintenanceSchedule(
+ client: SupabaseClient<Database>,
+ scheduleId: string
+) {
+ return client.from("maintenanceSchedule").delete().eq("id", scheduleId);
+}
+
+export async function deleteMaintenanceScheduleItem(
+ client: SupabaseClient<Database>,
+ itemId: string
+) {
+ return client.from("maintenanceScheduleItem").delete().eq("id", itemId);
+}
+
export async function deletePartner(
client: SupabaseClient<Database>,
partnerId: string
@@ -217,6 +284,51 @@ export async function getEmployeeAbilities(
.eq("active", true);
}
+export async function getFailureMode(
+ client: SupabaseClient<Database>,
+ failureModeId: string
+) {
+ return client
+ .from("maintenanceFailureMode")
+ .select("*")
+ .eq("id", failureModeId)
+ .single();
+}
+
+export async function getFailureModes(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args?: GenericQueryFilters & { search: string | null }
+) {
+ let query = client
+ .from("maintenanceFailureMode")
+ .select("*", { count: "exact" })
+ .eq("companyId", companyId);
+
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
+ }
+
+ if (args) {
+ query = setGenericQueryFilters(query, args, [
+ { column: "name", ascending: true }
+ ]);
+ }
+
+ return query;
+}
+
+export async function getFailureModesList(
+ client: SupabaseClient<Database>,
+ companyId: string
+) {
+ return client
+ .from("maintenanceFailureMode")
+ .select("id, name")
+ .eq("companyId", companyId)
+ .order("name");
+}
+
export async function getLocation(
client: SupabaseClient<Database>,
locationId: string
@@ -258,6 +370,155 @@ export async function getLocationsList(
.order("name");
}
+export async function getMaintenanceDispatch(
+ client: SupabaseClient<Database>,
+ dispatchId: string
+) {
+ return client
+ .from("maintenanceDispatch")
+ .select(
+ `*,
+ assignee:user!maintenanceDispatch_assignee_fkey(id, fullName, avatarUrl),
+ suspectedFailureMode:maintenanceFailureMode!maintenanceDispatch_suspectedFailureModeId_fkey(id, name),
+ actualFailureMode:maintenanceFailureMode!maintenanceDispatch_actualFailureModeId_fkey(id, name),
+ schedule:maintenanceSchedule(id, name)`
+ )
+ .eq("id", dispatchId)
+ .single();
+}
+
+export async function getMaintenanceDispatchComments(
+ client: SupabaseClient<Database>,
+ dispatchId: string
+) {
+ return client
+ .from("maintenanceDispatchComment")
+ .select(
+ `id, comment, createdAt,
+ createdBy:user!maintenanceDispatchComment_createdBy_fkey(id, fullName, avatarUrl)`
+ )
+ .eq("maintenanceDispatchId", dispatchId)
+ .order("createdAt", { ascending: false });
+}
+
+export async function getMaintenanceDispatchEvents(
+ client: SupabaseClient<Database>,
+ dispatchId: string
+) {
+ return client
+ .from("maintenanceDispatchEvent")
+ .select(
+ `id, startTime, endTime, duration, notes,
+ employee:user!maintenanceDispatchEvent_employeeId_fkey(id, fullName, avatarUrl),
+ workCenter:workCenter!maintenanceDispatchEvent_workCenterId_fkey(id, name)`
+ )
+ .eq("maintenanceDispatchId", dispatchId)
+ .order("startTime", { ascending: false });
+}
+
+export async function getMaintenanceDispatchItems(
+ client: SupabaseClient<Database>,
+ dispatchId: string
+) {
+ return client
+ .from("maintenanceDispatchItem")
+ .select(
+ `id, itemId, quantity, unitOfMeasureCode, unitCost, totalCost,
+ item:item!maintenanceDispatchItem_itemId_fkey(id, name)`
+ )
+ .eq("maintenanceDispatchId", dispatchId);
+}
+
+export async function getMaintenanceDispatches(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args?: GenericQueryFilters & { search: string | null; status?: string }
+) {
+ let query = client
+ .from("maintenanceDispatch")
+ .select(`*`, { count: "exact" })
+ .eq("companyId", companyId);
+
+ if (args?.search) {
+ query = query.ilike("maintenanceDispatchId", `%${args.search}%`);
+ }
+
+ if (args) {
+ query = setGenericQueryFilters(query, args, [
+ { column: "createdAt", ascending: false }
+ ]);
+ }
+
+ return query;
+}
+
+export async function getMaintenanceDispatchWorkCenters(
+ client: SupabaseClient<Database>,
+ dispatchId: string
+) {
+ return client
+ .from("maintenanceDispatchWorkCenter")
+ .select(
+ `id, workCenterId,
+ workCenter:workCenter!maintenanceDispatchWorkCenter_workCenterId_fkey(id, name)`
+ )
+ .eq("maintenanceDispatchId", dispatchId);
+}
+
+export async function getMaintenanceSchedule(
+ client: SupabaseClient<Database>,
+ scheduleId: string
+) {
+ return client
+ .from("maintenanceSchedule")
+ .select(
+ `*,
+ workCenter:workCenter!maintenanceSchedule_workCenterId_fkey(id, name)`
+ )
+ .eq("id", scheduleId)
+ .single();
+}
+
+export async function getMaintenanceScheduleItems(
+ client: SupabaseClient<Database>,
+ scheduleId: string
+) {
+ return client
+ .from("maintenanceScheduleItem")
+ .select(
+ `id, quantity, unitOfMeasureCode,
+ item:item!maintenanceScheduleItem_itemId_fkey(id, name)`
+ )
+ .eq("maintenanceScheduleId", scheduleId);
+}
+
+export async function getMaintenanceSchedules(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args?: GenericQueryFilters & { search: string | null; active?: boolean }
+) {
+ let query = client
+ .from("maintenanceSchedules")
+ .select(`*`, { count: "exact" })
+ .eq("companyId", companyId);
+
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
+ }
+
+ if (args?.active !== undefined) {
+ query = query.eq("active", args.active);
+ }
+
+ if (args) {
+ query = setGenericQueryFilters(query, args, [
+ { column: "name", ascending: true }
+ ]);
+ }
+
+ return query;
+}
+
export async function getOutstandingTrainingsForUser(
client: SupabaseClient<Database>,
companyId: string,
@@ -885,6 +1146,33 @@ export async function upsertEmployeeAbility(
.single();
}
+export async function upsertFailureMode(
+ client: SupabaseClient<Database>,
+ failureMode:
+ | (Omit<z.infer<typeof failureModeValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ customFields?: Json;
+ })
+ | (Omit<z.infer<typeof failureModeValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ customFields?: Json;
+ })
+) {
+ if ("createdBy" in failureMode) {
+ return client
+ .from("maintenanceFailureMode")
+ .insert([failureMode])
+ .select("id");
+ } else {
+ return client
+ .from("maintenanceFailureMode")
+ .update(sanitize(failureMode))
+ .eq("id", failureMode.id);
+ }
+}
+
export async function upsertLocation(
client: SupabaseClient<Database>,
location:
@@ -908,6 +1196,192 @@ export async function upsertLocation(
return client.from("location").insert([location]).select("*").single();
}
+export async function upsertMaintenanceDispatch(
+ client: SupabaseClient<Database>,
+ dispatch:
+ | (Omit<z.infer<typeof maintenanceDispatchValidator>, "id"> & {
+ maintenanceDispatchId: string;
+ companyId: string;
+ createdBy: string;
+ content?: Json;
+ })
+ | (Omit<z.infer<typeof maintenanceDispatchValidator>, "id" | "assignee"> & {
+ id: string;
+ assignee: string | null;
+ updatedBy: string;
+ content?: Json;
+ })
+) {
+ if ("createdBy" in dispatch) {
+ return client
+ .from("maintenanceDispatch")
+ .insert([dispatch])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceDispatch")
+ .update(sanitize(dispatch))
+ .eq("id", dispatch.id);
+ }
+}
+
+export async function upsertMaintenanceDispatchComment(
+ client: SupabaseClient<Database>,
+ comment:
+ | (Omit<z.infer<typeof maintenanceDispatchCommentValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof maintenanceDispatchCommentValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ })
+) {
+ if ("createdBy" in comment) {
+ return client
+ .from("maintenanceDispatchComment")
+ .insert([comment])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceDispatchComment")
+ .update(sanitize(comment))
+ .eq("id", comment.id);
+ }
+}
+
+export async function upsertMaintenanceDispatchEvent(
+ client: SupabaseClient<Database>,
+ event:
+ | (Omit<z.infer<typeof maintenanceDispatchEventValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof maintenanceDispatchEventValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ })
+) {
+ if ("createdBy" in event) {
+ return client
+ .from("maintenanceDispatchEvent")
+ .insert([event])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceDispatchEvent")
+ .update(sanitize(event))
+ .eq("id", event.id);
+ }
+}
+
+export async function upsertMaintenanceDispatchItem(
+ client: SupabaseClient<Database>,
+ item:
+ | (Omit<z.infer<typeof maintenanceDispatchItemValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof maintenanceDispatchItemValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ })
+) {
+ if ("createdBy" in item) {
+ return client
+ .from("maintenanceDispatchItem")
+ .insert([item])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceDispatchItem")
+ .update(sanitize(item))
+ .eq("id", item.id);
+ }
+}
+
+export async function upsertMaintenanceDispatchWorkCenter(
+ client: SupabaseClient<Database>,
+ workCenter:
+ | (Omit<z.infer<typeof maintenanceDispatchWorkCenterValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof maintenanceDispatchWorkCenterValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ })
+) {
+ if ("createdBy" in workCenter) {
+ return client
+ .from("maintenanceDispatchWorkCenter")
+ .insert([workCenter])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceDispatchWorkCenter")
+ .update(sanitize(workCenter))
+ .eq("id", workCenter.id);
+ }
+}
+
+export async function upsertMaintenanceSchedule(
+ client: SupabaseClient<Database>,
+ schedule:
+ | (Omit<z.infer<typeof maintenanceScheduleValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof maintenanceScheduleValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ })
+) {
+ if ("createdBy" in schedule) {
+ return client
+ .from("maintenanceSchedule")
+ .insert([schedule])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceSchedule")
+ .update(sanitize(schedule))
+ .eq("id", schedule.id);
+ }
+}
+
+export async function upsertMaintenanceScheduleItem(
+ client: SupabaseClient<Database>,
+ item:
+ | (Omit<z.infer<typeof maintenanceScheduleItemValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof maintenanceScheduleItemValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ })
+) {
+ if ("createdBy" in item) {
+ return client
+ .from("maintenanceScheduleItem")
+ .insert([item])
+ .select("id")
+ .single();
+ } else {
+ return client
+ .from("maintenanceScheduleItem")
+ .update(sanitize(item))
+ .eq("id", item.id);
+ }
+}
+
export async function upsertPartner(
client: SupabaseClient<Database>,
partner:
@@ -925,8 +1399,7 @@ export async function upsertPartner(
return client
.from("partner")
.update(sanitize(partner))
- .eq("id", partner.id)
- .eq("abilityId", partner.abilityId);
+ .eq("id", partner.id);
} else {
return await client.from("partner").insert([partner]);
}
diff --git a/apps/erp/app/modules/resources/types.ts b/apps/erp/app/modules/resources/types.ts
index db7088435e..659cbd402d 100644
--- a/apps/erp/app/modules/resources/types.ts
+++ b/apps/erp/app/modules/resources/types.ts
@@ -7,7 +7,18 @@ import type {
getAbility,
getContractors,
getEmployeeAbilities,
+ getFailureMode,
+ getFailureModes,
getLocations,
+ getMaintenanceDispatch,
+ getMaintenanceDispatchComments,
+ getMaintenanceDispatchEvents,
+ getMaintenanceDispatches,
+ getMaintenanceDispatchItems,
+ getMaintenanceDispatchWorkCenters,
+ getMaintenanceSchedule,
+ getMaintenanceScheduleItems,
+ getMaintenanceSchedules,
getPartners,
getProcesses,
getSuggestion,
@@ -135,3 +146,47 @@ export type Suggestion = NonNullable<
export type SuggestionListItem = NonNullable<
Awaited<ReturnType<typeof getSuggestions>>["data"]
>[number];
+
+export type FailureMode = NonNullable<
+ Awaited<ReturnType<typeof getFailureModes>>["data"]
+>[number];
+
+export type FailureModeDetail = NonNullable<
+ Awaited<ReturnType<typeof getFailureMode>>["data"]
+>;
+
+export type MaintenanceDispatch = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceDispatches>>["data"]
+>[number];
+
+export type MaintenanceDispatchDetail = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceDispatch>>["data"]
+>;
+
+export type MaintenanceDispatchComment = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceDispatchComments>>["data"]
+>[number];
+
+export type MaintenanceDispatchEvent = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceDispatchEvents>>["data"]
+>[number];
+
+export type MaintenanceDispatchItem = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceDispatchItems>>["data"]
+>[number];
+
+export type MaintenanceDispatchWorkCenter = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceDispatchWorkCenters>>["data"]
+>[number];
+
+export type MaintenanceSchedule = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceSchedules>>["data"]
+>[number];
+
+export type MaintenanceScheduleDetail = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceSchedule>>["data"]
+>;
+
+export type MaintenanceScheduleItem = NonNullable<
+ Awaited<ReturnType<typeof getMaintenanceScheduleItems>>["data"]
+>[number];
diff --git a/apps/erp/app/modules/production/ui/FailureModes/FailureModeForm.tsx b/apps/erp/app/modules/resources/ui/FailureModes/FailureModeForm.tsx
similarity index 94%
rename from apps/erp/app/modules/production/ui/FailureModes/FailureModeForm.tsx
rename to apps/erp/app/modules/resources/ui/FailureModes/FailureModeForm.tsx
index f73545b126..47d57b608e 100644
--- a/apps/erp/app/modules/production/ui/FailureModes/FailureModeForm.tsx
+++ b/apps/erp/app/modules/resources/ui/FailureModes/FailureModeForm.tsx
@@ -19,7 +19,7 @@ import type { z } from "zod/v3";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
import { path } from "~/utils/path";
-import { failureModeValidator } from "../../production.models";
+import { failureModeValidator } from "../../resources.models";
type FailureModeFormProps = {
initialValues: z.infer<typeof failureModeValidator>;
@@ -52,8 +52,8 @@ const FailureModeForm = ({
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
- ? !permissions.can("update", "production")
- : !permissions.can("create", "production");
+ ? !permissions.can("update", "resources")
+ : !permissions.can("create", "resources");
return (
<ModalDrawerProvider type={type}>
diff --git a/apps/erp/app/modules/production/ui/FailureModes/FailureModesTable.tsx b/apps/erp/app/modules/resources/ui/FailureModes/FailureModesTable.tsx
similarity index 89%
rename from apps/erp/app/modules/production/ui/FailureModes/FailureModesTable.tsx
rename to apps/erp/app/modules/resources/ui/FailureModes/FailureModesTable.tsx
index 88318e4bca..d7918141a5 100644
--- a/apps/erp/app/modules/production/ui/FailureModes/FailureModesTable.tsx
+++ b/apps/erp/app/modules/resources/ui/FailureModes/FailureModesTable.tsx
@@ -20,7 +20,6 @@ const FailureModesTable = memo(({ data, count }: FailureModesTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
- const customColumns = useCustomColumns<FailureMode>("maintenanceFailureMode");
const columns = useMemo<ColumnDef<FailureMode>[]>(() => {
const defaultColumns: ColumnDef<FailureMode>[] = [
{
@@ -33,8 +32,8 @@ const FailureModesTable = memo(({ data, count }: FailureModesTableProps) => {
)
}
];
- return [...defaultColumns, ...customColumns];
- }, [customColumns]);
+ return [...defaultColumns];
+ }, []);
const renderContextMenu = useCallback(
(row: FailureMode) => {
@@ -50,7 +49,7 @@ const FailureModesTable = memo(({ data, count }: FailureModesTableProps) => {
</MenuItem>
<MenuItem
destructive
- disabled={!permissions.can("delete", "production")}
+ disabled={!permissions.can("delete", "resources")}
onClick={() => {
navigate(
`${path.to.deleteFailureMode(row.id)}?${params.toString()}`
@@ -72,7 +71,7 @@ const FailureModesTable = memo(({ data, count }: FailureModesTableProps) => {
columns={columns}
count={count}
primaryAction={
- permissions.can("create", "production") && (
+ permissions.can("create", "resources") && (
<New
label="Failure Mode"
to={`${path.to.newFailureMode}?${params.toString()}`}
diff --git a/apps/erp/app/modules/production/ui/FailureModes/index.ts b/apps/erp/app/modules/resources/ui/FailureModes/index.ts
similarity index 100%
rename from apps/erp/app/modules/production/ui/FailureModes/index.ts
rename to apps/erp/app/modules/resources/ui/FailureModes/index.ts
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchExplorer.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchExplorer.tsx
similarity index 99%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchExplorer.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchExplorer.tsx
index c5a45366ea..ded83c2863 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchExplorer.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchExplorer.tsx
@@ -59,7 +59,7 @@ import { path } from "~/utils/path";
import {
maintenanceDispatchEventValidator,
maintenanceDispatchItemValidator
-} from "../../production.models";
+} from "../../resources.models";
import type {
MaintenanceDispatchEvent,
MaintenanceDispatchItem
@@ -234,7 +234,7 @@ function MaintenanceExplorerItem({
)}
</div>
</button>
- {permissions.can("update", "production") && (
+ {permissions.can("update", "resources") && (
<IconButton
aria-label="Add"
size="sm"
@@ -322,7 +322,7 @@ function MaintenanceExplorerChildItem({
) : (
<div className="flex w-full">{content}</div>
)}
- {permissions.can("delete", "production") && (
+ {permissions.can("delete", "resources") && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchForm.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchForm.tsx
similarity index 98%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchForm.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchForm.tsx
index d242a19f2f..7fdca8c857 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchForm.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchForm.tsx
@@ -29,7 +29,7 @@ import {
maintenanceSeverity,
maintenanceSource,
oeeImpact
-} from "../../production.models";
+} from "../../resources.models";
import MaintenanceOeeImpact from "./MaintenanceOeeImpact";
import MaintenanceSeverity from "./MaintenanceSeverity";
import MaintenanceSource from "./MaintenanceSource";
@@ -66,8 +66,8 @@ const MaintenanceDispatchForm = ({
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
- ? !permissions.can("update", "production")
- : !permissions.can("create", "production");
+ ? !permissions.can("update", "resources")
+ : !permissions.can("create", "resources");
const [content, setContent] = useState<JSONContent>(
initialValues?.content
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchHeader.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchHeader.tsx
similarity index 95%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchHeader.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchHeader.tsx
index ce6fcb7b95..45e8ad80e4 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchHeader.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchHeader.tsx
@@ -64,7 +64,7 @@ const MaintenanceDispatchHeader = () => {
<DropdownMenuItem
destructive
disabled={
- !permissions.can("delete", "production") ||
+ !permissions.can("delete", "resources") ||
!permissions.is("employee")
}
onClick={deleteModal.onOpen}
@@ -94,7 +94,7 @@ const MaintenanceDispatchHeader = () => {
isDisabled={
!["Open", "Assigned"].includes(status ?? "") ||
statusFetcher.state !== "idle" ||
- !permissions.can("update", "production")
+ !permissions.can("update", "resources")
}
isLoading={
statusFetcher.state !== "idle" &&
@@ -117,7 +117,7 @@ const MaintenanceDispatchHeader = () => {
isDisabled={
status !== "In Progress" ||
statusFetcher.state !== "idle" ||
- !permissions.can("update", "production")
+ !permissions.can("update", "resources")
}
isLoading={
statusFetcher.state !== "idle" &&
@@ -140,7 +140,7 @@ const MaintenanceDispatchHeader = () => {
isDisabled={
!["In Progress", "Completed"].includes(status ?? "") ||
statusFetcher.state !== "idle" ||
- !permissions.can("update", "production")
+ !permissions.can("update", "resources")
}
>
Reopen
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchNotes.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchNotes.tsx
similarity index 98%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchNotes.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchNotes.tsx
index 2ea7190dd7..aa79bbe587 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchNotes.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchNotes.tsx
@@ -102,7 +102,7 @@ export function MaintenanceDispatchNotes({
</CardHeader>
<CardContent>
- {permissions.can("update", "production") && !isDisabled ? (
+ {permissions.can("update", "resources") && !isDisabled ? (
<Editor
initialValue={(content ?? {}) as JSONContent}
onUpload={onUploadImage}
@@ -172,7 +172,7 @@ export function MaintenanceDispatchFiles({
dispatchId={dispatchId}
files={resolvedFiles ?? []}
isReadOnly={
- !permissions.can("update", "production") || isDisabled
+ !permissions.can("update", "resources") || isDisabled
}
/>
)}
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchProperties.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx
similarity index 94%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchProperties.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx
index 778ae0c38e..6b9801ff27 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchProperties.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx
@@ -35,7 +35,7 @@ import {
maintenanceSeverity,
maintenanceSource,
oeeImpact
-} from "../../production.models";
+} from "../../resources.models";
import type {
MaintenanceDispatchDetail,
MaintenanceDispatchEvent
@@ -215,7 +215,7 @@ const MaintenanceDispatchProperties = () => {
table="maintenanceDispatch"
size="sm"
value={assignee ?? ""}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
/>
</VStack>
@@ -230,7 +230,7 @@ const MaintenanceDispatchProperties = () => {
>
<Select
options={workCenterOptions}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="Work Center"
name="workCenterId"
inline={(value) => {
@@ -266,7 +266,7 @@ const MaintenanceDispatchProperties = () => {
</div>
)
}))}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="Priority"
name="priority"
inline={(value) => {
@@ -298,7 +298,7 @@ const MaintenanceDispatchProperties = () => {
value: severity,
label: severity
}))}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="Severity"
name="severity"
inline={(value) => {
@@ -330,7 +330,7 @@ const MaintenanceDispatchProperties = () => {
value: source,
label: <MaintenanceSource source={source} />
}))}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="Source"
name="source"
inline={(value) => {
@@ -362,7 +362,7 @@ const MaintenanceDispatchProperties = () => {
value: impact,
label: <MaintenanceOeeImpact oeeImpact={impact} />
}))}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="OEE Impact"
name="oeeImpact"
inline={(value) => {
@@ -394,7 +394,7 @@ const MaintenanceDispatchProperties = () => {
name="plannedStartTime"
label="Planned Start"
inline
- isDisabled={!permissions.can("update", "production") || isCompleted}
+ isDisabled={!permissions.can("update", "resources") || isCompleted}
onChange={(date) => {
onUpdate("plannedStartTime", date?.toString() ?? null);
}}
@@ -414,7 +414,7 @@ const MaintenanceDispatchProperties = () => {
name="plannedEndTime"
label="Planned End"
inline
- isDisabled={!permissions.can("update", "production") || isCompleted}
+ isDisabled={!permissions.can("update", "resources") || isCompleted}
onChange={(date) => {
onUpdate("plannedEndTime", date?.toString() ?? null);
}}
@@ -434,7 +434,7 @@ const MaintenanceDispatchProperties = () => {
name="actualStartTime"
label="Actual Start"
inline
- isDisabled={!permissions.can("update", "production") || isCompleted}
+ isDisabled={!permissions.can("update", "resources") || isCompleted}
onChange={(date) => {
onUpdate("actualStartTime", date?.toString() ?? null);
}}
@@ -454,7 +454,7 @@ const MaintenanceDispatchProperties = () => {
name="actualEndTime"
label="Actual End"
inline
- isDisabled={!permissions.can("update", "production") || isCompleted}
+ isDisabled={!permissions.can("update", "resources") || isCompleted}
onChange={(date) => {
onUpdate("actualEndTime", date?.toString() ?? null);
}}
@@ -478,7 +478,7 @@ const MaintenanceDispatchProperties = () => {
value: mode.id,
label: mode.name
}))}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="Suspected Failure Mode"
name="suspectedFailureModeId"
inline={(value) => {
@@ -511,7 +511,7 @@ const MaintenanceDispatchProperties = () => {
value: mode.id,
label: mode.name
}))}
- isReadOnly={!permissions.can("update", "production")}
+ isReadOnly={!permissions.can("update", "resources")}
label="Actual Failure Mode"
name="actualFailureModeId"
inline={(value) => {
@@ -642,12 +642,12 @@ const MaintenanceDispatchProperties = () => {
<DateTimePicker
name="startTime"
label="Start Time"
- isDisabled={!permissions.can("update", "production")}
+ isDisabled={!permissions.can("update", "resources")}
/>
<DateTimePicker
name="endTime"
label="End Time"
- isDisabled={!permissions.can("update", "production")}
+ isDisabled={!permissions.can("update", "resources")}
/>
</VStack>
</ModalBody>
@@ -664,7 +664,7 @@ const MaintenanceDispatchProperties = () => {
<Button
type="submit"
isLoading={eventFetcher.state !== "idle"}
- isDisabled={!permissions.can("update", "production")}
+ isDisabled={!permissions.can("update", "resources")}
>
Save
</Button>
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchesTable.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchesTable.tsx
similarity index 98%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchesTable.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchesTable.tsx
index 3d9f45d43b..6f2a55b145 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceDispatchesTable.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchesTable.tsx
@@ -27,7 +27,7 @@ import {
maintenanceDispatchStatus,
maintenanceSource,
oeeImpact
-} from "../../production.models";
+} from "../../resources.models";
import type { MaintenanceDispatch } from "../../types";
import MaintenanceOeeImpact from "./MaintenanceOeeImpact";
import MaintenancePriority from "./MaintenancePriority";
@@ -322,7 +322,7 @@ const MaintenanceDispatchesTable = memo(
</MenuItem>
<MenuItem
destructive
- disabled={!permissions.can("delete", "production")}
+ disabled={!permissions.can("delete", "resources")}
onClick={() => {
navigate(
`${path.to.deleteMaintenanceDispatch(row.id)}?${params.toString()}`
@@ -352,7 +352,7 @@ const MaintenanceDispatchesTable = memo(
}}
count={count}
primaryAction={
- permissions.can("create", "production") && (
+ permissions.can("create", "resources") && (
<New
label="Dispatch"
to={`${path.to.newMaintenanceDispatch}?${params.toString()}`}
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceOeeImpact.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceOeeImpact.tsx
similarity index 96%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceOeeImpact.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceOeeImpact.tsx
index 216a3c69fd..b99dcd73e0 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceOeeImpact.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceOeeImpact.tsx
@@ -5,7 +5,7 @@ import {
LuCircleX,
LuTriangleAlert
} from "react-icons/lu";
-import type { oeeImpact } from "../../production.models";
+import type { oeeImpact } from "../../resources.models";
type MaintenanceOeeImpactProps = {
oeeImpact?: (typeof oeeImpact)[number] | null;
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenancePriority.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenancePriority.tsx
similarity index 94%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenancePriority.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenancePriority.tsx
index e7d3dfee88..a1b0c47f28 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenancePriority.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenancePriority.tsx
@@ -2,7 +2,7 @@ import { BsExclamationSquareFill } from "react-icons/bs";
import { HighPriorityIcon } from "~/assets/icons/HighPriorityIcon";
import { LowPriorityIcon } from "~/assets/icons/LowPriorityIcon";
import { MediumPriorityIcon } from "~/assets/icons/MediumPriorityIcon";
-import type { maintenanceDispatchPriority } from "../../production.models";
+import type { maintenanceDispatchPriority } from "../../resources.models";
type MaintenancePriorityProps = {
priority?: (typeof maintenanceDispatchPriority)[number] | null;
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceSeverity.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceSeverity.tsx
similarity index 95%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceSeverity.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceSeverity.tsx
index 779a2d1942..7fb9e4aeaf 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceSeverity.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceSeverity.tsx
@@ -5,7 +5,7 @@ import {
LuTriangleAlert,
LuWrench
} from "react-icons/lu";
-import type { maintenanceSeverity } from "../../production.models";
+import type { maintenanceSeverity } from "../../resources.models";
type MaintenanceSeverityProps = {
severity?: (typeof maintenanceSeverity)[number] | null;
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceSource.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceSource.tsx
similarity index 94%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceSource.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceSource.tsx
index 741fcc0f21..966e23e436 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceSource.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceSource.tsx
@@ -5,7 +5,7 @@ import {
LuShieldX,
LuTriangleAlert
} from "react-icons/lu";
-import type { maintenanceSource } from "../../production.models";
+import type { maintenanceSource } from "../../resources.models";
type MaintenanceSourceProps = {
source?: (typeof maintenanceSource)[number] | null;
diff --git a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceStatus.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceStatus.tsx
similarity index 93%
rename from apps/erp/app/modules/production/ui/Maintenance/MaintenanceStatus.tsx
rename to apps/erp/app/modules/resources/ui/Maintenance/MaintenanceStatus.tsx
index 10b979c5ce..ce0f22c68e 100644
--- a/apps/erp/app/modules/production/ui/Maintenance/MaintenanceStatus.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceStatus.tsx
@@ -1,5 +1,5 @@
import { Status } from "@carbon/react";
-import type { maintenanceDispatchStatus } from "../../production.models";
+import type { maintenanceDispatchStatus } from "../../resources.models";
type MaintenanceStatusProps = {
status?: (typeof maintenanceDispatchStatus)[number] | null;
diff --git a/apps/erp/app/modules/production/ui/Maintenance/index.ts b/apps/erp/app/modules/resources/ui/Maintenance/index.ts
similarity index 100%
rename from apps/erp/app/modules/production/ui/Maintenance/index.ts
rename to apps/erp/app/modules/resources/ui/Maintenance/index.ts
diff --git a/apps/erp/app/modules/production/ui/MaintenanceSchedule/MaintenanceScheduleForm.tsx b/apps/erp/app/modules/resources/ui/MaintenanceSchedule/MaintenanceScheduleForm.tsx
similarity index 97%
rename from apps/erp/app/modules/production/ui/MaintenanceSchedule/MaintenanceScheduleForm.tsx
rename to apps/erp/app/modules/resources/ui/MaintenanceSchedule/MaintenanceScheduleForm.tsx
index 66883d247e..2391dccf0a 100644
--- a/apps/erp/app/modules/production/ui/MaintenanceSchedule/MaintenanceScheduleForm.tsx
+++ b/apps/erp/app/modules/resources/ui/MaintenanceSchedule/MaintenanceScheduleForm.tsx
@@ -20,6 +20,7 @@ import type { z } from "zod/v3";
import { HighPriorityIcon } from "~/assets/icons/HighPriorityIcon";
import { LowPriorityIcon } from "~/assets/icons/LowPriorityIcon";
import { MediumPriorityIcon } from "~/assets/icons/MediumPriorityIcon";
+import { Enumerable } from "~/components/Enumerable";
import { Hidden, Input, Submit, WorkCenter } from "~/components/Form";
import { usePermissions } from "~/hooks";
import { path } from "~/utils/path";
@@ -27,7 +28,7 @@ import {
maintenanceDispatchPriority,
maintenanceFrequency,
maintenanceScheduleValidator
-} from "../../production.models";
+} from "../../resources.models";
function getPriorityIcon(
priority: (typeof maintenanceDispatchPriority)[number]
@@ -115,7 +116,7 @@ const MaintenanceScheduleForm = ({
label="Frequency"
options={maintenanceFrequency.map((freq) => ({
value: freq,
- label: freq
+ label: <Enumerable value={freq} />
}))}
/>
<Select
diff --git a/apps/erp/app/modules/production/ui/MaintenanceSchedule/MaintenanceSchedulesTable.tsx b/apps/erp/app/modules/resources/ui/MaintenanceSchedule/MaintenanceSchedulesTable.tsx
similarity index 99%
rename from apps/erp/app/modules/production/ui/MaintenanceSchedule/MaintenanceSchedulesTable.tsx
rename to apps/erp/app/modules/resources/ui/MaintenanceSchedule/MaintenanceSchedulesTable.tsx
index 102561d705..a062c2bf7f 100644
--- a/apps/erp/app/modules/production/ui/MaintenanceSchedule/MaintenanceSchedulesTable.tsx
+++ b/apps/erp/app/modules/resources/ui/MaintenanceSchedule/MaintenanceSchedulesTable.tsx
@@ -21,7 +21,7 @@ import { path } from "~/utils/path";
import {
maintenanceDispatchPriority,
maintenanceFrequency
-} from "../../production.models";
+} from "../../resources.models";
import type { MaintenanceSchedule } from "../../types";
import { MaintenancePriority } from "../Maintenance";
diff --git a/apps/erp/app/modules/production/ui/MaintenanceSchedule/index.ts b/apps/erp/app/modules/resources/ui/MaintenanceSchedule/index.ts
similarity index 100%
rename from apps/erp/app/modules/production/ui/MaintenanceSchedule/index.ts
rename to apps/erp/app/modules/resources/ui/MaintenanceSchedule/index.ts
diff --git a/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx b/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
index d450d681ea..793c535c05 100644
--- a/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
+++ b/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
@@ -1,4 +1,6 @@
import {
+ LuCalendarClock,
+ LuCircleAlert,
LuClipboardCheck,
LuCog,
LuGraduationCap,
@@ -11,6 +13,28 @@ import type { RouteGroup } from "~/types";
import { path } from "~/utils/path";
const resourcesRoutes: RouteGroup[] = [
+ {
+ name: "Maintenance",
+ routes: [
+ {
+ name: "Dispatches",
+ to: path.to.maintenanceDispatches,
+ icon: <LuWrench />,
+ table: "maintenanceDispatch"
+ },
+ {
+ name: "Schedules",
+ to: path.to.maintenanceSchedules,
+ icon: <LuCalendarClock />,
+ table: "maintenanceSchedule"
+ },
+ {
+ name: "Failure Modes",
+ to: path.to.failureModes,
+ icon: <LuCircleAlert />
+ }
+ ]
+ },
{
name: "Infrastructure",
routes: [
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.comments.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.comments.tsx
index 5bce4188b6..4fa1bd0473 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.comments.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.comments.tsx
@@ -19,14 +19,14 @@ import { usePermissions, useRouteData } from "~/hooks";
import {
maintenanceDispatchCommentValidator,
upsertMaintenanceDispatchComment
-} from "~/modules/production";
-import type { MaintenanceDispatchComment } from "~/modules/production/types";
+} from "~/modules/resources";
+import type { MaintenanceDispatchComment } from "~/modules/resources/types";
import { path } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const { dispatchId } = params;
@@ -44,7 +44,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
const upsertComment = await upsertMaintenanceDispatchComment(client, {
...validation.data,
maintenanceDispatchId: dispatchId,
- createdBy: userId,
+ createdBy: validation.data.id ? undefined : userId,
+ // @ts-expect-error - stfu typescript
updatedBy: validation.data.id ? userId : undefined
});
@@ -87,7 +88,7 @@ export default function MaintenanceDispatchCommentsRoute() {
<h2 className="text-lg font-semibold">Comments</h2>
</HStack>
- {permissions.can("update", "production") && (
+ {permissions.can("update", "resources") && (
<Card>
<CardContent className="py-4">
<VStack spacing={2}>
@@ -127,10 +128,7 @@ export default function MaintenanceDispatchCommentsRoute() {
<VStack spacing={2}>
<HStack className="justify-between w-full">
<HStack>
- <EmployeeAvatar employeeId={c.createdBy} size="xs" />
- <span className="text-sm font-medium">
- {c.user?.fullName ?? "Unknown"}
- </span>
+ <EmployeeAvatar employeeId={c.createdBy.id} size="xs" />
</HStack>
<span className="text-xs text-muted-foreground">
{new Date(c.createdAt).toLocaleString()}
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.$eventId.delete.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.$eventId.delete.tsx
index f9213ebade..9c940bcc0d 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.$eventId.delete.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.$eventId.delete.tsx
@@ -3,13 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import type { ActionFunctionArgs } from "react-router";
import { redirect } from "react-router";
-import { deleteMaintenanceDispatchEvent } from "~/modules/production";
+import { deleteMaintenanceDispatchEvent } from "~/modules/resources";
import { path, requestReferrer } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client } = await requirePermissions(request, {
- delete: "production"
+ delete: "resources"
});
const { dispatchId, eventId } = params;
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.new.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.new.tsx
index 959281d51d..4465b09ce1 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.new.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.event.new.tsx
@@ -7,13 +7,13 @@ import { redirect } from "react-router";
import {
maintenanceDispatchEventValidator,
upsertMaintenanceDispatchEvent
-} from "~/modules/production";
+} from "~/modules/resources";
import { path, requestReferrer } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const { dispatchId } = params;
@@ -39,8 +39,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
employeeId,
workCenterId,
startTime,
- endTime: endTime ?? null,
- notes: notes ?? null,
+ endTime: endTime ?? undefined,
+ notes: notes ?? undefined,
companyId,
createdBy: userId
});
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.events.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.events.tsx
index 40401b9ae2..c7201729e6 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.events.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.events.tsx
@@ -16,17 +16,14 @@ import type { ActionFunctionArgs } from "react-router";
import { data, useFetcher, useParams } from "react-router";
import { EmployeeAvatar } from "~/components";
import { usePermissions, useRouteData, useUser } from "~/hooks";
-import {
- maintenanceDispatchEventValidator,
- upsertMaintenanceDispatchEvent
-} from "~/modules/production";
-import type { MaintenanceDispatchEvent } from "~/modules/production/types";
+import { maintenanceDispatchEventValidator } from "~/modules/resources";
+import type { MaintenanceDispatchEvent } from "~/modules/resources/types";
import { path } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
- update: "production"
+ const { client, companyId, userId } = await requirePermissions(request, {
+ update: "resources"
});
const { dispatchId } = params;
@@ -35,13 +32,33 @@ export async function action({ request, params }: ActionFunctionArgs) {
const formData = await request.formData();
const intent = formData.get("intent");
+ const dispatch = await client
+ .from("maintenanceDispatch")
+ .select("id, workCenterId")
+ .eq("id", dispatchId)
+ .single();
+ if (dispatch.error) {
+ return data(
+ {},
+ await flash(request, error(dispatch.error, "Failed to get dispatch"))
+ );
+ }
+
+ const { workCenterId } = dispatch.data;
+
if (intent === "start") {
- const insertEvent = await upsertMaintenanceDispatchEvent(client, {
- maintenanceDispatchId: dispatchId,
- employeeId: userId,
- startTime: new Date().toISOString(),
- createdBy: userId
- });
+ const insertEvent = await client
+ .from("maintenanceDispatchEvent")
+ .insert({
+ maintenanceDispatchId: dispatchId!,
+ employeeId: userId,
+ workCenterId,
+ startTime: new Date().toISOString(),
+ companyId,
+ createdBy: userId
+ })
+ .select("id")
+ .single();
if (insertEvent.error) {
return data(
@@ -57,11 +74,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
const eventId = formData.get("eventId") as string;
if (!eventId) throw new Error("eventId not found");
- const updateEvent = await upsertMaintenanceDispatchEvent(client, {
- id: eventId,
- endTime: new Date().toISOString(),
- updatedBy: userId
- });
+ const updateEvent = await client
+ .from("maintenanceDispatchEvent")
+ .update({
+ endTime: new Date().toISOString(),
+ updatedBy: userId
+ })
+ .eq("id", eventId);
if (updateEvent.error) {
return data(
@@ -81,11 +100,10 @@ export async function action({ request, params }: ActionFunctionArgs) {
return validationError(validation.error);
}
- const upsertEvent = await upsertMaintenanceDispatchEvent(client, {
+ const upsertEvent = await client.from("maintenanceDispatchEvent").insert({
...validation.data,
- maintenanceDispatchId: dispatchId,
- createdBy: userId,
- updatedBy: validation.data.id ? userId : undefined
+ companyId,
+ createdBy: userId
});
if (upsertEvent.error) {
@@ -112,14 +130,14 @@ export default function MaintenanceDispatchEventsRoute() {
const events = routeData?.events ?? [];
const activeEvent = events.find(
- (e) => e.employeeId === user.id && !e.endTime
+ (e) => e.employee?.id === user.id && !e.endTime
);
return (
<VStack spacing={4}>
<HStack className="justify-between w-full">
<h2 className="text-lg font-semibold">Time Events</h2>
- {permissions.can("update", "production") && (
+ {permissions.can("update", "resources") && (
<fetcher.Form method="post">
{activeEvent ? (
<>
@@ -165,7 +183,7 @@ export default function MaintenanceDispatchEventsRoute() {
<CardHeader className="pb-2">
<HStack className="justify-between">
<HStack>
- <EmployeeAvatar employeeId={event.employeeId} size="xs" />
+ <EmployeeAvatar employeeId={event.employee?.id} size="xs" />
<span className="text-sm font-medium">
{event.employee?.fullName ?? "Unknown"}
</span>
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.$itemId.delete.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.$itemId.delete.tsx
index 9d094d7fb8..e837ce2554 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.$itemId.delete.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.$itemId.delete.tsx
@@ -3,13 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import type { ActionFunctionArgs } from "react-router";
import { redirect } from "react-router";
-import { deleteMaintenanceDispatchItem } from "~/modules/production";
+import { deleteMaintenanceDispatchItem } from "~/modules/resources";
import { path, requestReferrer } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client } = await requirePermissions(request, {
- delete: "production"
+ delete: "resources"
});
const { dispatchId, itemId } = params;
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.new.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.new.tsx
index 8462281a04..416d09146d 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.new.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.item.new.tsx
@@ -5,12 +5,12 @@ import type { ActionFunctionArgs } from "react-router";
import {
maintenanceDispatchItemValidator,
upsertMaintenanceDispatchItem
-} from "~/modules/production";
+} from "~/modules/resources";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const { dispatchId } = params;
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.items.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.items.tsx
index 901f1da091..47330b1bc1 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.items.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.items.tsx
@@ -9,14 +9,14 @@ import { useRouteData } from "~/hooks";
import {
maintenanceDispatchItemValidator,
upsertMaintenanceDispatchItem
-} from "~/modules/production";
-import type { MaintenanceDispatchItem } from "~/modules/production/types";
+} from "~/modules/resources";
+import type { MaintenanceDispatchItem } from "~/modules/resources/types";
import { path } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const { dispatchId } = params;
@@ -34,7 +34,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
const upsertItem = await upsertMaintenanceDispatchItem(client, {
...validation.data,
maintenanceDispatchId: dispatchId,
- createdBy: userId,
+ createdBy: validation.data.id ? undefined : userId,
+ // @ts-expect-error - stfu typescript
updatedBy: validation.data.id ? userId : undefined
});
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.status.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.status.tsx
index 33b7bea120..146f67a7f9 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.status.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.status.tsx
@@ -6,13 +6,13 @@ import { redirect } from "react-router";
import {
maintenanceDispatchStatus,
upsertMaintenanceDispatch
-} from "~/modules/production";
+} from "~/modules/resources";
import { path, requestReferrer } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const { dispatchId } = params;
@@ -30,12 +30,14 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
- const update = await upsertMaintenanceDispatch(client, {
- id: dispatchId,
- status,
- assignee: ["Completed", "Cancelled"].includes(status) ? null : undefined,
- updatedBy: userId
- });
+ const update = await client
+ .from("maintenanceDispatch")
+ .update({
+ status,
+ assignee: ["Completed", "Cancelled"].includes(status) ? null : undefined,
+ updatedBy: userId
+ })
+ .eq("id", dispatchId);
if (update.error) {
throw redirect(
diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx
index 2426247773..45a199859e 100644
--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx
@@ -11,21 +11,21 @@ import {
getMaintenanceDispatchComments,
getMaintenanceDispatchEvents,
getMaintenanceDispatchItems
-} from "~/modules/production";
+} from "~/modules/resources";
import {
MaintenanceDispatchExplorer,
MaintenanceDispatchFiles,
MaintenanceDispatchHeader,
MaintenanceDispatchNotes,
MaintenanceDispatchProperties
-} from "~/modules/production/ui/Maintenance";
+} from "~/modules/resources/ui/Maintenance";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
export const handle: Handle = {
breadcrumb: "Maintenance",
to: path.to.maintenanceDispatches,
- module: "production"
+ module: "resources"
};
async function getMaintenanceDispatchFiles(
@@ -41,7 +41,7 @@ async function getMaintenanceDispatchFiles(
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
- view: "production"
+ view: "resources"
});
const { dispatchId } = params;
diff --git a/apps/erp/app/routes/x+/maintenance+/_layout.tsx b/apps/erp/app/routes/x+/maintenance+/_layout.tsx
index 2f396e8cd2..00cb3b7824 100644
--- a/apps/erp/app/routes/x+/maintenance+/_layout.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/_layout.tsx
@@ -8,9 +8,9 @@ export const meta: MetaFunction = () => {
};
export const handle: Handle = {
- breadcrumb: "Production",
- to: path.to.production,
- module: "production"
+ breadcrumb: "Resources",
+ to: path.to.resources,
+ module: "resources"
};
export default function MaintenanceRoute() {
diff --git a/apps/erp/app/routes/x+/maintenance+/new.tsx b/apps/erp/app/routes/x+/maintenance+/new.tsx
index 3110148707..9c2221e6e6 100644
--- a/apps/erp/app/routes/x+/maintenance+/new.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/new.tsx
@@ -9,8 +9,8 @@ import {
getFailureModesList,
maintenanceDispatchValidator,
upsertMaintenanceDispatch
-} from "~/modules/production";
-import { MaintenanceDispatchForm } from "~/modules/production/ui/Maintenance";
+} from "~/modules/resources";
+import { MaintenanceDispatchForm } from "~/modules/resources/ui/Maintenance";
import { getNextSequence } from "~/modules/settings";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
@@ -18,12 +18,12 @@ import { path } from "~/utils/path";
export const handle: Handle = {
breadcrumb: "Maintenance",
to: path.to.maintenanceDispatches,
- module: "production"
+ module: "resources"
};
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
- create: "production"
+ create: "resources"
});
const failureModes = await getFailureModesList(client, companyId);
@@ -36,7 +36,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId, userId } = await requirePermissions(request, {
- create: "production"
+ create: "resources"
});
const formData = await request.formData();
diff --git a/apps/erp/app/routes/x+/maintenance+/update.tsx b/apps/erp/app/routes/x+/maintenance+/update.tsx
index 75b36ae2f4..3929d9054d 100644
--- a/apps/erp/app/routes/x+/maintenance+/update.tsx
+++ b/apps/erp/app/routes/x+/maintenance+/update.tsx
@@ -1,10 +1,10 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { type ActionFunctionArgs } from "react-router";
-import { upsertMaintenanceDispatch } from "~/modules/production";
+import { upsertMaintenanceDispatch } from "~/modules/resources";
export async function action({ request }: ActionFunctionArgs) {
const { client, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const formData = await request.formData();
diff --git a/apps/erp/app/routes/x+/resources+/_index.tsx b/apps/erp/app/routes/x+/resources+/_index.tsx
index ee2acc927b..9cc12bf2b1 100644
--- a/apps/erp/app/routes/x+/resources+/_index.tsx
+++ b/apps/erp/app/routes/x+/resources+/_index.tsx
@@ -2,5 +2,5 @@ import { redirect } from "react-router";
import { path } from "~/utils/path";
export async function loader() {
- throw redirect(path.to.workCenters);
+ throw redirect(path.to.maintenanceDispatches);
}
diff --git a/apps/erp/app/routes/x+/production+/failure-modes.$failureModeId.tsx b/apps/erp/app/routes/x+/resources+/failure-modes.$failureModeId.tsx
similarity index 93%
rename from apps/erp/app/routes/x+/production+/failure-modes.$failureModeId.tsx
rename to apps/erp/app/routes/x+/resources+/failure-modes.$failureModeId.tsx
index d256176682..f2f63b0c5f 100644
--- a/apps/erp/app/routes/x+/production+/failure-modes.$failureModeId.tsx
+++ b/apps/erp/app/routes/x+/resources+/failure-modes.$failureModeId.tsx
@@ -8,14 +8,14 @@ import {
failureModeValidator,
getFailureMode,
upsertFailureMode
-} from "~/modules/production";
-import FailureModeForm from "~/modules/production/ui/FailureModes/FailureModeForm";
+} from "~/modules/resources";
+import FailureModeForm from "~/modules/resources/ui/FailureModes/FailureModeForm";
import { getCustomFields, setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
@@ -42,7 +42,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const formData = await request.formData();
diff --git a/apps/erp/app/routes/x+/production+/failure-modes.delete.$failureModeId.tsx b/apps/erp/app/routes/x+/resources+/failure-modes.delete.$failureModeId.tsx
similarity index 95%
rename from apps/erp/app/routes/x+/production+/failure-modes.delete.$failureModeId.tsx
rename to apps/erp/app/routes/x+/resources+/failure-modes.delete.$failureModeId.tsx
index 77874eb226..b1f7ef3fc3 100644
--- a/apps/erp/app/routes/x+/production+/failure-modes.delete.$failureModeId.tsx
+++ b/apps/erp/app/routes/x+/resources+/failure-modes.delete.$failureModeId.tsx
@@ -4,12 +4,12 @@ import { flash } from "@carbon/auth/session.server";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { redirect, useLoaderData, useNavigate, useParams } from "react-router";
import { ConfirmDelete } from "~/components/Modals";
-import { deleteFailureMode, getFailureMode } from "~/modules/production";
+import { deleteFailureMode, getFailureMode } from "~/modules/resources";
import { getParams, path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
const { failureModeId } = params;
@@ -31,7 +31,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export async function action({ request, params }: ActionFunctionArgs) {
const { client } = await requirePermissions(request, {
- delete: "production"
+ delete: "resources"
});
const { failureModeId } = params;
diff --git a/apps/erp/app/routes/x+/production+/failure-modes.new.tsx b/apps/erp/app/routes/x+/resources+/failure-modes.new.tsx
similarity index 91%
rename from apps/erp/app/routes/x+/production+/failure-modes.new.tsx
rename to apps/erp/app/routes/x+/resources+/failure-modes.new.tsx
index f845b35ac1..ce3e64fe3d 100644
--- a/apps/erp/app/routes/x+/production+/failure-modes.new.tsx
+++ b/apps/erp/app/routes/x+/resources+/failure-modes.new.tsx
@@ -4,14 +4,13 @@ import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { redirect, useNavigate } from "react-router";
-import { failureModeValidator, upsertFailureMode } from "~/modules/production";
-import FailureModeForm from "~/modules/production/ui/FailureModes/FailureModeForm";
-import { setCustomFields } from "~/utils/form";
+import { failureModeValidator, upsertFailureMode } from "~/modules/resources";
+import FailureModeForm from "~/modules/resources/ui/FailureModes/FailureModeForm";
import { getParams, path, requestReferrer } from "~/utils/path";
export async function loader({ request }: LoaderFunctionArgs) {
await requirePermissions(request, {
- create: "production"
+ create: "resources"
});
return null;
@@ -20,7 +19,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId, userId } = await requirePermissions(request, {
- create: "production"
+ create: "resources"
});
const formData = await request.formData();
diff --git a/apps/erp/app/routes/x+/production+/failure-modes.tsx b/apps/erp/app/routes/x+/resources+/failure-modes.tsx
similarity index 87%
rename from apps/erp/app/routes/x+/production+/failure-modes.tsx
rename to apps/erp/app/routes/x+/resources+/failure-modes.tsx
index 6c2a69101c..0741d3df85 100644
--- a/apps/erp/app/routes/x+/production+/failure-modes.tsx
+++ b/apps/erp/app/routes/x+/resources+/failure-modes.tsx
@@ -2,8 +2,8 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { VStack } from "@carbon/react";
import type { LoaderFunctionArgs } from "react-router";
import { Outlet, useLoaderData } from "react-router";
-import { getFailureModes } from "~/modules/production";
-import FailureModesTable from "~/modules/production/ui/FailureModes/FailureModesTable";
+import { getFailureModes } from "~/modules/resources";
+import FailureModesTable from "~/modules/resources/ui/FailureModes/FailureModesTable";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
import { getGenericQueryFilters } from "~/utils/query";
@@ -15,7 +15,7 @@ export const handle: Handle = {
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
diff --git a/apps/erp/app/routes/x+/production+/maintenance.delete.$dispatchId.tsx b/apps/erp/app/routes/x+/resources+/maintenance.delete.$dispatchId.tsx
similarity index 97%
rename from apps/erp/app/routes/x+/production+/maintenance.delete.$dispatchId.tsx
rename to apps/erp/app/routes/x+/resources+/maintenance.delete.$dispatchId.tsx
index 942df395be..ec9b6e7b21 100644
--- a/apps/erp/app/routes/x+/production+/maintenance.delete.$dispatchId.tsx
+++ b/apps/erp/app/routes/x+/resources+/maintenance.delete.$dispatchId.tsx
@@ -7,12 +7,12 @@ import { ConfirmDelete } from "~/components/Modals";
import {
deleteMaintenanceDispatch,
getMaintenanceDispatch
-} from "~/modules/production";
+} from "~/modules/resources";
import { getParams, path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
const { dispatchId } = params;
diff --git a/apps/erp/app/routes/x+/production+/maintenance.tsx b/apps/erp/app/routes/x+/resources+/maintenance.tsx
similarity index 91%
rename from apps/erp/app/routes/x+/production+/maintenance.tsx
rename to apps/erp/app/routes/x+/resources+/maintenance.tsx
index abd89915ff..d8c0ef113c 100644
--- a/apps/erp/app/routes/x+/production+/maintenance.tsx
+++ b/apps/erp/app/routes/x+/resources+/maintenance.tsx
@@ -5,8 +5,8 @@ import { Outlet, useLoaderData } from "react-router";
import {
getFailureModesList,
getMaintenanceDispatches
-} from "~/modules/production";
-import MaintenanceDispatchesTable from "~/modules/production/ui/Maintenance/MaintenanceDispatchesTable";
+} from "~/modules/resources";
+import MaintenanceDispatchesTable from "~/modules/resources/ui/Maintenance/MaintenanceDispatchesTable";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
import { getGenericQueryFilters } from "~/utils/query";
@@ -18,7 +18,7 @@ export const handle: Handle = {
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
diff --git a/apps/erp/app/routes/x+/production+/scheduled-maintenance.$scheduleId.tsx b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.$scheduleId.tsx
similarity index 93%
rename from apps/erp/app/routes/x+/production+/scheduled-maintenance.$scheduleId.tsx
rename to apps/erp/app/routes/x+/resources+/scheduled-maintenance.$scheduleId.tsx
index 85dbd6bb87..634dd62b3e 100644
--- a/apps/erp/app/routes/x+/production+/scheduled-maintenance.$scheduleId.tsx
+++ b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.$scheduleId.tsx
@@ -8,13 +8,13 @@ import {
getMaintenanceSchedule,
maintenanceScheduleValidator,
upsertMaintenanceSchedule
-} from "~/modules/production";
-import MaintenanceScheduleForm from "~/modules/production/ui/MaintenanceSchedule/MaintenanceScheduleForm";
+} from "~/modules/resources";
+import MaintenanceScheduleForm from "~/modules/resources/ui/MaintenanceSchedule/MaintenanceScheduleForm";
import { path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
@@ -41,7 +41,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- update: "production"
+ update: "resources"
});
const formData = await request.formData();
diff --git a/apps/erp/app/routes/x+/production+/scheduled-maintenance.delete.$scheduleId.tsx b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.delete.$scheduleId.tsx
similarity index 97%
rename from apps/erp/app/routes/x+/production+/scheduled-maintenance.delete.$scheduleId.tsx
rename to apps/erp/app/routes/x+/resources+/scheduled-maintenance.delete.$scheduleId.tsx
index 8a3ae12704..93f9207bf6 100644
--- a/apps/erp/app/routes/x+/production+/scheduled-maintenance.delete.$scheduleId.tsx
+++ b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.delete.$scheduleId.tsx
@@ -7,12 +7,12 @@ import { ConfirmDelete } from "~/components/Modals";
import {
deleteMaintenanceSchedule,
getMaintenanceSchedule
-} from "~/modules/production";
+} from "~/modules/resources";
import { getParams, path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
const { scheduleId } = params;
@@ -34,7 +34,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export async function action({ request, params }: ActionFunctionArgs) {
const { client } = await requirePermissions(request, {
- delete: "production"
+ delete: "resources"
});
const { scheduleId } = params;
diff --git a/apps/erp/app/routes/x+/production+/scheduled-maintenance.new.tsx b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.new.tsx
similarity index 92%
rename from apps/erp/app/routes/x+/production+/scheduled-maintenance.new.tsx
rename to apps/erp/app/routes/x+/resources+/scheduled-maintenance.new.tsx
index ab1f0615be..10aff0b593 100644
--- a/apps/erp/app/routes/x+/production+/scheduled-maintenance.new.tsx
+++ b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.new.tsx
@@ -7,13 +7,13 @@ import { redirect, useNavigate } from "react-router";
import {
maintenanceScheduleValidator,
upsertMaintenanceSchedule
-} from "~/modules/production";
-import MaintenanceScheduleForm from "~/modules/production/ui/MaintenanceSchedule/MaintenanceScheduleForm";
+} from "~/modules/resources";
+import MaintenanceScheduleForm from "~/modules/resources/ui/MaintenanceSchedule/MaintenanceScheduleForm";
import { getParams, path, requestReferrer } from "~/utils/path";
export async function loader({ request }: LoaderFunctionArgs) {
await requirePermissions(request, {
- create: "production"
+ create: "resources"
});
return null;
@@ -22,7 +22,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId, userId } = await requirePermissions(request, {
- create: "production"
+ create: "resources"
});
const formData = await request.formData();
diff --git a/apps/erp/app/routes/x+/production+/scheduled-maintenance.tsx b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsx
similarity index 86%
rename from apps/erp/app/routes/x+/production+/scheduled-maintenance.tsx
rename to apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsx
index b38d59559f..8426cf6142 100644
--- a/apps/erp/app/routes/x+/production+/scheduled-maintenance.tsx
+++ b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsx
@@ -2,8 +2,8 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { VStack } from "@carbon/react";
import type { LoaderFunctionArgs } from "react-router";
import { Outlet, useLoaderData } from "react-router";
-import { getMaintenanceSchedules } from "~/modules/production";
-import MaintenanceSchedulesTable from "~/modules/production/ui/MaintenanceSchedule/MaintenanceSchedulesTable";
+import { getMaintenanceSchedules } from "~/modules/resources";
+import MaintenanceSchedulesTable from "~/modules/resources/ui/MaintenanceSchedule/MaintenanceSchedulesTable";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
import { getGenericQueryFilters } from "~/utils/query";
@@ -15,7 +15,7 @@ export const handle: Handle = {
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
- view: "production",
+ view: "resources",
role: "employee"
});
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 737439f33a..a5f12e514b 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -49,7 +49,7 @@ export const path = {
docs: `${api}/docs`,
employeeTypes: `${api}/users/employee-types`,
emptyPermissions: `${api}/users/empty-permissions`,
- failureModes: `${api}/production/failure-modes`,
+ failureModes: `${api}/resources/failure-modes`,
gauges: `${api}/quality/gauges`,
generateCsvColumns: (table: string) =>
generatePath(`${api}/ai/csv/${table}/columns`),
@@ -76,8 +76,8 @@ export const path = {
kanbanJobLink: (id: string) => generatePath(`${api}/kanban/link/${id}`),
kanbanStart: (id: string) => generatePath(`${api}/kanban/start/${id}`),
locations: `${api}/resources/locations`,
- maintenanceDispatches: `${api}/production/maintenance`,
- maintenanceSchedules: `${api}/production/scheduled-maintenance`,
+ maintenanceDispatches: `${api}/resources/maintenance`,
+ maintenanceSchedules: `${api}/resources/scheduled-maintenance`,
materialDimensions: (formId: string) =>
generatePath(`${api}/items/dimensions/${formId}`),
materialFinishes: (substanceId: string) =>
@@ -541,7 +541,7 @@ export const path = {
deleteEmployeeType: (id: string) =>
generatePath(`${x}/users/employee-types/delete/${id}`),
deleteFailureMode: (id: string) =>
- generatePath(`${x}/production/failure-modes/delete/${id}`),
+ generatePath(`${x}/resources/failure-modes/delete/${id}`),
deleteGauge: (id: string) =>
generatePath(`${x}/quality/gauges/delete/${id}`),
deleteGaugeCalibrationRecord: (id: string) =>
@@ -602,9 +602,9 @@ export const path = {
deleteKanban: (id: string) =>
generatePath(`${x}/inventory/kanbans/delete/${id}`),
deleteMaintenanceDispatch: (id: string) =>
- generatePath(`${x}/production/maintenance/delete/${id}`),
+ generatePath(`${x}/resources/maintenance/delete/${id}`),
deleteMaintenanceSchedule: (id: string) =>
- generatePath(`${x}/production/scheduled-maintenance/delete/${id}`),
+ generatePath(`${x}/resources/scheduled-maintenance/delete/${id}`),
deleteNoQuoteReason: (id: string) =>
generatePath(`${x}/sales/no-quote-reasons/delete/${id}`),
deleteCustomerPortal: (id: string) =>
@@ -747,8 +747,8 @@ export const path = {
generatePath(`/share/training/${assignmentId}`),
feedback: `${x}/feedback`,
failureMode: (id: string) =>
- generatePath(`${x}/production/failure-modes/${id}`),
- failureModes: `${x}/production/failure-modes`,
+ generatePath(`${x}/resources/failure-modes/${id}`),
+ failureModes: `${x}/resources/failure-modes`,
fiscalYears: `${x}/accounting/years`,
gauge: (id: string) => generatePath(`${x}/quality/gauges/${id}`),
gauges: `${x}/quality/gauges`,
@@ -876,10 +876,10 @@ export const path = {
generatePath(`${x}/maintenance/${dispatchId}/event/new`),
deleteMaintenanceDispatchEvent: (dispatchId: string, eventId: string) =>
generatePath(`${x}/maintenance/${dispatchId}/event/${eventId}/delete`),
- maintenanceDispatches: `${x}/production/maintenance`,
+ maintenanceDispatches: `${x}/resources/maintenance`,
maintenanceSchedule: (id: string) =>
- generatePath(`${x}/production/scheduled-maintenance/${id}`),
- maintenanceSchedules: `${x}/production/scheduled-maintenance`,
+ generatePath(`${x}/resources/scheduled-maintenance/${id}`),
+ maintenanceSchedules: `${x}/resources/scheduled-maintenance`,
makeMethodGet: `${x}/items/methods/get`,
makeMethodSave: `${x}/items/methods/save`,
markTrainingComplete: `${x}/resources/assignments/complete`,
@@ -974,7 +974,7 @@ export const path = {
newEmployeeAbility: (id: string) =>
generatePath(`${x}/resources/ability/${id}/employee/new`),
newEmployeeType: `${x}/users/employee-types/new`,
- newFailureMode: `${x}/production/failure-modes/new`,
+ newFailureMode: `${x}/resources/failure-modes/new`,
newFixture: `${x}/fixture/new`,
newFixtureSupplier: (id: string) =>
generatePath(`${x}/fixture/${id}/purchasing/new`),
@@ -1003,7 +1003,7 @@ export const path = {
newKanban: `${x}/inventory/kanbans/new`,
newLocation: `${x}/resources/locations/new`,
newMaintenanceDispatch: `${x}/maintenance/new`,
- newMaintenanceSchedule: `${x}/production/scheduled-maintenance/new`,
+ newMaintenanceSchedule: `${x}/resources/scheduled-maintenance/new`,
newMakeMethodVersion: `${x}/items/methods/version/new`,
newMaterial: `${x}/material/new`,
newMethodMaterial: `${x}/items/methods/material/new`,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 4a4bbb1ca3..6652e054f1 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -49513,14 +49513,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 4a4bbb1ca3..6652e054f1 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -49513,14 +49513,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]