seperated backend and frontend

This commit is contained in:
2025-11-14 19:10:12 +03:00
parent 45f6b7a1ef
commit 42983eab65
150 changed files with 26903 additions and 9078 deletions

View File

@@ -0,0 +1,37 @@
import { Person } from "@/models/People";
import { GraphQLError } from "graphql/error";
export const personResolvers = {
Query: {
persons: async () => {
try {
return await Person.find();
} catch (err: any) {
throw new GraphQLError(err.message);
}
},
person: async (_: any, { id }: { id: string }) => {
try {
const person = await Person.findById(id);
if (!person) throw new GraphQLError("Person not found");
return person;
} catch (err: any) {
throw new GraphQLError(err.message);
}
},
},
Mutation: {
createPerson: async (_: any, { input }: any) => {
try {
const person = await Person.create({
...input,
birthDate: new Date(input.birthDate),
});
return person;
} catch (err: any) {
throw new GraphQLError(err.message);
}
},
},
};

View File

@@ -0,0 +1,31 @@
import { connectDB } from '@/lib/mongodb';
import { Users, IUser } from '@/models/Users';
import { Types } from 'mongoose';
export const userResolvers = {
Query: {
users: async () => {
try {
await connectDB();
const users = await Users.find().populate("person").lean();
return users;
} catch (error) {
console.log(error);
return [];
}
},
},
Mutation: {
createUser: async (parent: any, args: { input: IUser }) => {
try {
await connectDB();
const user = new Users({ ...args.input, person: new Types.ObjectId(args.input.person) });
await user.save();
return user;
} catch (error) {
console.log(error);
return null;
}
},
},
};