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: remove ununused documenttypes

Brad Barbin5d8416c14718
diff --git a/apps/erp/app/routes/api+/integrations.slack.interactive.ts b/apps/erp/app/routes/api+/integrations.slack.interactive.ts
index 54c30de65a..37a51a005b 100644
--- a/apps/erp/app/routes/api+/integrations.slack.interactive.ts
+++ b/apps/erp/app/routes/api+/integrations.slack.interactive.ts
@@ -18,7 +18,6 @@ export const config = {
runtime: "nodejs",
};
-// Slack interactive payload schema
const slackInteractivePayloadSchema = z.object({
type: z.string(),
team: z.object({
@@ -41,7 +40,6 @@ const slackInteractivePayloadSchema = z.object({
export async function action({ request }: ActionFunctionArgs) {
try {
- // Verify the request is from Slack
const formData = await request.formData();
const payloadString = formData.get("payload") as string;
@@ -53,10 +51,8 @@ export async function action({ request }: ActionFunctionArgs) {
JSON.parse(payloadString)
);
- // Get the service role client
const serviceRole = await getCarbonServiceRole();
- // Get the Slack integration for this team
const integration = await getIntegration(
serviceRole,
"slack",
@@ -80,7 +76,6 @@ export async function action({ request }: ActionFunctionArgs) {
});
}
- // Handle different interaction types
switch (payload.type) {
case "block_actions":
return handleBlockActions(payload, companyId, slackToken);
@@ -94,7 +89,6 @@ export async function action({ request }: ActionFunctionArgs) {
);
case "view_closed":
- // User closed the modal without submitting
return json({ ok: true });
default:
@@ -130,14 +124,12 @@ async function handleBlockActions(
switch (action.action_id) {
case "open_ncr_modal":
- // Get lists for the modal
const serviceRole = await getCarbonServiceRole();
const [types, workflows] = await Promise.all([
getIssueTypesList(serviceRole, companyId),
getIssueWorkflowsList(serviceRole, companyId),
]);
- // Open the NCR creation modal
await slackClient.views.open({
trigger_id: payload.trigger_id,
view: {
@@ -296,7 +288,6 @@ async function handleViewSubmission(
}
try {
- // Extract form values
const values = view.state.values;
const title = values.title_block.title.value;
const description = values.description_block?.description?.value || "";
@@ -305,11 +296,9 @@ async function handleViewSubmission(
const severity =
values.severity_block?.severity?.selected_option?.value || "Medium";
- // Parse metadata
const metadata = JSON.parse(view.private_metadata);
const { channel_id, user_id } = metadata;
- // Get next sequence number
const nextSequence = await getNextSequence(
serviceRole,
"nonConformance",
@@ -320,15 +309,14 @@ async function handleViewSubmission(
throw new Error("Failed to get next sequence number");
}
- // Create the non-conformance
const createResult = await upsertIssue(serviceRole, {
nonConformanceId: nextSequence.data,
approvalRequirements: [],
companyId,
- createdBy: "system", // TODO: Map Slack user to system user
+ createdBy: "system",
description,
investigationTypeIds: [],
- locationId: "", // TODO
+ locationId: "",
name: title,
nonConformanceTypeId: typeId,
nonConformanceWorkflowId: workflowId,
@@ -345,7 +333,6 @@ async function handleViewSubmission(
const ncrId = createResult.data.id;
const slackClient = createSlackWebClient({ token: slackToken });
- // Post initial message to channel
const threadMessage = await slackClient.chat.postMessage({
channel: channel_id,
unfurl_links: false,
@@ -403,7 +390,6 @@ async function handleViewSubmission(
],
});
- // Store the thread mapping in the database
if (threadMessage.ts) {
await serviceRole.from("slackDocumentThread").insert({
documentType: "nonConformance",
@@ -414,7 +400,6 @@ async function handleViewSubmission(
createdBy: user_id,
});
- // Trigger async job to sync additional details
await tasks.trigger("slack-document-created", {
documentType: "nonConformance",
documentId: ncrId,
@@ -424,14 +409,12 @@ async function handleViewSubmission(
});
}
- // Close the modal with success
return json({
response_action: "clear",
});
} catch (error) {
console.error("Error creating NCR:", error);
- // Show error in modal
return json({
response_action: "errors",
errors: {
diff --git a/packages/integrations/src/slack/lib/messages.ts b/packages/integrations/src/slack/lib/messages.ts
index 986a6ecc9c..e36c89fa91 100644
--- a/packages/integrations/src/slack/lib/messages.ts
+++ b/packages/integrations/src/slack/lib/messages.ts
@@ -1,14 +1,13 @@
import type { KnownBlock } from "@slack/types";
-export type DocumentType =
- | "nonConformance"
- | "quote"
- | "salesOrder"
- | "job"
- | "purchaseOrder"
- | "invoice"
- | "receipt"
- | "shipment";
+export type DocumentType = "nonConformance";
+// | "quote"
+// | "salesOrder"
+// | "job"
+// | "purchaseOrder"
+// | "invoice"
+// | "receipt"
+// | "shipment";
export interface BaseDocumentData {
id: string;
@@ -34,35 +33,9 @@ export interface NonConformanceData extends BaseDocumentData {
requiredActions?: string[];
}
-export interface QuoteData extends BaseDocumentData {
- documentType: "quote";
- quoteId: string;
- customerName?: string;
- expirationDate?: string;
-}
-
-export interface SalesOrderData extends BaseDocumentData {
- documentType: "salesOrder";
- salesOrderId: string;
- customerName?: string;
- deliveryDate?: string;
-}
+export type DocumentData = NonConformanceData;
-export interface JobData extends BaseDocumentData {
- documentType: "job";
- jobId: string;
- partNumber?: string;
- quantity?: number;
- dueDate?: string;
-}
-
-export type DocumentData =
- | NonConformanceData
- | QuoteData
- | SalesOrderData
- | JobData;
-
-export interface TaskUpdate {
+export interface IssueTaskUpdate {
taskType: "investigation" | "action" | "approval";
taskName: string;
status: string;
@@ -72,22 +45,19 @@ export interface TaskUpdate {
notes?: string;
}
-export interface StatusUpdate {
+export interface IssueStatusUpdate {
previousStatus: string;
newStatus: string;
updatedBy: string;
reason?: string;
}
-export interface AssignmentUpdate {
+export interface IssueAssignmentUpdate {
previousAssignee?: string;
newAssignee: string;
updatedBy: string;
}
-/**
- * Get document type display info
- */
function getDocumentTypeInfo(documentType: DocumentType): {
emoji: string;
name: string;
@@ -99,37 +69,6 @@ function getDocumentTypeInfo(documentType: DocumentType): {
name: "Issue",
urlPath: "/x/issue",
},
- quote: {
- emoji: "💰",
- name: "Quote",
- urlPath: "/x/quote",
- },
- salesOrder: {
- emoji: "📦",
- name: "Sales Order",
- urlPath: "/x/sales-order",
- },
- job: { emoji: "🔧", name: "Job", urlPath: "/x/job" },
- purchaseOrder: {
- emoji: "📋",
- name: "Purchase Order",
- urlPath: "/x/purchase-order",
- },
- invoice: {
- emoji: "🧾",
- name: "Invoice",
- urlPath: "/x/invoice",
- },
- receipt: {
- emoji: "📥",
- name: "Receipt",
- urlPath: "/x/receipt",
- },
- shipment: {
- emoji: "🚚",
- name: "Shipment",
- urlPath: "/x/shipment",
- },
};
return typeMap[documentType];
@@ -142,14 +81,8 @@ function getDocumentIdentifier(data: DocumentData): string {
switch (data.documentType) {
case "nonConformance":
return (data as NonConformanceData).nonConformanceId;
- case "quote":
- return (data as QuoteData).quoteId;
- case "salesOrder":
- return (data as SalesOrderData).salesOrderId;
- case "job":
- return (data as JobData).jobId;
+
default:
- // @ts-expect-error - this is a fallback for unknown document types
throw new Error(`Unknown document type: ${data.documentType}`);
}
}
@@ -273,42 +206,6 @@ function getDocumentSpecificFields(data: DocumentData): any[] {
});
}
break;
-
- case "quote":
- const quoteData = data as QuoteData;
- if (quoteData.customerName) {
- fields.push({
- type: "mrkdwn",
- text: `*Customer:*\n${quoteData.customerName}`,
- });
- }
- break;
-
- case "salesOrder":
- const soData = data as SalesOrderData;
- if (soData.customerName) {
- fields.push({
- type: "mrkdwn",
- text: `*Customer:*\n${soData.customerName}`,
- });
- }
- break;
-
- case "job":
- const jobData = data as JobData;
- if (jobData.partNumber) {
- fields.push({
- type: "mrkdwn",
- text: `*Part Number:*\n${jobData.partNumber}`,
- });
- }
- if (jobData.quantity) {
- fields.push({
- type: "mrkdwn",
- text: `*Quantity:*\n${jobData.quantity.toLocaleString()}`,
- });
- }
- break;
}
return fields;
@@ -348,36 +245,6 @@ function getDocumentSpecificSections(data: DocumentData): KnownBlock[] {
});
}
break;
-
- case "quote":
- const quoteData = data as QuoteData;
- if (quoteData.expirationDate) {
- sections.push({
- type: "section",
- text: {
- type: "mrkdwn",
- text: `*Expires:* <!date^${Math.floor(
- new Date(quoteData.expirationDate).getTime() / 1000
- )}^{date_short_pretty}|${quoteData.expirationDate}>`,
- },
- });
- }
- break;
-
- case "job":
- const jobData = data as JobData;
- if (jobData.dueDate) {
- sections.push({
- type: "section",
- text: {
- type: "mrkdwn",
- text: `*Due Date:* <!date^${Math.floor(
- new Date(jobData.dueDate).getTime() / 1000
- )}^{date_short_pretty}|${jobData.dueDate}>`,
- },
- });
- }
- break;
}
return sections;
@@ -389,7 +256,7 @@ function getDocumentSpecificSections(data: DocumentData): KnownBlock[] {
export function formatStatusUpdate(
documentType: DocumentType,
documentIdentifier: string,
- update: StatusUpdate
+ update: IssueStatusUpdate
): KnownBlock[] {
const typeInfo = getDocumentTypeInfo(documentType);
@@ -432,7 +299,7 @@ export function formatStatusUpdate(
export function formatTaskUpdate(
documentType: DocumentType,
documentIdentifier: string,
- update: TaskUpdate
+ update: IssueTaskUpdate
): KnownBlock[] {
const taskTypeLabel = {
investigation: "Investigation",
@@ -516,7 +383,7 @@ export function formatTaskUpdate(
export function formatAssignmentUpdate(
documentType: DocumentType,
documentIdentifier: string,
- update: AssignmentUpdate
+ update: IssueAssignmentUpdate
): KnownBlock[] {
const typeInfo = getDocumentTypeInfo(documentType);