Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Remove old and closed Omnichannel inquiries #17113

Merged
merged 8 commits into from
Apr 1, 2020
1 change: 1 addition & 0 deletions server/startup/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,5 @@ import './v176';
import './v177';
import './v178';
import './v179';
import './v180';
import './xrun';
20 changes: 20 additions & 0 deletions server/startup/migrations/v180.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Migrations } from '../../../app/migrations/server';
import { LivechatRooms, LivechatInquiry } from '../../../app/models/server';

Migrations.add({
version: 180,
up() {
// Remove Old Omnichannel Inquiries related to rooms already closed
LivechatInquiry.find().forEach((inquiry) => {
const { rid, status } = inquiry;
if (status === 'closed') {
return LivechatInquiry.removeByRoomId(rid);
}

const room = LivechatRooms.findOneById(rid, { closedAt: 1 });
if (!room || room.closedAt) {
LivechatInquiry.removeByRoomId(rid);
}
});
},
});