Skip to content

Commit 145548c

Browse files
refactor: fromDate and fromEndDate to be number
1 parent 84f2519 commit 145548c

8 files changed

Lines changed: 23 additions & 25 deletions

apps/logic-system/src/interfaces/proposal.interface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export interface ListProposalsOptions {
2828
status?: string | string[];
2929
/** Filter by DAO (passed as header, not query param) */
3030
daoId?: string;
31-
/** Filter proposals after this date (timestamp in seconds as float) */
32-
fromDate?: string;
33-
/** Filter proposals by end timestamp (timestamp in seconds as float) */
34-
fromEndDate?: string;
31+
/** Filter proposals after this date (timestamp in seconds) */
32+
fromDate?: number;
33+
/** Filter proposals by end timestamp (timestamp in seconds) */
34+
fromEndDate?: number;
3535
/** Order direction - asc or desc */
3636
orderDirection?: string;
3737
}

apps/logic-system/src/repositories/proposal.repository.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ export class ProposalRepository implements ProposalDataSource {
2222

2323
// Date filtering
2424
if (options?.fromDate) {
25-
// Convert string timestamp to integer
26-
variables.fromDate = parseInt(options.fromDate, 10);
25+
variables.fromDate = options.fromDate;
2726
}
2827

2928
if (options?.fromEndDate) {
30-
// Convert string timestamp to integer
31-
variables.fromEndDate = parseInt(options.fromEndDate, 10);
29+
variables.fromEndDate = options.fromEndDate;
3230
}
3331

3432
// Pagination

apps/logic-system/src/triggers/new-proposal-trigger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class NewProposalTrigger extends Trigger<ProposalOnChain, ListProposalsOp
2222
if (initialTimestamp) {
2323
this.timestampCursor = parseInt(initialTimestamp, 10);
2424
} else {
25-
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000);
25+
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000); // 24 hours ago
2626
}
2727
}
2828

@@ -36,7 +36,7 @@ export class NewProposalTrigger extends Trigger<ProposalOnChain, ListProposalsOp
3636
if (timestamp) {
3737
this.timestampCursor = parseInt(timestamp, 10);
3838
} else {
39-
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000);
39+
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000); // 24 hours ago
4040
}
4141
}
4242

@@ -66,9 +66,9 @@ export class NewProposalTrigger extends Trigger<ProposalOnChain, ListProposalsOp
6666
if (!options?.status) {
6767
throw new Error('Status is required in filter options');
6868
}
69-
return await this.proposalRepository.listAll({
69+
return await this.proposalRepository.listAll({
7070
status: options.status,
71-
fromDate: this.timestampCursor.toString()
71+
fromDate: this.timestampCursor
7272
});
7373
}
7474
}

apps/logic-system/src/triggers/proposal-finished-trigger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ProposalFinishedTrigger extends Trigger<ProposalOnChain, void> {
2222
if (initialTimestamp) {
2323
this.endTimestampCursor = parseInt(initialTimestamp, 10);
2424
} else {
25-
this.endTimestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000);
25+
this.endTimestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000); // 24 hours ago
2626
}
2727
}
2828

@@ -36,14 +36,14 @@ export class ProposalFinishedTrigger extends Trigger<ProposalOnChain, void> {
3636
if (timestamp) {
3737
this.endTimestampCursor = parseInt(timestamp, 10);
3838
} else {
39-
this.endTimestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000);
39+
this.endTimestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000); // 24 hours ago
4040
}
4141
}
4242

4343
protected async fetchData(): Promise<ProposalOnChain[]> {
4444
return await this.proposalRepository.listAll({
4545
status: this.finishedStatuses, // API accepts array
46-
fromEndDate: this.endTimestampCursor.toString(),
46+
fromEndDate: this.endTimestampCursor,
4747
orderDirection: 'desc', // API orders by endTimestamp when using fromEndDate
4848
limit: 100
4949
});

apps/logic-system/src/triggers/voting-reminder-trigger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class VotingReminderTrigger extends Trigger<ProposalOnChain> {
4747
if (initialTimestamp) {
4848
this.timestampCursor = parseInt(initialTimestamp, 10);
4949
} else {
50-
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000);
50+
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000); // 24 hours ago
5151
}
5252
}
5353

