Skip to content

Commit

Permalink
...;
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhajdin committed Jun 20, 2023
1 parent 71de9cf commit 078afd5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 108 deletions.
30 changes: 0 additions & 30 deletions app/api/users/new/route.ts

This file was deleted.

44 changes: 0 additions & 44 deletions app/api/users/projects/[id]/route.ts

This file was deleted.

1 change: 1 addition & 0 deletions app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const MyProfile = async ({ searchParams }: any) => {
return (
<>
<ProfilePage
// @ts-ignore
user={result?.user}
// @ts-ignore
searchParams={searchParams}
Expand Down
2 changes: 1 addition & 1 deletion graphql/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const getProjectByIdQuery = (id: string) => {
}`
}

export const getProjectsOfUserQuery = (id: string, last: number = 5, cursor: string | null) => {
export const getProjectsOfUserQuery = (id: string, last?: string, cursor?: string | null) => {
let query = `{
user(by: {id: "${id}"}) {
id
Expand Down
86 changes: 53 additions & 33 deletions lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FormState } from "@/common.types";
import { makeRequest } from "./request";
import { getApiConfig, isBase64DataURL } from "./utils";
import { GraphQLClient } from "graphql-request";
import { createProjectMutation, deleteProjectMutation, updateProjectMutation } from "@/graphql/mutation";
import { getProjectByIdQuery } from "@/graphql/query";
import { createProjectMutation, createUserMutation, deleteProjectMutation, updateProjectMutation, updateUserMutation } from "@/graphql/mutation";
import { getProjectByIdQuery, getProjectsOfUserQuery, getUserQuery } from "@/graphql/query";

type UserProps = {
name: string
Expand Down Expand Up @@ -149,62 +149,82 @@ export const getProjectDetails = async (id: string) => {

export const createUser = async (name: string, email: string, avatarUrl: string) => {
try {
const result = await makeRequest(`api/users/new`, {
method: "POST",
body: {
name,
email,
avatarUrl
}
})
const { apiUrl, apiKey } = await getApiConfig();

return result
const client = new GraphQLClient(apiUrl, {
headers: {
'x-api-key': apiKey,
},
});

const mutation = createUserMutation(name, email, avatarUrl);
const data = await client.request(mutation);

return data
} catch (err) {
console.log("Error", err)
}
}

export const getUserProjects = async (id: string, last?: string, cursor?: string) => {
try {
const result = await makeRequest(`api/users/projects/${id}`, {
method: "POST",
body: {
last,
cursor
}
})
const { apiUrl, apiKey } = await getApiConfig();

const client = new GraphQLClient(apiUrl, {
headers: {
'x-api-key': apiKey,
},
});

const mutation = getProjectsOfUserQuery(id, last, cursor);
const data = await client.request(mutation);

return result
return data
} catch (error) {
console.log("Error", error)
}
}

export const updateUser = async (userId: string, form: UserProps) => {
try {
const result = await makeRequest(`api/users/${userId}`, {
method: "PUT",
body: {
form,
}
})
// const result = await makeRequest(`api/users/${userId}`, {
// method: "PUT",
// body: {
// form,
// }
// })

return result
const { apiUrl, apiKey } = await getApiConfig();

const client = new GraphQLClient(apiUrl, {
headers: {
'x-api-key': apiKey,
},
});

const mutation = updateUserMutation(form, userId);
const data = await client.request(mutation);

return data;
} catch (err) {
console.log("Error", err)
}
}

export const getUser = async (email: string) => {
try {
const result = await makeRequest(`api/users`, {
method: "POST",
body: {
email
}
})
const { apiUrl, apiKey } = await getApiConfig();

const client = new GraphQLClient(apiUrl, {
headers: {
'x-api-key': apiKey,
},
});

const mutation = getUserQuery(email);
const data = await client.request(mutation);

return result
return data;
} catch (err) {
console.log("Error", err)
}
Expand Down

0 comments on commit 078afd5

Please sign in to comment.