File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,39 @@ export async function loadSalesFromEActivites(
109
109
if ( typeof product . eActivitiesId !== "number" ) {
110
110
logger . warn ( `Product ${ product . id } has an invalid eActivities ID, so skipping!` ) ;
111
111
}
112
-
112
+
113
113
// Filter out sales
114
114
const sales = allSales . filter ( ( sale ) => sale . ProductID === product . eActivitiesId ) ;
115
+ if ( sales . length === 0 ) {
116
+ logger . warn ( `No sales found for product ${ product . name } id ${ product . id } - skipping` ) ;
117
+ continue ;
118
+ }
119
+
120
+ // If length of sales === number of sales for product, skip
121
+ const existingSales = await prisma . variant . findMany ( {
122
+ select : {
123
+ _count : {
124
+ select : {
125
+ OrderItem : true ,
126
+ } ,
127
+ } ,
128
+ } ,
129
+ where : {
130
+ rootItemId : product . id ,
131
+ } ,
132
+ } ) ;
133
+
134
+ const existingSalesCount = existingSales . reduce (
135
+ ( acc , curr ) => acc + curr . _count . OrderItem ,
136
+ 0 ,
137
+ ) ;
138
+
139
+ if ( existingSalesCount === sales . length ) {
140
+ logger . warn (
141
+ `All sales for product ${ product . name } id ${ product . id } already imported, skipping. (${ existingSalesCount } sales already imported)` ,
142
+ ) ;
143
+ continue ;
144
+ }
115
145
116
146
// Pull product data as well
117
147
let productData : Awaited < ReturnType < typeof eActivities . getProductById > > ;
You can’t perform that action at this time.
0 commit comments