bulltrackers-module 1.0.397 → 1.0.398
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.
|
@@ -869,7 +869,7 @@ async function autoGenerateWatchlist(req, res, dependencies, config) {
|
|
|
869
869
|
watchlistItems.push({
|
|
870
870
|
cid: Number(cidStr),
|
|
871
871
|
username: username,
|
|
872
|
-
addedAt: FieldValue.serverTimestamp()
|
|
872
|
+
addedAt: new Date(), // Use regular Date (FieldValue.serverTimestamp() not allowed in arrays)
|
|
873
873
|
alertConfig: {
|
|
874
874
|
newPositions: true,
|
|
875
875
|
volatilityChanges: true,
|
|
@@ -917,6 +917,31 @@ async function autoGenerateWatchlist(req, res, dependencies, config) {
|
|
|
917
917
|
const existingData = existingDoc.data();
|
|
918
918
|
const existingItems = existingData.items || [];
|
|
919
919
|
|
|
920
|
+
// Create a map of existing items by CID to preserve their addedAt timestamps
|
|
921
|
+
const existingItemsMap = new Map();
|
|
922
|
+
for (const item of existingItems) {
|
|
923
|
+
if (item.cid) {
|
|
924
|
+
existingItemsMap.set(item.cid, item);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// Merge watchlist items, preserving addedAt for existing items
|
|
929
|
+
const syncedItems = watchlistItems.map(newItem => {
|
|
930
|
+
const existingItem = existingItemsMap.get(newItem.cid);
|
|
931
|
+
if (existingItem && existingItem.addedAt) {
|
|
932
|
+
// Preserve existing addedAt timestamp
|
|
933
|
+
return {
|
|
934
|
+
...newItem,
|
|
935
|
+
addedAt: existingItem.addedAt
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
// New item, use current date
|
|
939
|
+
return {
|
|
940
|
+
...newItem,
|
|
941
|
+
addedAt: new Date()
|
|
942
|
+
};
|
|
943
|
+
});
|
|
944
|
+
|
|
920
945
|
// Calculate what changed
|
|
921
946
|
const existingCIDs = new Set(existingItems.map(item => item.cid));
|
|
922
947
|
const newCIDs = new Set(watchlistItems.map(item => item.cid));
|
|
@@ -926,7 +951,7 @@ async function autoGenerateWatchlist(req, res, dependencies, config) {
|
|
|
926
951
|
|
|
927
952
|
// Replace entire items array to sync with current copied PIs
|
|
928
953
|
await existingDoc.ref.update({
|
|
929
|
-
items:
|
|
954
|
+
items: syncedItems, // Full replacement to match current state, preserving timestamps
|
|
930
955
|
updatedAt: FieldValue.serverTimestamp()
|
|
931
956
|
});
|
|
932
957
|
|