@merkl/api 0.10.401 → 0.10.402
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Campaign, Reward, RewardBreakdown } from "../../../../database/api/.generated/drizzle/schema.ts";
|
2
2
|
import { apiDbClient } from "../../../utils/prisma";
|
3
|
-
import { and, eq, inArray, sql } from "drizzle-orm";
|
3
|
+
import { and, eq, exists, inArray, sql } from "drizzle-orm";
|
4
4
|
import { CampaignService } from "../campaign";
|
5
5
|
import { TokenService } from "../token";
|
6
6
|
import { UserService } from "../user";
|
@@ -330,13 +330,23 @@ export class RewardRepository {
|
|
330
330
|
const { page: _page, items: _items, campaignIds } = query;
|
331
331
|
const page = _page || 0;
|
332
332
|
const items = _items || 50;
|
333
|
-
const ids = typeof campaignIds === "string"
|
333
|
+
const ids = typeof campaignIds === "string"
|
334
|
+
? campaignIds === "[]"
|
335
|
+
? []
|
336
|
+
: [campaignIds]
|
337
|
+
: campaignIds?.some(c => c === "[]")
|
338
|
+
? []
|
339
|
+
: (campaignIds ?? []);
|
334
340
|
const result = await apiDbClient.$drizzle
|
335
341
|
.select({ amount: Reward.amount, claimed: Reward.claimed, pending: Reward.pending, recipient: Reward.recipient })
|
336
342
|
.from(Reward)
|
337
|
-
.
|
338
|
-
|
339
|
-
|
343
|
+
.where(and(eq(Reward.root, root), eq(Reward.rewardTokenId, id), ids.length > 0
|
344
|
+
? exists(apiDbClient.$drizzle
|
345
|
+
.select()
|
346
|
+
.from(RewardBreakdown)
|
347
|
+
.innerJoin(Campaign, eq(RewardBreakdown.campaignId, Campaign.id))
|
348
|
+
.where(and(eq(RewardBreakdown.rewardId, Reward.id), inArray(Campaign.campaignId, ids))))
|
349
|
+
: sql `TRUE`))
|
340
350
|
.orderBy(sql `(${Reward.amount}::numeric + ${Reward.pending}::numeric) desc`)
|
341
351
|
.limit(items)
|
342
352
|
.offset(items * page);
|