@tthr/vue 0.0.67 → 0.0.68
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.
|
@@ -194,13 +194,17 @@ function createDatabaseProxy(apiKey, url, projectId) {
|
|
|
194
194
|
},
|
|
195
195
|
upsert: async (options) => {
|
|
196
196
|
const whereObj = options.where;
|
|
197
|
-
const id = whereObj?.id;
|
|
198
197
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
// Try to find existing record using the where clause
|
|
199
|
+
// This allows upserting on any field (e.g. clip_id, email, etc.)
|
|
200
|
+
const existing = await makeRequest('findFirst', { where: whereObj }).catch(() => null);
|
|
202
201
|
|
|
203
202
|
if (existing) {
|
|
203
|
+
// Use _id from the found record for the update
|
|
204
|
+
const id = existing._id ?? existing.id;
|
|
205
|
+
if (!id) {
|
|
206
|
+
throw new Error('Found record has no _id or id field for update');
|
|
207
|
+
}
|
|
204
208
|
await makeMutation('update', { id, data: options.update });
|
|
205
209
|
return { ...existing, ...options.update };
|
|
206
210
|
} else {
|