diff --git a/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts b/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts index 79223a837c..206c634652 100644 --- a/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts +++ b/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts @@ -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)); @@ -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, ); @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/indexer/packages/postgres/src/stores/affiliate-info-table.ts b/indexer/packages/postgres/src/stores/affiliate-info-table.ts index 7ef02c7a91..8a27b8c895 100644 --- a/indexer/packages/postgres/src/stores/affiliate-info-table.ts +++ b/indexer/packages/postgres/src/stores/affiliate-info-table.ts @@ -84,7 +84,7 @@ export async function upsert( export async function findById( address: string, options: Options = DEFAULT_POSTGRES_OPTIONS, -): Promise { +): Promise { const baseQuery: QueryBuilder = setupBaseQuery( AffiliateInfoModel, options, @@ -100,7 +100,7 @@ export async function paginatedFindWithAddressFilter( limit: number, sortByAffiliateEarning: boolean, options: Options = DEFAULT_POSTGRES_OPTIONS, -): Promise { +): Promise { let baseQuery: QueryBuilder = setupBaseQuery( AffiliateInfoModel, options, diff --git a/indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts b/indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts index 5a224a7228..76e2433255 100644 --- a/indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts +++ b/indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts @@ -129,7 +129,7 @@ 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, @@ -137,15 +137,6 @@ class AffiliatesController extends Controller { finalsortByAffiliateEarning, ); - // No results found - if (infos === undefined) { - return { - affiliateList: [], - total: 0, - currentOffset: finalOffset, - }; - } - // Get referral codes const addressUsernames: AddressUsername[] = await SubaccountUsernamesTable.findByAddress( @@ -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(', ');