26 lines
821 B
TypeScript
26 lines
821 B
TypeScript
/* global defineEventHandler, readBody */
|
|
|
|
import { RowDataPacket } from "mysql2";
|
|
|
|
import { database } from "../utils/database";
|
|
import { isString } from "../utils/isString";
|
|
|
|
export default defineEventHandler(async (e) => {
|
|
const data = await readBody(e);
|
|
|
|
const nazwa = data.nazwa;
|
|
const adres = data.adres;
|
|
const kontakt = data.kontakt;
|
|
|
|
if (!isString(nazwa)) throw new Error("nazwa is not string");
|
|
if (!isString(adres)) throw new Error("adres is not string");
|
|
if (!isString(kontakt)) throw new Error("kontakt is not string");
|
|
|
|
const [inserted] = await database.query("INSERT INTO `sch_baza_smartfony`.`lombardy` (`nazwa`, `adres`, `kontakt`) VALUES (?, ?, ?);", [nazwa, adres, kontakt]) as RowDataPacket[];
|
|
return {
|
|
id: inserted.insertId as number,
|
|
nazwa,
|
|
adres,
|
|
kontakt,
|
|
};
|
|
});
|