Skip to content

Commit

Permalink
feat: add imageOptions for lemonade
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrliu committed Nov 23, 2024
1 parent cb1274b commit a47bd7b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BadgeConfig,
CONTACT_EVENT_NAME,
GenericIssuanceSendPipelineEmailResponseValue,
ImageOptions,
LemonadePipelineDefinition,
LemonadePipelineEventConfig,
LemonadePipelineTicketTypeConfig,
Expand Down Expand Up @@ -586,6 +587,37 @@ export class LemonadePipeline implements BasePipeline {
});
}

private imageOptionsToImageUrl(
imageOptions: ImageOptions | undefined,
isCheckedIn: boolean
): string | undefined {
if (!imageOptions) return undefined;
if (imageOptions.requireCheckedIn && !isCheckedIn) return undefined;
return imageOptions.imageUrl;
}

private atomToQrCodeOverrideImageUrl(
ticketAtom: LemonadeAtom
): string | undefined {
return this.getEventById(ticketAtom.lemonadeEventId).imageOptions
?.qrCodeOverrideImageUrl;
}

private atomToImageUrl(ticketAtom: LemonadeAtom): string | undefined {
return this.imageOptionsToImageUrl(
this.getEventById(ticketAtom.lemonadeEventId).imageOptions,
ticketAtom.checkinDate !== undefined
);
}

private atomToEventLocation(atom: LemonadeAtom): string | undefined {
return this.getEventById(atom.lemonadeEventId).imageOptions?.eventLocation;
}

private atomToEventStartDate(atom: LemonadeAtom): string | undefined {
return this.getEventById(atom.lemonadeEventId).imageOptions?.eventStartDate;
}

private async manualTicketToTicketData(
client: PoolClient,
manualTicket: ManualTicket,
Expand All @@ -608,6 +640,10 @@ export class LemonadePipeline implements BasePipeline {
attendeeName: manualTicket.attendeeName,
attendeeSemaphoreId: sempahoreId,
isConsumed: checkIn ? true : false,
imageUrl: this.imageOptionsToImageUrl(event.imageOptions, !!checkIn),
qrCodeOverrideImageUrl: event.imageOptions?.qrCodeOverrideImageUrl,
eventStartDate: event.imageOptions?.eventStartDate,
eventLocation: event.imageOptions?.eventLocation,
isRevoked: false,
timestampSigned: Date.now(),
timestampConsumed: checkIn ? checkIn.timestamp.getTime() : 0,
Expand Down Expand Up @@ -1160,6 +1196,10 @@ export class LemonadePipeline implements BasePipeline {
timestampConsumed:
atom.checkinDate instanceof Date ? atom.checkinDate.getTime() : 0,
timestampSigned: Date.now(),
imageUrl: this.atomToImageUrl(atom),
qrCodeOverrideImageUrl: this.atomToQrCodeOverrideImageUrl(atom),
eventStartDate: this.atomToEventStartDate(atom),
eventLocation: this.atomToEventLocation(atom),
attendeeSemaphoreId: semaphoreId,
isConsumed: atom.checkinDate instanceof Date,
isRevoked: false, // Not clear what concept this maps to in Lemonade
Expand Down
22 changes: 13 additions & 9 deletions packages/lib/passport-interface/src/genericIssuanceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ const SemaphoreGroupListSchema = z
{ message: "Semaphore group names must be unique" }
);

const ImageOptionsSchema = z.object({
imageUrl: z.string(),
requireCheckedIn: z.boolean(),
qrCodeOverrideImageUrl: z.string().optional(),
eventStartDate: z.string().optional(),
eventLocation: z.string().optional()
});

/**
* Generic Issuance-specific ticket type configuration - roughly corresponds to a
* 'Product' in Pretix-land.
Expand All @@ -206,7 +214,11 @@ const LemonadePipelineEventConfigSchema = z.object({
/**
* Roughly translates to Products in {@link EdDSATicketPCD}.
*/
ticketTypes: z.array(LemonadePipelineTicketTypeConfigSchema)
ticketTypes: z.array(LemonadePipelineTicketTypeConfigSchema),
/**
* Options to configure displaying an image instead of the QR code
*/
imageOptions: ImageOptionsSchema.optional()
});

/**
Expand Down Expand Up @@ -275,14 +287,6 @@ const FeedIssuanceOptionsSchema = z.object({

export type FeedIssuanceOptions = z.infer<typeof FeedIssuanceOptionsSchema>;

const ImageOptionsSchema = z.object({
imageUrl: z.string(),
requireCheckedIn: z.boolean(),
qrCodeOverrideImageUrl: z.string().optional(),
eventStartDate: z.string().optional(),
eventLocation: z.string().optional()
});

export type ImageOptions = z.infer<typeof ImageOptionsSchema>;

const LemonadePipelineOptionsSchema = BasePipelineOptionsSchema.extend({
Expand Down

0 comments on commit a47bd7b

Please sign in to comment.