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

8
oldgraphql/index.ts Normal file
View File

@@ -0,0 +1,8 @@
import { mergeTypeDefs, mergeResolvers } from "@graphql-tools/merge";
import { userTypeDefs } from "./schema/userTypeDefs";
import { userResolvers } from "./resolvers/userResolvers";
import { personTypeDefs } from "./schema/personTypeDefs";
import { personResolvers } from "./resolvers/personResolvers";
export const typeDefs = mergeTypeDefs([userTypeDefs, personTypeDefs]);
export const resolvers = mergeResolvers([userResolvers, personResolvers]);

5
oldgraphql/resolvers.ts Normal file
View File

@@ -0,0 +1,5 @@
export const resolvers = {
Query: {
hello: () => "Hello World from Apollo Standalone!",
},
};

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;
}
},
},
};

7
oldgraphql/schema.ts Normal file
View File

@@ -0,0 +1,7 @@
import { gql } from "graphql-tag";
export const typeDefs = gql`
type Query {
hello: String!
}
`;

View File

@@ -0,0 +1,49 @@
import { gql } from "graphql-tag";
export const personTypeDefs = gql`
scalar Date
type Person {
_id: ID!
firstName: String!
surname: String!
middleName: String!
sexCode: String!
personRef: String!
personTag: String!
fatherName: String!
motherName: String!
countryCode: String!
nationalIdentityId: String!
birthPlace: String!
birthDate: Date!
taxNo: String!
birthname: String!
}
input CreatePersonInput {
firstName: String!
surname: String!
middleName: String!
sexCode: String!
personRef: String!
personTag: String!
fatherName: String!
motherName: String!
countryCode: String!
nationalIdentityId: String!
birthPlace: String!
birthDate: Date!
taxNo: String!
birthname: String!
}
type Query {
persons: [Person!]!
person(id: ID!): Person
}
type Mutation {
createPerson(input: CreatePersonInput!): Person!
}
`;

View File

@@ -0,0 +1,75 @@
import { gql } from "graphql-tag";
export const userTypeDefs = gql`
"""Represents a single token entry with a prefix and value"""
type CollectionTokenItem {
prefix: String!
token: String!
}
"""Represents the collection of tokens assigned to a user"""
type CollectionToken {
tokens: [CollectionTokenItem!]!
default: String!
}
type Person {
_id: ID!
firstName: String!
surname: String!
middleName: String!
}
"""User model with references and metadata"""
type User {
_id: ID
uuid: String!
expiresAt: String
resetToken: String
password: String!
history: [String!]
tag: String!
email: String!
phone: String!
collectionTokens: CollectionToken!
person: Person!
type: ID
createdAt: String
updatedAt: String
}
"""Input type for a single token entry"""
input CollectionTokenItemInput {
prefix: String!
token: String!
}
"""Input type for a user's token collection"""
input CollectionTokenInput {
tokens: [CollectionTokenItemInput!]!
default: String!
}
"""Input for creating a new user"""
input CreateUserInput {
password: String!
history: [String!]
tag: String!
email: String!
phone: String!
collectionTokens: CollectionTokenInput!
person: ID!
type: ID
}
"""Queries"""
type Query {
users: [User!]!
user(id: ID!): User
}
"""Mutations"""
type Mutation {
createUser(input: CreateUserInput!): User!
}
`;