update cuz presentation

This commit is contained in:
Wroclaw 2023-05-24 09:40:45 +02:00
parent 7a9e451739
commit 4e67cc4e19
29 changed files with 1065 additions and 88 deletions

View file

@ -0,0 +1,12 @@
/* global defineEventHandler, createError */
import { orderExists, getImportedProducts } from "../[id].get";
export default defineEventHandler(async (e) => {
const id = e.context.params?.id as string;
if (!orderExists(id)) throw createError({ statusCode: 404 });
const importedProducts = await getImportedProducts(id);
return importedProducts;
});

View file

@ -0,0 +1,27 @@
/* global defineEventHandler, readBody, createError, setResponseStatus */
import { checkIsImportedProduct } from "../../orders.post";
import { getImportedProducts, orderExists } from "../[id].get";
import Snowflake from "~/utils/snowflake";
import { database } from "~/server/utils/database";
export default defineEventHandler(async (e) => {
const body = await readBody(e);
const idOrder = e.context.params?.id as string;
const idImportedProducts = new Snowflake().toString();
if (!orderExists(idOrder)) throw createError({ statusCode: 404 });
if (!checkIsImportedProduct(body, false)) throw createError({ message: "Invalid body", statusCode: 400 });
await database.query(
["INSERT INTO",
"`imported_products`",
"VALUES",
"(?, ?, ?, ?, ?, ?)",
].join(" "),
[idImportedProducts, idOrder, body.name, body.link, body.price_imported, body.price],
);
setResponseStatus(e, 201);
return getImportedProducts(idOrder);
});

View file

@ -0,0 +1,12 @@
/* global defineEventHandler, createError */
import { orderExists, getWork } from "../[id].get";
export default defineEventHandler(async (e) => {
const id = e.context.params?.id as string;
if (!orderExists(id)) throw createError({ statusCode: 404 });
const work = await getWork(id);
return work;
});

View file

@ -0,0 +1,28 @@
/* global defineEventHandler, readBody, createError, setResponseStatus */
import { checkIsWork } from "../../orders.post";
import { getWork, orderExists } from "../[id].get";
import Snowflake from "~/utils/snowflake";
import { database } from "~/server/utils/database";
export default defineEventHandler(async (e) => {
const body = await readBody(e);
const idOrder = e.context.params?.id as string;
const idWork = new Snowflake().toString();
if (!orderExists(idOrder)) throw createError({ statusCode: 404 });
if (!checkIsWork(body, false)) throw createError({ message: "Invalid body", statusCode: 400 });
await database.query(
["INSERT INTO",
"`work`",
"VALUES",
"(?, ?, ?, ?, ?, ?)",
].join(" "),
[idWork, idOrder, body.offer, body.price, body.notes, body.is_fulfilled],
);
setResponseStatus(e, 201);
return getWork(idWork);
});

View file

@ -0,0 +1,20 @@
/* global defineEventHandler, createError */
import { ResultSetHeader } from "mysql2";
import { orderExists } from "../../[id].get";
import { database } from "~/server/utils/database";
export default defineEventHandler(async (e) => {
const idOrder = e.context.params?.id as string;
const idWork = e.context.params?.idWork as string;
if (!orderExists(idOrder)) throw createError({ statusCode: 404 });
const [response] = await database.query(
"DELETE FROM `work` WHERE `id` = ?",
[idWork],
) as unknown as [ResultSetHeader];
if (response.affectedRows === 0) throw createError({ statusCode: 404 });
return null;
});

View file

@ -0,0 +1,11 @@
/* global defineEventHandler, createError */
import { orderExists, getWork } from "../../[id].get";
export default defineEventHandler((e) => {
const idOrder = e.context.params?.id as string;
const idWork = e.context.params?.idWork as string;
if (!orderExists(idOrder)) throw createError({ statusCode: 404 });
return getWork(idWork);
});