Skip to content

Commit

Permalink
pr revision 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Sep 17, 2024
1 parent 3ef1eed commit b344fa0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Affiliate info store', () => {

it('Can upsert affiliate info multiple times', async () => {
await AffiliateInfoTable.upsert(defaultAffiliateInfo);
let info: AffiliateInfoFromDatabase | undefined = await AffiliateInfoTable.findById(
let info: AffiliateInfoFromDatabase = await AffiliateInfoTable.findById(
defaultAffiliateInfo.address,
);
expect(info).toEqual(expect.objectContaining(defaultAffiliateInfo));
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('Affiliate info store', () => {
it('Successfully finds an affiliate info', async () => {
await AffiliateInfoTable.create(defaultAffiliateInfo);

const info: AffiliateInfoFromDatabase | undefined = await AffiliateInfoTable.findById(
const info: AffiliateInfoFromDatabase = await AffiliateInfoTable.findById(
defaultAffiliateInfo.address,
);

Expand All @@ -80,7 +80,7 @@ describe('Affiliate info store', () => {
});

it('Successfully filters by address', async () => {
const infos: AffiliateInfoFromDatabase[] | undefined = await AffiliateInfoTable
const infos: AffiliateInfoFromDatabase[] = await AffiliateInfoTable
.paginatedFindWithAddressFilter(
['address_0'],
0,
Expand All @@ -97,7 +97,7 @@ describe('Affiliate info store', () => {
});

it('Successfully sorts by affiliate earning', async () => {
const infos: AffiliateInfoFromDatabase[] | undefined = await AffiliateInfoTable
const infos: AffiliateInfoFromDatabase[] = await AffiliateInfoTable
.paginatedFindWithAddressFilter(
[],
0,
Expand All @@ -119,7 +119,7 @@ describe('Affiliate info store', () => {
});

it('Successfully uses offset and limit', async () => {
const infos: AffiliateInfoFromDatabase[] | undefined = await AffiliateInfoTable
const infos: AffiliateInfoFromDatabase[] = await AffiliateInfoTable
.paginatedFindWithAddressFilter(
[],
5,
Expand All @@ -141,7 +141,7 @@ describe('Affiliate info store', () => {
});

it('Successfully filters, sorts, offsets, and limits', async () => {
const infos: AffiliateInfoFromDatabase[] | undefined = await AffiliateInfoTable
const infos: AffiliateInfoFromDatabase[] = await AffiliateInfoTable
.paginatedFindWithAddressFilter(
[],
3,
Expand All @@ -163,7 +163,7 @@ describe('Affiliate info store', () => {
});

it('Returns empty array if no results', async () => {
const infos: AffiliateInfoFromDatabase[] | undefined = await AffiliateInfoTable
const infos: AffiliateInfoFromDatabase[] = await AffiliateInfoTable
.paginatedFindWithAddressFilter(
['address_11'],
0,
Expand Down
4 changes: 2 additions & 2 deletions indexer/packages/postgres/src/stores/affiliate-info-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function upsert(
export async function findById(
address: string,
options: Options = DEFAULT_POSTGRES_OPTIONS,
): Promise<AffiliateInfoFromDatabase | undefined> {
): Promise<AffiliateInfoFromDatabase> {
const baseQuery: QueryBuilder<AffiliateInfoModel> = setupBaseQuery<AffiliateInfoModel>(
AffiliateInfoModel,
options,
Expand All @@ -100,7 +100,7 @@ export async function paginatedFindWithAddressFilter(
limit: number,
sortByAffiliateEarning: boolean,
options: Options = DEFAULT_POSTGRES_OPTIONS,
): Promise<AffiliateInfoFromDatabase[] | undefined> {
): Promise<AffiliateInfoFromDatabase[]> {
let baseQuery: QueryBuilder<AffiliateInfoModel> = setupBaseQuery<AffiliateInfoModel>(
AffiliateInfoModel,
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,14 @@ class AffiliatesController extends Controller {
const finalLimit: number = limit ?? 1000;
const finalsortByAffiliateEarning: boolean = sortByAffiliateEarning ?? false;

const infos: AffiliateInfoFromDatabase[] | undefined = await AffiliateInfoTable
const infos: AffiliateInfoFromDatabase[] = await AffiliateInfoTable
.paginatedFindWithAddressFilter(
finalAddressFilter,
finalOffset,
finalLimit,
finalsortByAffiliateEarning,
);

// No results found
if (infos === undefined) {
return {
affiliateList: [],
total: 0,
currentOffset: finalOffset,
};
}

// Get referral codes
const addressUsernames:
AddressUsername[] = await SubaccountUsernamesTable.findByAddress(
Expand All @@ -156,7 +147,7 @@ class AffiliatesController extends Controller {
addressUsernameMap[addressUsername.address] = addressUsername.username;
});
if (addressUsernames.length !== infos.length) {
const addressesNotFound = infos
const addressesNotFound: string = infos
.map((info) => info.address)
.filter((address) => !(address in addressUsernameMap))
.join(', ');
Expand Down

0 comments on commit b344fa0

Please sign in to comment.