realtimex-crm 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realtimex-crm",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "description": "RealTimeX CRM - A full-featured CRM built with React, shadcn-admin-kit, and Supabase. Fork of Atomic CRM with RealTimeX App SDK integration.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -73,65 +73,55 @@ async function createActivity(apiKey: any, req: Request) {
73
73
  const body = await req.json();
74
74
  const { type, ...activityData } = body;
75
75
 
76
- // Activities can be notes or tasks
77
- if (type === "note" || type === "contact_note") {
78
- const { data, error } = await supabaseAdmin
79
- .from("contactNotes")
80
- .insert({
81
- ...activityData,
82
- sales_id: apiKey.sales_id,
83
- })
84
- .select()
85
- .single();
76
+ // Map activity type to table and validate
77
+ let tableName: string;
78
+ let responseType: string;
86
79
 
87
- if (error) {
88
- return createErrorResponse(400, error.message);
89
- }
90
-
91
- return new Response(JSON.stringify({ data, type: "note" }), {
92
- status: 201,
93
- headers: { "Content-Type": "application/json", ...corsHeaders },
94
- });
95
- } else if (type === "task") {
96
- const { data, error } = await supabaseAdmin
97
- .from("tasks")
98
- .insert({
99
- ...activityData,
100
- sales_id: apiKey.sales_id,
101
- })
102
- .select()
103
- .single();
104
-
105
- if (error) {
106
- return createErrorResponse(400, error.message);
107
- }
108
-
109
- return new Response(JSON.stringify({ data, type: "task" }), {
110
- status: 201,
111
- headers: { "Content-Type": "application/json", ...corsHeaders },
112
- });
113
- } else if (type === "deal_note") {
114
- const { data, error } = await supabaseAdmin
115
- .from("dealNotes")
116
- .insert({
117
- ...activityData,
118
- sales_id: apiKey.sales_id,
119
- })
120
- .select()
121
- .single();
80
+ switch (type) {
81
+ case "note":
82
+ case "contact_note":
83
+ tableName = "contactNotes";
84
+ responseType = "contact_note";
85
+ break;
86
+ case "company_note":
87
+ tableName = "companyNotes";
88
+ responseType = "company_note";
89
+ break;
90
+ case "deal_note":
91
+ tableName = "dealNotes";
92
+ responseType = "deal_note";
93
+ break;
94
+ case "task_note":
95
+ tableName = "taskNotes";
96
+ responseType = "task_note";
97
+ break;
98
+ case "task":
99
+ tableName = "tasks";
100
+ responseType = "task";
101
+ break;
102
+ default:
103
+ return createErrorResponse(
104
+ 400,
105
+ "Invalid activity type. Must be 'contact_note', 'company_note', 'deal_note', 'task_note', or 'task'"
106
+ );
107
+ }
122
108
 
123
- if (error) {
124
- return createErrorResponse(400, error.message);
125
- }
109
+ // Insert activity
110
+ const { data, error } = await supabaseAdmin
111
+ .from(tableName)
112
+ .insert({
113
+ ...activityData,
114
+ sales_id: apiKey.sales_id,
115
+ })
116
+ .select()
117
+ .single();
126
118
 
127
- return new Response(JSON.stringify({ data, type: "deal_note" }), {
128
- status: 201,
129
- headers: { "Content-Type": "application/json", ...corsHeaders },
130
- });
131
- } else {
132
- return createErrorResponse(
133
- 400,
134
- "Invalid activity type. Must be 'note', 'contact_note', 'task', or 'deal_note'"
135
- );
119
+ if (error) {
120
+ return createErrorResponse(400, error.message);
136
121
  }
122
+
123
+ return new Response(JSON.stringify({ data, type: responseType }), {
124
+ status: 201,
125
+ headers: { "Content-Type": "application/json", ...corsHeaders },
126
+ });
137
127
  }