@@ -7,6 +7,7 @@ import type { Card } from '@devcard/shared';
77import type { FastifyInstance , FastifyRequest , FastifyReply } from 'fastify' ;
88import { CardVisibility } from '@prisma/client' ;
99import { hashIp } from '../utils/refreshToken' ;
10+ import { id } from 'zod/v4/locales' ;
1011
1112export interface CreateCardBody {
1213 title : string ;
@@ -254,4 +255,37 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
254255 handleDbError ( error , request , reply )
255256 }
256257 } )
258+
259+ app . get ( '/:id/qr' , async ( request : FastifyRequest < { Params : { id : string } } > , reply :FastifyReply ) => {
260+ const cardId = request . params . id
261+ const userId = request . user . id
262+
263+ try {
264+ const qrImage = await cardService . genrateQr ( app , userId , cardId )
265+ return reply . type ( 'image/png' ) . send ( qrImage )
266+ } catch ( error :any ) {
267+ if ( error ?. code === 'CARD_NOT_FOUND' ) {
268+ return reply . status ( 404 ) . send ( {
269+ error : error . message ,
270+ } ) ;
271+ }
272+ if ( error ?. code === 'CARD_PRIVATE' ) {
273+ return reply . status ( 403 ) . send ( {
274+ error : error . message ,
275+ } ) ;
276+ }
277+ if ( error ?. code === 'QR_ENABLED' ) {
278+ return reply . status ( 404 ) . send ( {
279+ error : error . message ,
280+ } ) ;
281+ }
282+ if ( error ?. code === 'QR_IMAGE' ) {
283+ return reply . status ( 403 ) . send ( {
284+ error : error . message ,
285+ } ) ;
286+ }
287+ app . log . error ( error )
288+ handleDbError ( error , request , reply )
289+ }
290+ } )
257291}
0 commit comments