Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
chore: remove approval notifications from notify task and routes
Ayush Soni8f0d82160403
diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsxindex ade597cf52..0fca776996 100644--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsx@@ -9,7 +9,6 @@ import { flash } from "@carbon/auth/session.server";import { PurchaseOrderEmail } from "@carbon/documents/email";import { validationError, validator } from "@carbon/form";import type { sendEmailResendTask } from "@carbon/jobs/trigger/send-email-resend"; // Assuming you have a sendEmail task defined-import { NotificationEvent } from "@carbon/notifications";import { renderAsync } from "@react-email/components";import { FunctionRegion } from "@supabase/supabase-js";import { tasks } from "@trigger.dev/sdk";@@ -127,7 +126,7 @@ export async function action(args: ActionFunctionArgs) {orderAmount);- const approvalResult = await createApprovalRequest(serviceRole, {+ await createApprovalRequest(serviceRole, {documentType: "purchaseOrder",documentId: orderId,companyId,@@ -137,42 +136,6 @@ export async function action(args: ActionFunctionArgs) {approverGroupIds: config.data?.approverGroupIds || undefined,approverId: config.data?.defaultApproverId || undefined});-- if (!approvalResult.error && approvalResult.data) {- // Notify approvers- let notifyRecipient:- | { type: "group"; groupIds: string[] }- | { type: "user"; userId: string }- | null = null;- if (- config.data?.approverGroupIds &&- config.data.approverGroupIds.length > 0- ) {- notifyRecipient = {- type: "group",- groupIds: config.data.approverGroupIds- };- } else if (config.data?.defaultApproverId) {- notifyRecipient = {- type: "user",- userId: config.data.defaultApproverId- };- }-- if (notifyRecipient) {- try {- await tasks.trigger("notify", {- event: NotificationEvent.ApprovalRequested,- companyId,- documentId: approvalResult.data.id,- recipient: notifyRecipient,- from: userId- });- } catch (err) {- console.error("Failed to notify approvers", err);- }- }- }}await updatePurchaseOrderStatus(client, {diff --git a/apps/erp/app/routes/x+/quality-document+/update.tsx b/apps/erp/app/routes/x+/quality-document+/update.tsxindex 1e9595ad64..203684982c 100644--- a/apps/erp/app/routes/x+/quality-document+/update.tsx+++ b/apps/erp/app/routes/x+/quality-document+/update.tsx@@ -1,7 +1,5 @@import { getCarbonServiceRole } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";-import { NotificationEvent } from "@carbon/notifications";-import { tasks } from "@trigger.dev/sdk";import { type ActionFunctionArgs } from "react-router";import {createApprovalRequest,@@ -74,55 +72,15 @@ export async function action({ request }: ActionFunctionArgs) {undefined);- const approvalResult = await createApprovalRequest(- serviceRole,- {- documentType: "qualityDocument",- documentId: doc.id,- companyId,- requestedBy: userId,- createdBy: userId,- approverGroupIds:- config.data?.approverGroupIds || undefined,- approverId: config.data?.defaultApproverId || undefined- }- );-- if (!approvalResult.error && approvalResult.data) {- // Notify approvers- let notifyRecipient:- | { type: "group"; groupIds: string[] }- | { type: "user"; userId: string }- | null = null;- if (- config.data?.approverGroupIds &&- config.data.approverGroupIds.length > 0- ) {- notifyRecipient = {- type: "group",- groupIds: config.data.approverGroupIds- };- } else if (config.data?.defaultApproverId) {- notifyRecipient = {- type: "user",- userId: config.data.defaultApproverId- };- }-- if (notifyRecipient) {- try {- await tasks.trigger("notify", {- event: NotificationEvent.ApprovalRequested,- companyId,- documentId: approvalResult.data.id,- recipient: notifyRecipient,- from: userId- });- } catch (err) {- console.error("Failed to notify approvers", err);- }- }- }+ await createApprovalRequest(serviceRole, {+ documentType: "qualityDocument",+ documentId: doc.id,+ companyId,+ requestedBy: userId,+ createdBy: userId,+ approverGroupIds: config.data?.approverGroupIds || undefined,+ approverId: config.data?.defaultApproverId || undefined+ });}}}diff --git a/apps/erp/app/routes/x+/settings+/approvals+/requests.$id.tsx b/apps/erp/app/routes/x+/settings+/approvals+/requests.$id.tsxindex af084a96a1..35b0806125 100644--- a/apps/erp/app/routes/x+/settings+/approvals+/requests.$id.tsx+++ b/apps/erp/app/routes/x+/settings+/approvals+/requests.$id.tsx@@ -2,8 +2,6 @@ import { error, getCarbonServiceRole } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";-import { NotificationEvent } from "@carbon/notifications";-import { tasks } from "@trigger.dev/sdk";import { useEffect } from "react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";import { redirect, useNavigate } from "react-router";@@ -77,7 +75,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { companyId, userId } = await requirePermissions(request, {+ const { userId } = await requirePermissions(request, {role: "employee"});@@ -161,24 +159,6 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- try {- await tasks.trigger("notify", {- event:- decision === "Approved"- ? NotificationEvent.ApprovalApproved- : NotificationEvent.ApprovalRejected,- companyId,- documentId: id,- recipient: {- type: "user" as const,- userId: approval.data.requestedBy- },- from: userId- });- } catch (err) {- console.error("Failed to notify requester", err);- }-// Return JSON response for fetcher requests// The modal will handle the response and refresh the datareturn Response.json({diff --git a/packages/jobs/trigger/notify.ts b/packages/jobs/trigger/notify.tsindex d7a6b5ac95..fb6fc7a333 100644--- a/packages/jobs/trigger/notify.ts+++ b/packages/jobs/trigger/notify.ts@@ -34,29 +34,22 @@ export const notifyTask = task({companyId: string;documentId: string;recipient:- | {- type: "user";- userId: string;- }- | {- type: "group";- groupIds: string[];- }- | {- type: "users";- userIds: string[];- };+ | {+ type: "user";+ userId: string;+ }+ | {+ type: "group";+ groupIds: string[];+ }+ | {+ type: "users";+ userIds: string[];+ };from?: string;}) => {if (isLocal) {- console.log("Skipping notify task on local environment", {- event: payload.event,- documentId: payload.documentId,- recipient: payload.recipient,- companyId: payload.companyId,- from: payload.from,- note: "Notifications are only sent in deployed environments. In local dev, check the approval requests page at /x/settings/approvals/requests"- });+ console.log("Skipping notify task on local", { payload });return;}@@ -64,10 +57,6 @@ export const notifyTask = task({function getWorkflow(type: NotificationEvent) {switch (type) {- case NotificationEvent.ApprovalRequested:- case NotificationEvent.ApprovalApproved:- case NotificationEvent.ApprovalRejected:- return NotificationWorkflow.Approval;case NotificationEvent.JobAssignment:case NotificationEvent.JobOperationAssignment:case NotificationEvent.MaintenanceDispatchAssignment:@@ -102,47 +91,6 @@ export const notifyTask = task({async function getDescription(type: NotificationEvent, documentId: string) {switch (type) {- case NotificationEvent.ApprovalRequested:- case NotificationEvent.ApprovalApproved:- case NotificationEvent.ApprovalRejected:- const approval = await client- .from("approvalRequest")- .select("*, user:requestedBy(fullName)")- .eq("id", documentId)- .single();-- if (approval.error) {- console.error("Failed to get approval", approval.error);- throw approval.error;- }-- // Get document readable ID based on type- let docReadableId = "";- if (approval.data.documentType === "purchaseOrder") {- const po = await client- .from("purchaseOrder")- .select("purchaseOrderId")- .eq("id", approval.data.documentId)- .single();- docReadableId = po.data?.purchaseOrderId || approval.data.documentId;- } else if (approval.data.documentType === "qualityDocument") {- const qd = await client- .from("qualityDocument")- .select("name")- .eq("id", approval.data.documentId)- .single();- docReadableId = qd.data?.name || approval.data.documentId;- }-- if (type === NotificationEvent.ApprovalRequested) {- return `Approval requested for ${approval.data.documentType === "purchaseOrder" ? "Purchase Order" : "Quality Document"} ${docReadableId}`;- } else if (type === NotificationEvent.ApprovalApproved) {- return `${approval.data.documentType === "purchaseOrder" ? "Purchase Order" : "Quality Document"} ${docReadableId} has been approved`;- } else if (type === NotificationEvent.ApprovalRejected) {- return `${approval.data.documentType === "purchaseOrder" ? "Purchase Order" : "Quality Document"} ${docReadableId} has been rejected`;- }- break;-case NotificationEvent.SalesRfqReady:case NotificationEvent.SalesRfqAssignment:const salesRfq = await client@@ -194,7 +142,7 @@ export const notifyTask = task({.select("*").eq("id", documentId).single();-+if (maintenanceDispatchCreated.error) {console.error("Failed to get maintenanceDispatchCreated", maintenanceDispatchCreated.error);throw maintenanceDispatchCreated.error;@@ -207,7 +155,7 @@ export const notifyTask = task({.select("*").eq("id", documentId).single();-+if (maintenanceDispatchAssignment.error) {console.error("Failed to get maintenanceDispatchAssignment", maintenanceDispatchAssignment.error);throw maintenanceDispatchAssignment.error;@@ -421,7 +369,7 @@ export const notifyTask = task({.eq("id", documentId).single();-+if (supplierQuote.error) {console.error("Failed to get supplier quote", supplierQuote.error);throw supplierQuote.error;@@ -541,12 +489,12 @@ export const notifyTask = task({const userIds =payload.recipient.type === "group"? await client.rpc("users_for_groups", {- groups: payload.recipient.groupIds,- })+ groups: payload.recipient.groupIds,+ }): {- data: payload.recipient.userIds,- error: null,- };+ data: payload.recipient.userIds,+ error: null,+ };if (userIds.error) {console.error("Failed to get userIds", userIds.error);diff --git a/packages/notifications/src/index.ts b/packages/notifications/src/index.tsindex 664976da4c..c62adf8ebc 100644--- a/packages/notifications/src/index.ts+++ b/packages/notifications/src/index.ts@@ -3,7 +3,6 @@ import { nanoid } from "nanoid";const API_ENDPOINT = "https://api.novu.co/v1";export enum NotificationWorkflow {- Approval = "approval",Assignment = "assignment",DigitalQuoteResponse = "digital-quote-response",Expiration = "expiration",@@ -15,9 +14,6 @@ export enum NotificationWorkflow {}export enum NotificationEvent {- ApprovalRequested = "approval-requested",- ApprovalApproved = "approval-approved",- ApprovalRejected = "approval-rejected",DigitalQuoteResponse = "digital-quote-response",GaugeCalibrationExpired = "gauge-calibration-expired",JobAssignment = "job-assignment",@@ -44,7 +40,6 @@ export enum NotificationEvent {}export enum NotificationType {- ApprovalInApp = "approval-in-app",AssignmentInApp = "assignment-in-app",DigitalQuoteResponseInApp = "digital-quote-response-in-app",JobCompletedInApp = "job-completed-in-app",