users update create delete tested

This commit is contained in:
2025-11-16 20:35:19 +03:00
parent cf4f632afe
commit f870c2e62e
58 changed files with 4511 additions and 191 deletions

View File

@@ -0,0 +1,35 @@
'use server';
import { NextResponse } from 'next/server';
import { GraphQLClient, gql } from 'graphql-request';
import { userUpdateSchema } from './schema';
const endpoint = "http://localhost:3001/graphql";
export async function POST(request: Request) {
const searchUrl = new URL(request.url);
const uuid = searchUrl.searchParams.get("uuid") || "";
const body = await request.json();
const validatedBody = userUpdateSchema.parse(body);
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
try {
const client = new GraphQLClient(endpoint);
const query = gql`
mutation UpdateUserTest($uuid: String!, $input: UpdateUserInput!) {
updateUser(uuid: $uuid, input: $input) {
tag
email
phone
person
expiryStarts
expiryEnds
}
}
`;
const variables = { uuid: uuid, input: validatedBody };
const data = await client.request(query, variables);
return NextResponse.json({ data: data.updateUser, status: 200 });
} catch (err: any) {
console.error(err);
return NextResponse.json({ error: err.message }, { status: 500 });
}
}

View File

@@ -0,0 +1,28 @@
import { z } from "zod"
export const tokenSchema = z.object({
prefix: z.string().min(1, "Prefix is required").optional(),
token: z.string().min(1, "Token is required").optional(),
})
export const collectionTokensSchema = z.object({
default: z.string().optional(),
tokens: z.array(tokenSchema).optional()
})
export const userUpdateSchema = z.object({
expiryStarts: z.string().optional(),
expiryEnds: z.string().optional(),
isConfirmed: z.boolean().optional(),
isNotificationSend: z.boolean().optional(),
tag: z.string().optional(),
email: z.string().email().optional(),
phone: z.string().min(5).optional(),
person: z.string().optional(),
collectionTokens: collectionTokensSchema,
})
export type UserUpdate = z.infer<typeof userUpdateSchema>