@merkl/api 0.10.335 → 0.10.337
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.
- package/dist/src/modules/v4/campaign/campaign.repository.d.ts +1 -0
- package/dist/src/modules/v4/campaign/campaign.repository.js +10 -0
- package/dist/src/modules/v4/campaign/campaign.service.d.ts +2 -1
- package/dist/src/modules/v4/campaign/campaign.service.js +9 -4
- package/dist/src/modules/v4/reward/reward.service.js +1 -2
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -45,6 +45,7 @@ export declare abstract class CampaignRepository {
|
|
45
45
|
campaignParameters: import("database/engine/.generated/runtime/library").JsonValue;
|
46
46
|
}[]>;
|
47
47
|
static checkIfExist(campaign: CampaignUnique): Promise<boolean>;
|
48
|
+
static checkIfIdExist(id: string): Promise<boolean>;
|
48
49
|
static findUnique(campaign: CampaignUnique): Promise<{
|
49
50
|
type: import("../../../../database/api/.generated").$Enums.CampaignType;
|
50
51
|
id: string;
|
@@ -199,6 +199,16 @@ export class CampaignRepository {
|
|
199
199
|
},
|
200
200
|
}));
|
201
201
|
}
|
202
|
+
static async checkIfIdExist(id) {
|
203
|
+
return !!(await apiDbClient.campaign.findFirst({
|
204
|
+
select: {
|
205
|
+
id: true,
|
206
|
+
},
|
207
|
+
where: {
|
208
|
+
id,
|
209
|
+
},
|
210
|
+
}));
|
211
|
+
}
|
202
212
|
static async findUnique(campaign) {
|
203
213
|
return await apiDbClient.campaign.findUnique({
|
204
214
|
where: {
|
@@ -20,7 +20,7 @@ export declare abstract class CampaignService {
|
|
20
20
|
creatorAddress: string;
|
21
21
|
} | undefined>;
|
22
22
|
static moveToOpportunity(campaign: Omit<UpdateCampaignModel, "id">, upsert?: boolean): Promise<string>;
|
23
|
-
static createMany(campaigns: Omit<CreateCampaignModel, "id">[]): Promise<{
|
23
|
+
static createMany(campaigns: Omit<CreateCampaignModel, "id">[], upsert?: boolean): Promise<{
|
24
24
|
success: number;
|
25
25
|
fail: number;
|
26
26
|
}>;
|
@@ -83,6 +83,7 @@ export declare abstract class CampaignService {
|
|
83
83
|
*/
|
84
84
|
static countMany(query: GetCampaignQueryModel): Promise<number>;
|
85
85
|
static checkIfExist(campaign: CampaignUnique): Promise<boolean>;
|
86
|
+
static checkIfIdExist(id: string): Promise<boolean>;
|
86
87
|
static findUnique(campaign: CampaignUnique): Promise<{
|
87
88
|
type: import("../../../../database/api/.generated").$Enums.CampaignType;
|
88
89
|
id: string;
|
@@ -63,21 +63,23 @@ export class CampaignService {
|
|
63
63
|
// Move campaign to new opportunity
|
64
64
|
await CampaignRepository.update(id, { id, ...updatedCampaignData });
|
65
65
|
// Update new opportunity with campaign
|
66
|
-
await OpportunityService.recreate(opportunityId);
|
66
|
+
// await OpportunityService.recreate(opportunityId);
|
67
67
|
// Remov (update) campaign from old opportunity
|
68
68
|
await OpportunityService.recreate(existingCampaign.opportunityId);
|
69
69
|
// Return new opportunityId
|
70
70
|
return (await CampaignService.findUniqueOrThrow(campaign)).opportunityId;
|
71
71
|
}
|
72
|
-
static async createMany(campaigns) {
|
72
|
+
static async createMany(campaigns, upsert = false) {
|
73
73
|
const failedToFetchMetadata = [];
|
74
74
|
const campaignsToInsert = [];
|
75
75
|
await Promise.all(campaigns.map(async (campaign) => {
|
76
76
|
const id = CampaignService.hashId({ distributionChain: campaign.chainId, campaignId: campaign.campaignId });
|
77
77
|
campaign.computeChainId = campaign.computeChainId === 0 ? campaign.chainId : campaign.computeChainId;
|
78
78
|
try {
|
79
|
-
await
|
80
|
-
|
79
|
+
if (upsert || !(await CampaignService.checkIfIdExist(id))) {
|
80
|
+
await OpportunityService.createFromCampaign(campaign);
|
81
|
+
campaignsToInsert.push({ id, ...campaign });
|
82
|
+
}
|
81
83
|
}
|
82
84
|
catch (err) {
|
83
85
|
log.error(`Cannot get Opportunity metadata for campaign ${campaign.campaignId} of type ${campaign.type}`, err);
|
@@ -115,6 +117,9 @@ export class CampaignService {
|
|
115
117
|
static async checkIfExist(campaign) {
|
116
118
|
return await CampaignRepository.checkIfExist(campaign);
|
117
119
|
}
|
120
|
+
static async checkIfIdExist(id) {
|
121
|
+
return await CampaignRepository.checkIfIdExist(id);
|
122
|
+
}
|
118
123
|
static async findUnique(campaign) {
|
119
124
|
return await CampaignRepository.findUnique(campaign);
|
120
125
|
}
|
@@ -42,14 +42,13 @@ export class RewardService {
|
|
42
42
|
return rewards.map(reward => {
|
43
43
|
const { Breakdown, RewardToken, id, rewardTokenId, ...rest } = reward;
|
44
44
|
const claimed = Breakdown.reduce((sum, { claimed }) => sum + BigInt(claimed), 0n);
|
45
|
-
const amount = Breakdown.reduce((sum, { amount }) => sum + BigInt(amount), 0n);
|
46
45
|
const pending = Breakdown.reduce((sum, { pending }) => sum + BigInt(pending), 0n);
|
47
46
|
return {
|
48
47
|
...rest,
|
49
48
|
token: RewardToken,
|
50
49
|
breakdowns: Breakdown.map(RewardService.formatBreakdown),
|
51
50
|
claimed,
|
52
|
-
amount,
|
51
|
+
amount: BigInt(rest.amount),
|
53
52
|
pending,
|
54
53
|
};
|
55
54
|
});
|