open offers fix
This commit is contained in:
1 parent
43173a833d
commit
0cec6414ae
1 file changed
+10
-11
+10
-11
@@ -131,8 +131,8 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
|
||||
const protectedOfferStatuses = [Status.Confirmed, Status.Complete];
|
||||
|
||||
// can't delete a listing with an open offer
|
||||
// so delete those offers first
|
||||
// delete all the offers where we don't want to keep them
|
||||
// for historical reasons
|
||||
const { count: offersRemoved } = await prisma.offer.deleteMany({
|
||||
where: {
|
||||
wantId: want.id,
|
||||
@@ -145,7 +145,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
}
|
||||
});
|
||||
|
||||
if (offersRemoved > 0) log.info({ offersRemoved }, 'open offers removed');
|
||||
if (offersRemoved > 0) log.info({ offersRemoved }, 'pending offers removed');
|
||||
|
||||
// now we have to filter listingIds with confirmed offers
|
||||
// and get their listingIds to filter out
|
||||
@@ -154,23 +154,22 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
wantId: want.id,
|
||||
status: {
|
||||
in: protectedOfferStatuses,
|
||||
}
|
||||
},
|
||||
},
|
||||
select: {
|
||||
listingId: true,
|
||||
}
|
||||
},
|
||||
})).map(r => r.listingId);
|
||||
const removalIds = _.without(currentListingIds, ...confirmedListingIds);
|
||||
const removalIds = currentListingIds.filter(id => confirmedListingIds.includes(id));
|
||||
|
||||
if (removalIds.length) log.info({ removalIds });
|
||||
|
||||
// finally we delete listings that aren't related
|
||||
// to a historical offer
|
||||
const { count } = await prisma.listing.deleteMany({
|
||||
where: {
|
||||
wantId: want.id,
|
||||
id: {
|
||||
notIn: currentListingIds,
|
||||
}
|
||||
}
|
||||
id: { in: removalIds },
|
||||
},
|
||||
});
|
||||
|
||||
log.info({ count }, 'second stage open offers removed');
|
||||
|
||||
Reference in new issue
Block a user