Cards
singularName: cardpluralName: cards
Schema
| Name | Type | Details |
|---|---|---|
| card_type | enumeration | one of [member, guest] |
| member | relation | manyToOne → Members |
| guest_number | integer | |
| is_active | boolean | |
| drink_redemptions | relation | oneToMany → Drink Redemption |
| card_uid | string |
Lifecycles
beforeCreate (async)
Assigns a random UUID to card_uid and validates the card before creation. For member cards: checks the member is active and has no existing active card. For guest cards: auto-assigns the next guest_number if not set.
Parameters:
event:
afterCreate
Fires only for member cards when CARD_EMAILS_ENABLED=true. Generates the member card image and Google Wallet URL, then sends the card email via email-designer-5. Runs in setImmediate so the HTTP response is not blocked.
Parameters:
event:
Services
bulkCreateGuestCards (async)
Creates multiple guest cards with a continuous guest_number sequence, starting from the current maximum. The card_uid for each card is generated automatically by the card beforeCreate lifecycle hook.
Parameters:
count: - Number of guest cards to create.
Returns:
- of created cards ordered by guest_number.
deactivateCard (async)
Deactivates a card by setting is_active to false. Returns null if no card with the given documentId exists.
Parameters:
documentId: - Strapi documentId of the card to deactivate.
Returns:
- card, or null if not found.
buildBackgroundSVG
Builds an SVG buffer containing the card's coloured bands and white text. Bitmap images (logo, photo, QR) are composited on top by sharp separately. Coordinate mapping (pdf-lib y-up → screen y-down): screen_y = (CARD_H − pdf_y) × SCALE Key anchors at SCALE=3 (px): Header band : y=0..129 Body band : y=129..459 Photo : left=30 top=159 size=270 QR : left=501 top=231 size=198 Text x : 321 Name base : 159 + namePx × 0.72 CardNum base: 393 Date base : 429
generateQR (async)
Generates a QR code PNG buffer for value at sizePx resolution, compositing the favicon in the centre if available.
Parameters:
value: - Value to encode.sizePx: - Output size in pixels.
Returns:
generateMemberCardImage (async)
Generate a PNG image of a member card identical in layout to the PDF version.
Parameters:
card: - card record from strapi.db.query, with member populated (member must include: alias, member_id, member_type, joined_date, image.url)
Returns:
- buffer (729 × 459 px at SCALE=3)
fitFontSize
Returns the largest font size (stepping down by 0.5pt) at which text fits within maxW in a single line. Never goes below minSize.
Parameters:
text: - Text to measure.font: - pdf-lib font object withwidthOfTextAtSize.maxW: - Maximum allowed width in points.maxSize: - Starting (maximum) font size to try.minSize: - Floor font size; returned if nothing else fits.
Returns:
- fitting font size.
generateQRBuffer (async)
Generate a QR code PNG buffer for the given value. If sharp and favicon.png are available, composites the favicon in the centre.
Parameters:
value: - Value to encode (card_uid).
Returns:
drawCard
Draw a single card at position (cx, cy) — bottom-left corner in pdf-lib coords.
Parameters:
page: - pdf-lib PDFPagecx: - x coordinate of card bottom-leftcy: - y coordinate of card bottom-leftcardData: -font: - pdf-lib Helvetica fontboldFont: - pdf-lib HelveticaBold fontheaderImg: - pdf-lib embedded header image, or nullmemberPhoto: - pdf-lib embedded photo image, or nullqrImg: - pdf-lib embedded QR code image, or null
renderCardsToDoc (async)
Render an array of card rows into the PDF document. Each row is printed twice side-by-side (two copies per A4 row) with cut guides.
Parameters:
pdfDoc: - pdf-lib PDFDocumentrows: - [{ cardData, photo, qrImg }]font: - HelveticaboldFont: - HelveticaBoldheaderImg: - Embedded header image or null
generateCardsPDF (async)
Generate a DIN-A4 PDF of member and/or guest cards. Each card is printed twice side-by-side per A4 row with dashed cut guides.
Parameters:
memberIds: - member_id values to include. Empty = no member filter.guestNumbers: - guest_number values to include. Empty = no guest filter. Omit both to print all active cards.
Returns:
- as a Node.js Buffer.
getLogoUrl (async)
Lazily generates a 660×660 PNG wallet logo by compositing the white club SVG onto a #880E4F background. Cached to disk after first generation. Returns the public URL, or null if sharp / the SVG is unavailable.
getHeroImageUrl (async)
Lazily generates a 1032×336 hero banner (wide format required by Google Wallet) with the white club SVG centred on a #880E4F background.
generateSaveToWalletUrl (async)
Generates a "Save to Google Wallet" URL for the given member card. Returns null gracefully when credentials are not configured. Required env vars: GOOGLE_WALLET_ISSUER_ID – numeric issuer ID from Google Pay Console GOOGLE_WALLET_CLIENT_EMAIL – service account e-mail address GOOGLE_WALLET_PRIVATE_KEY – service account private key (PEM); use \n for newlines when set in a .env file Optional: GOOGLE_WALLET_CLASS_ID – pass class suffix (default: klh_member_card) STRAPI_PUBLIC_URL – public base URL of this server, e.g. https://klharriettes.org — enables logo + member photo on the pass
Parameters:
card: - card record with member populated (including image.url)
Returns:
