- Scanning the QR code app redicts to page - Option to chose if we want to redirect to page or checkout
21 lines
602 B
JavaScript
21 lines
602 B
JavaScript
import { redirect } from "react-router";
|
|
import invariant from "tiny-invariant";
|
|
import db from "../db.server";
|
|
|
|
import { getDestinationUrl } from "../models/QRCode.server";
|
|
|
|
export const loader = async ({ params }) => {
|
|
invariant(params.id, "Could not find QR code destination");
|
|
|
|
const id = Number(params.id);
|
|
const qrCode = await db.qRCode.findFirst({ where: { id } });
|
|
|
|
invariant(qrCode, "Could not find QR code destination");
|
|
|
|
await db.qRCode.update({
|
|
where: { id },
|
|
data: { scans: { increment: 1 } },
|
|
});
|
|
|
|
return redirect(getDestinationUrl(qrCode));
|
|
}; |