Pixel/links development. New validations folder. More refactoring.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
import { canUpdateWebsite, canDeleteWebsite, canViewWebsite } from '@/lib/auth';
|
||||
import { canUpdateLink, canDeleteLink, canViewLink } from '@/validations';
|
||||
import { SHARE_ID_REGEX } from '@/lib/constants';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { ok, json, unauthorized, serverError } from '@/lib/response';
|
||||
import { deleteWebsite, getWebsite, updateWebsite } from '@/queries';
|
||||
import { deleteLink, getLink, updateLink } from '@/queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
@@ -17,11 +17,11 @@ export async function GET(
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
if (!(await canViewLink(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const website = await getWebsite(websiteId);
|
||||
const website = await getLink(websiteId);
|
||||
|
||||
return json(website);
|
||||
}
|
||||
@@ -45,12 +45,12 @@ export async function POST(
|
||||
const { websiteId } = await params;
|
||||
const { name, domain, shareId } = body;
|
||||
|
||||
if (!(await canUpdateWebsite(auth, websiteId))) {
|
||||
if (!(await canUpdateLink(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
try {
|
||||
const website = await updateWebsite(websiteId, { name, domain, shareId });
|
||||
const website = await updateLink(websiteId, { name, domain, shareId });
|
||||
|
||||
return Response.json(website);
|
||||
} catch (e: any) {
|
||||
@@ -74,11 +74,11 @@ export async function DELETE(
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
if (!(await canDeleteWebsite(auth, websiteId))) {
|
||||
if (!(await canDeleteLink(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
await deleteWebsite(websiteId);
|
||||
await deleteLink(websiteId);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { canCreateTeamWebsite, canCreateWebsite } from '@/lib/auth';
|
||||
import { canCreateTeamWebsite, canCreateWebsite } from '@/validations';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
@@ -20,9 +20,9 @@ export async function GET(request: Request) {
|
||||
|
||||
const filters = await getQueryFilters(query);
|
||||
|
||||
const result = await getUserLinks(auth.user.id, filters);
|
||||
const links = await getUserLinks(auth.user.id, filters);
|
||||
|
||||
return json(result);
|
||||
return json(links);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
|
||||
Reference in New Issue
Block a user