add @lib and @api paths for cleaner imports

This commit is contained in:
Agusti Fernandez Pardo committed 2022-03-25 00:43:35 +01:00
1 parent 737a8897ba
commit f4d889e87b
10 files changed
+232 -38

No files matched your search

+2 -1
View File
@@ -1,8 +1,9 @@
import { PrismaClient, EventType } from "@prisma/client";
import schema from "lib/validations/queryIdTransformParseInt";
import type { NextApiRequest, NextApiResponse } from "next";
import { withValidation } from "next-validations";
import schema from "@lib/validation/queryIdTransformParseInt";
const prisma = new PrismaClient();
type ResponseData = {
+3 -11
View File
@@ -1,20 +1,12 @@
import { PrismaClient, EventType } from "@prisma/client";
import schemaQuery from "lib/validations/queryIdTransformParseInt";
import type { NextApiRequest, NextApiResponse } from "next";
import { withValidation } from "next-validations";
import { z } from "zod";
import schema from "@lib/validation/eventType";
import schemaQuery from "@lib/validation/queryIdTransformParseInt";
const prisma = new PrismaClient();
const schema = z
.object({
title: z.string().min(3),
slug: z.string().min(3),
length: z.number().min(1).max(1440), // max is a full day.
description: z.string().min(3).optional(),
})
.strict(); // Adding strict so that we can disallow passing in extra fields
type ResponseData = {
data?: EventType;
error?: any;
+2 -1
View File
@@ -1,8 +1,9 @@
import { PrismaClient, EventType } from "@prisma/client";
import schema from "lib/validations/queryIdTransformParseInt";
import type { NextApiRequest, NextApiResponse } from "next";
import { withValidation } from "next-validations";
import schema from "@lib/validation/queryIdTransformParseInt";
const prisma = new PrismaClient();
type ResponseData = {
+4 -22
View File
@@ -1,48 +1,30 @@
import { PrismaClient, EventType } from "@prisma/client";
import type { NextApiRequest, NextApiResponse } from "next";
import { withValidation } from "next-validations";
import { z } from "zod";
import schema from "@lib/validation/eventType";
const prisma = new PrismaClient();
const schema = z
.object({
title: z.string().min(3),
slug: z.string().min(3),
length: z.number().min(1).max(1440), // max is a full day.
description: z.string().min(3).optional(),
})
.strict(); // Adding strict so that we can disallow passing in extra fields
// type schema = z.infer<typeof schema>;
const validate = withValidation({
schema,
type: "Zod",
mode: "body",
});
// interface Body {
// title: string;
// slug: string;
// length: number;
// }
type Data = {
data?: EventType;
error?: string;
};
type NextApiRequestWithBody = NextApiRequest & {
// body: Body;
};
async function createEventType(req: NextApiRequestWithBody, res: NextApiResponse<Data>) {
async function createEventType(req: NextApiRequest, res: NextApiResponse<Data>) {
const { body, method } = req;
if (method === "POST") {
const safe = schema.safeParse(body);
if (safe.success && safe.data) {
await prisma.eventType
.create({
data: { title: safe.data.title, slug: safe.data.slug, length: safe.data.length },
data: safe.data,
})
.then((event) => res.status(201).json({ data: event }))
.catch((error) => {