Skip to content

Commit

Permalink
fix: history log fix (bloom-housing#4353) (#772)
Browse files Browse the repository at this point in the history
4310
  • Loading branch information
mcgarrye authored Oct 1, 2024
1 parent 0520f23 commit d850244
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 8 additions & 2 deletions api/src/services/lottery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,13 +959,19 @@ export class LotteryService {
updatedAt: OrderByEnum.ASC,
},
});

let previouslyActive = true;
const filteredActivityLogs = activityLogs.filter((log) => {
const logString = JSON.stringify(log.metadata);
// only return closed listing status updates
if (logString.includes('status')) {
if (logString.includes(ListingsStatusEnum.closed)) {
if (logString.includes(ListingsStatusEnum.closed) && previouslyActive) {
previouslyActive = false;
return true;
} else return false;
} else if (logString.includes(ListingsStatusEnum.active)) {
previouslyActive = true;
}
return false;
}
return true;
});
Expand Down
18 changes: 18 additions & 0 deletions api/test/unit/services/lottery.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,8 @@ describe('Testing lottery service', () => {
},
} as User;

const openedDate = new Date();
openedDate.setDate(openedDate.getDate() - 11);
const closedDate = new Date();
closedDate.setDate(closedDate.getDate() - 10);
const ranDate = new Date();
Expand All @@ -1075,6 +1077,14 @@ describe('Testing lottery service', () => {
beforeEach(() => {
canOrThrowMock.mockResolvedValue(true);
prisma.activityLog.findMany = jest.fn().mockResolvedValue([
{
metadata: { status: 'active' },
updatedAt: openedDate,
userAccounts: {
firstName: 'Abc',
lastName: 'Def',
},
},
{
metadata: { status: 'closed' },
updatedAt: closedDate,
Expand All @@ -1083,6 +1093,14 @@ describe('Testing lottery service', () => {
lastName: 'Def',
},
},
{
metadata: { status: 'closed' },
updatedAt: ranDate,
userAccounts: {
firstName: 'Abc',
lastName: 'Def',
},
},
{
metadata: { lotteryStatus: 'ran' },
updatedAt: ranDate,
Expand Down

0 comments on commit d850244

Please sign in to comment.