diff --git a/components/publisher/PublisherForm.js b/components/publisher/PublisherForm.js index 130178e..f5e9c8f 100644 --- a/components/publisher/PublisherForm.js +++ b/components/publisher/PublisherForm.js @@ -16,7 +16,7 @@ import ShiftsList from "../publisher/ShiftsList.tsx"; import ConfirmationModal from "../ConfirmationModal"; import { UserRole } from "@prisma/client"; -const { data: session } = useSession() +// const { data: session } = useSession() // import { Tabs, List } from 'tw-elements' diff --git a/pages/api/data/prisma/[...model].ts b/pages/api/data/prisma/[...model].ts index ba5ba99..0e18862 100644 --- a/pages/api/data/prisma/[...model].ts +++ b/pages/api/data/prisma/[...model].ts @@ -18,28 +18,33 @@ const parseQueryParams = (query: any) => { }; -// Helper function to escape and quote strings, handle nulls and other types const serializeValue = (value) => { if (value === null || value === undefined) { return 'NULL'; } if (typeof value === 'string') { - return `'${value.replace(/'/g, "''")}'`; // escape single quotes in SQL string + // Escape single quotes and backslashes for MySQL + return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "''")}'`; } if (typeof value === 'boolean') { - return value ? 'true' : 'false'; + // MySQL uses 1 and 0 for TRUE and FALSE + return value ? '1' : '0'; } if (typeof value === 'number') { return value; } + if (value instanceof Date) { + // Format date objects to MySQL date strings + return `'${value.toISOString().slice(0, 19).replace('T', ' ')}'`; + } if (Array.isArray(value) || typeof value === 'object') { // Convert arrays and objects to JSON strings and escape them - return `'${JSON.stringify(value).replace(/'/g, "''")}'`; + return `'${JSON.stringify(value).replace(/\\/g, "\\\\").replace(/'/g, "''")}'`; } return value; }; -// Function to generate SQL INSERT statements from data +// Function to generate SQL INSERT statements for MySQL from data const generateSQL = (data, tableName) => { return data.map(item => { const columns = Object.keys(item).join(", "); @@ -47,7 +52,6 @@ const generateSQL = (data, tableName) => { return `INSERT INTO ${tableName} (${columns}) VALUES (${values});`; }).join("\n"); }; - export default async function handler(req: NextApiRequest, res: NextApiResponse) { const prisma: PrismaClient = common.getPrismaClient(); const modelArray = (req.query.model || (req.body && req.body.model)) as string[];