Skip to content

Commit

Permalink
feat : add img url in post functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedrinvits committed Oct 15, 2024
1 parent caa1d54 commit ac9f64a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 8 additions & 7 deletions data/createPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getUserByEmail } from "./user";
type Post = {
title: string
description: string
imgURL: string
}
export const createpost = async (

Expand All @@ -22,16 +23,16 @@ export const createpost = async (
if (!user) {
throw new Error('Usuário não encontrado.');
}

const createPost = await db.post.create({
await db.post.create({
data: {
authorId: user.id,
title: post.title,
description: post.description
title : post.title,
description : post.description,
imageUrl : post.imgURL
},
});

// cria o post e depois manda os posts atualizados
// console.log(res);
const updatedPosts = await db.post.findMany({
include : {
author : {
Expand All @@ -43,7 +44,7 @@ export const createpost = async (
}
})

return { updatedPosts, success: "Informações atualizadas com sucesso!", error: null };
return { updatedPosts, success: "Post criado com sucesso!", error: null };
} catch (error) {
console.error('Erro ao atualizar as informações:', error);
return { success: null, error: "Erro ao atualizar as informações." };
Expand Down
6 changes: 4 additions & 2 deletions data/editPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { getUserByEmail } from "./user";
export const editpost = async (
post_id: number,
title : string,
description : string
description : string,
imageUrl : string
) => {
try {
// Autenticação para obter a sessão e o ID do usuário
Expand All @@ -25,7 +26,8 @@ export const editpost = async (
id : post_id
},data : {
title,
description
description,
imageUrl
}
});

Expand Down

0 comments on commit ac9f64a

Please sign in to comment.