@@ -59,7 +59,7 @@ export class VotingReminderTrigger extends Trigger<ProposalOnChain> {
5959
if (timestamp) {
6060
this.timestampCursor = parseInt(timestamp, 10);
6161
} else {
62-
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000);
62+
this.timestampCursor = Math.floor((Date.now() - 24 * 60 * 60 * 1000) / 1000); // 24 hours ago
6363
}
6464
}
6565

@@ -179,9 +179,9 @@ export class VotingReminderTrigger extends Trigger<ProposalOnChain> {
179179
* Fetches active proposals from the repository
180180
*/
181181
protected async fetchData(): Promise<ProposalOnChain[]> {
182-
return await this.proposalRepository.listAll({
182+
return await this.proposalRepository.listAll({
183183
status: 'ACTIVE',
184-
fromDate: this.timestampCursor.toString()
184+
fromDate: this.timestampCursor
185185
});
186186
}
187187
}

apps/logic-system/tests/new-proposal-trigger.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('NewProposalTrigger', () => {
9393
expect(mockProposalDataSource.listAll).toHaveBeenCalledTimes(1);
9494
expect(mockProposalDataSource.listAll).toHaveBeenCalledWith({
9595
status: 'ACTIVE',
96-
fromDate: initialTimestamp.toString()
96+
fromDate: initialTimestamp
9797
});
9898
});
9999

@@ -107,7 +107,7 @@ describe('NewProposalTrigger', () => {
107107

108108
expect(mockProposalDataSource.listAll).toHaveBeenCalledWith({
109109
status: 'ACTIVE',
110-
fromDate: initialTimestamp.toString()
110+
fromDate: initialTimestamp
111111
});
112112
});
113113

@@ -119,7 +119,7 @@ describe('NewProposalTrigger', () => {
119119
expect(mockProposalDataSource.listAll).toHaveBeenCalledTimes(1);
120120
expect(mockProposalDataSource.listAll).toHaveBeenCalledWith({
121121
status: 'ACTIVE',
122-
fromDate: initialTimestamp.toString()
122+
fromDate: initialTimestamp
123123
});
124124

125125
mockProposalDataSource.listAll.mockClear();

apps/logic-system/tests/proposal-finished-trigger.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('ProposalFinishedTrigger', () => {
3939

4040
expect(mockProposalRepository.listAll).toHaveBeenCalledWith({
4141
status: ['EXECUTED', 'DEFEATED', 'SUCCEEDED', 'EXPIRED', 'CANCELED'],
42-
fromEndDate: initialTimestamp.toString(),
42+
fromEndDate: initialTimestamp,
4343
orderDirection: 'desc',
4444
limit: 100
4545
});
@@ -203,7 +203,7 @@ describe('ProposalFinishedTrigger', () => {
203203
// This ensures A is not fetched again, avoiding duplicates
204204
expect(mockProposalRepository.listAll).toHaveBeenLastCalledWith({
205205
status: ['EXECUTED', 'DEFEATED', 'SUCCEEDED', 'EXPIRED', 'CANCELED'],
206-
fromEndDate: '2001', // A's endTimestamp + 1 converted to string for repository
206+
fromEndDate: 2001, // A's endTimestamp + 1
207207
orderDirection: 'desc',
208208
limit: 100
209209
});

apps/logic-system/tests/voting-reminder-trigger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('VotingReminderTrigger', () => {
200200
// Should include fromDate filter with timestampCursor
201201
expect(mockProposalRepository.listAll).toHaveBeenCalledWith({
202202
status: 'ACTIVE',
203-
fromDate: expect.any(String)
203+
fromDate: expect.any(Number)
204204
});
205205
expect(result).toEqual(proposals);
206206
});

0 commit comments

Comments
 (0)