diff --git a/server/services/notifications/controller/notifications/tiFullFlow/tiImport.ts b/server/services/notifications/controller/notifications/tiFullFlow/tiImport.ts index c6f10be..cf440b7 100644 --- a/server/services/notifications/controller/notifications/tiFullFlow/tiImport.ts +++ b/server/services/notifications/controller/notifications/tiFullFlow/tiImport.ts @@ -276,16 +276,28 @@ export const tiImport = async () => { * Update the db so we dont try to pull the next one */ + const currentDate = new Date(Date.now()); const uniqueOrders = Array.from( new Set([ ...notiSet[0].notifiySettings.releases, { releaseNumber: header[0].releaseNumber, - timeStamp: new Date(Date.now()), + timeStamp: currentDate, }, ]) ); + // 45 days ago + const dateLimit = new Date( + currentDate.getTime() - 45 * 24 * 60 * 60 * 1000 + ); + + // filter dates + let filteredOrders = uniqueOrders.filter((item) => { + const time = new Date(item.timeStamp).getTime(); + return time >= dateLimit.getTime(); + }); + const { data, error } = await tryCatch( db .update(notifications) @@ -293,7 +305,7 @@ export const tiImport = async () => { lastRan: sql`NOW()`, notifiySettings: { ...notiSet[0].notifiySettings, - releases: uniqueOrders, + releases: filteredOrders, }, }) .where(eq(notifications.name, "tiIntergration"))