@merkl/api 0.10.336 → 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.
@@ -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 OpportunityService.createFromCampaign(campaign);
80
- campaignsToInsert.push({ id, ...campaign });
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
  }