@rmdes/indiekit-endpoint-blogroll 1.0.13 → 1.0.14
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/lib/storage/blogs.js +31 -26
- package/package.json +1 -1
package/lib/storage/blogs.js
CHANGED
|
@@ -272,39 +272,44 @@ export async function upsertBlog(application, data) {
|
|
|
272
272
|
updatedAt: now,
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
-
// Conditionally add microsub fields when
|
|
276
|
-
if (data.source) setFields.source = data.source;
|
|
277
|
-
if (data.microsubFeedId) setFields.microsubFeedId = data.microsubFeedId;
|
|
278
|
-
if (data.microsubChannelId) setFields.microsubChannelId = data.microsubChannelId;
|
|
279
|
-
if (data.microsubChannelName) setFields.microsubChannelName = data.microsubChannelName;
|
|
275
|
+
// Conditionally add microsub/optional fields to $set when provided
|
|
276
|
+
if (data.source !== undefined) setFields.source = data.source;
|
|
277
|
+
if (data.microsubFeedId !== undefined) setFields.microsubFeedId = data.microsubFeedId;
|
|
278
|
+
if (data.microsubChannelId !== undefined) setFields.microsubChannelId = data.microsubChannelId;
|
|
279
|
+
if (data.microsubChannelName !== undefined) setFields.microsubChannelName = data.microsubChannelName;
|
|
280
280
|
if (data.skipItemFetch !== undefined) setFields.skipItemFetch = data.skipItemFetch;
|
|
281
|
-
if (data.photo) setFields.photo = data.photo;
|
|
281
|
+
if (data.photo !== undefined) setFields.photo = data.photo;
|
|
282
282
|
if (data.lastFetchAt !== undefined) setFields.lastFetchAt = data.lastFetchAt;
|
|
283
|
-
if (data.status) setFields.status = data.status;
|
|
283
|
+
if (data.status !== undefined) setFields.status = data.status;
|
|
284
|
+
|
|
285
|
+
// $setOnInsert only for fields NOT already in $set (avoids MongoDB path conflicts)
|
|
286
|
+
const insertDefaults = {
|
|
287
|
+
description: null,
|
|
288
|
+
tags: [],
|
|
289
|
+
author: null,
|
|
290
|
+
lastError: null,
|
|
291
|
+
itemCount: 0,
|
|
292
|
+
pinned: false,
|
|
293
|
+
hidden: false,
|
|
294
|
+
notes: null,
|
|
295
|
+
createdAt: now,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// Add defaults for optional fields only when they're NOT in $set
|
|
299
|
+
if (!("source" in setFields)) insertDefaults.source = null;
|
|
300
|
+
if (!("microsubFeedId" in setFields)) insertDefaults.microsubFeedId = null;
|
|
301
|
+
if (!("microsubChannelId" in setFields)) insertDefaults.microsubChannelId = null;
|
|
302
|
+
if (!("microsubChannelName" in setFields)) insertDefaults.microsubChannelName = null;
|
|
303
|
+
if (!("skipItemFetch" in setFields)) insertDefaults.skipItemFetch = false;
|
|
304
|
+
if (!("photo" in setFields)) insertDefaults.photo = null;
|
|
305
|
+
if (!("lastFetchAt" in setFields)) insertDefaults.lastFetchAt = null;
|
|
306
|
+
if (!("status" in setFields)) insertDefaults.status = "active";
|
|
284
307
|
|
|
285
308
|
const result = await collection.updateOne(
|
|
286
309
|
filter,
|
|
287
310
|
{
|
|
288
311
|
$set: setFields,
|
|
289
|
-
$setOnInsert:
|
|
290
|
-
description: null,
|
|
291
|
-
tags: [],
|
|
292
|
-
photo: data.photo || null,
|
|
293
|
-
author: null,
|
|
294
|
-
status: data.status || "active",
|
|
295
|
-
lastFetchAt: data.lastFetchAt || null,
|
|
296
|
-
lastError: null,
|
|
297
|
-
itemCount: 0,
|
|
298
|
-
pinned: false,
|
|
299
|
-
hidden: false,
|
|
300
|
-
notes: null,
|
|
301
|
-
source: data.source || null,
|
|
302
|
-
microsubFeedId: data.microsubFeedId || null,
|
|
303
|
-
microsubChannelId: data.microsubChannelId || null,
|
|
304
|
-
microsubChannelName: data.microsubChannelName || null,
|
|
305
|
-
skipItemFetch: data.skipItemFetch || false,
|
|
306
|
-
createdAt: now,
|
|
307
|
-
},
|
|
312
|
+
$setOnInsert: insertDefaults,
|
|
308
313
|
},
|
|
309
314
|
{ upsert: true }
|
|
310
315
|
);
|