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.

changes for comments

Sid Gaikwad2b00add884d6
diff --git a/apps/erp/app/modules/users/users.server.ts b/apps/erp/app/modules/users/users.server.ts
index 5f21b943a0..97723a27c7 100644
--- a/apps/erp/app/modules/users/users.server.ts
+++ b/apps/erp/app/modules/users/users.server.ts
@@ -446,11 +446,7 @@ export async function createEmployeeAccount(
await deleteAuthAccount(serviceRole, userId);
} else {
// Clean up the employee record that was successfully inserted
- await serviceRole
- .from("employee")
- .delete()
- .eq("id", userId)
- .eq("companyId", companyId);
+ await deleteEmployee(serviceRole, userId, companyId);
}
return { success: false, message: jobInsert.error.message };
}
@@ -461,16 +457,8 @@ export async function createEmployeeAccount(
} else {
// Clean up the employee and job records that were successfully inserted
await Promise.all([
- serviceRole
- .from("employee")
- .delete()
- .eq("id", userId)
- .eq("companyId", companyId),
- serviceRole
- .from("employeeJob")
- .delete()
- .eq("id", userId)
- .eq("companyId", companyId)
+ deleteEmployee(serviceRole, userId, companyId),
+ deleteEmployeeJob(serviceRole, userId, companyId)
]);
}
return { success: false, message: inviteInsert.error.message };
@@ -738,6 +726,30 @@ export async function insertEmployee(
return client.from("employee").insert([employee]).select("*").single();
}
+async function deleteEmployee(
+ client: SupabaseClient<Database>,
+ userId: string,
+ companyId: string
+) {
+ return client
+ .from("employee")
+ .delete()
+ .eq("id", userId)
+ .eq("companyId", companyId);
+}
+
+async function deleteEmployeeJob(
+ client: SupabaseClient<Database>,
+ userId: string,
+ companyId: string
+) {
+ return client
+ .from("employeeJob")
+ .delete()
+ .eq("id", userId)
+ .eq("companyId", companyId);
+}
+
export async function insertInvite(
client: SupabaseClient<Database>,
invite: InviteInsert