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];
|
const protectedOfferStatuses = [Status.Confirmed, Status.Complete];
|
||||||
|
|
||||||
// can't delete a listing with an open offer
|
// delete all the offers where we don't want to keep them
|
||||||
// so delete those offers first
|
// for historical reasons
|
||||||
const { count: offersRemoved } = await prisma.offer.deleteMany({
|
const { count: offersRemoved } = await prisma.offer.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
wantId: want.id,
|
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
|
// now we have to filter listingIds with confirmed offers
|
||||||
// and get their listingIds to filter out
|
// and get their listingIds to filter out
|
||||||
@@ -154,23 +154,22 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
|||||||
wantId: want.id,
|
wantId: want.id,
|
||||||
status: {
|
status: {
|
||||||
in: protectedOfferStatuses,
|
in: protectedOfferStatuses,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
listingId: true,
|
listingId: true,
|
||||||
}
|
},
|
||||||
})).map(r => r.listingId);
|
})).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
|
// finally we delete listings that aren't related
|
||||||
// to a historical offer
|
// to a historical offer
|
||||||
const { count } = await prisma.listing.deleteMany({
|
const { count } = await prisma.listing.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
wantId: want.id,
|
id: { in: removalIds },
|
||||||
id: {
|
},
|
||||||
notIn: currentListingIds,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info({ count }, 'second stage open offers removed');
|
log.info({ count }, 'second stage open offers removed');
|
||||||
|
|||||||
Reference in new issue
Block a user