-
Notifications
You must be signed in to change notification settings - Fork 115
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
[OTE-762] Affiliates comlink affiliate info #2269
Changes from 11 commits
368742b
bc16518
0a16cad
ac62c32
f321a91
0784cfa
21481ec
3fa0437
5e7e139
93d3f83
dd9d66c
6ca6830
3ef1eed
b344fa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as Knex from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
return knex.schema.alterTable('affiliate_info', (table) => { | ||
// null indicates variable precision whereas not specifying will result in 8,2 precision,scale | ||
table.decimal('affiliateEarnings', null).alter(); | ||
table.decimal('totalReferredFees', null).alter(); | ||
table.decimal('referredNetProtocolEarnings', null).alter(); | ||
|
||
table.decimal('referredTotalVolume', null).notNullable(); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
return knex.schema.alterTable('affiliate_info', (table) => { | ||
table.decimal('affiliateEarnings').alter(); | ||
table.decimal('totalReferredFees').alter(); | ||
table.decimal('referredNetProtocolEarnings').alter(); | ||
|
||
table.dropColumn('referredTotalVolume'); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ export async function upsert( | |
// should only ever be one AffiliateInfo | ||
return AffiliateInfos[0]; | ||
} | ||
|
||
export async function findById( | ||
address: string, | ||
options: Options = DEFAULT_POSTGRES_OPTIONS, | ||
|
@@ -92,3 +93,32 @@ export async function findById( | |
.findById(address) | ||
.returning('*'); | ||
} | ||
|
||
export async function paginatedFindWithAddressFilter( | ||
jerryfan01234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
addressFilter: string[], | ||
offset: number, | ||
limit: number, | ||
sortByAffiliateEarning: boolean, | ||
options: Options = DEFAULT_POSTGRES_OPTIONS, | ||
): Promise<AffiliateInfoFromDatabase[] | undefined> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like it returns empty array, when will this ever return undefined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it cant be undefined, i will remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix this for other affiliate endpoints in upcoming PR |
||
let baseQuery: QueryBuilder<AffiliateInfoModel> = setupBaseQuery<AffiliateInfoModel>( | ||
AffiliateInfoModel, | ||
options, | ||
); | ||
|
||
// Apply address filter if provided | ||
if (addressFilter.length > 0) { | ||
baseQuery = baseQuery.whereIn(AffiliateInfoColumns.address, addressFilter); | ||
} | ||
|
||
// Sorting by affiliate earnings or default sorting by address | ||
if (sortByAffiliateEarning) { | ||
baseQuery = baseQuery.orderBy(AffiliateInfoColumns.affiliateEarnings, Ordering.DESC); | ||
} | ||
|
||
// Apply pagination using offset and limit | ||
baseQuery = baseQuery.offset(offset).limit(limit); | ||
|
||
// Returning all fields | ||
return baseQuery.returning('*'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does variable precision mean? Thinking about this more, we probably want scale of 6 for all fees, thats the smallest unit of USDC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For variable precision it will not append any 0s after the decimal. Eg. 2 stays 2 and 2.123 stays 2.123. Variable precision allows for up to the maximum postgres limit.
If you set the precision to 6. It will pad 0s so 2 -> 2.000000.
We can do it either way, the main change will be that our unit tests use the string conversion so we have to change those values. I prefer to stick with variable, as that is convention other columns in our tables use.