Compare commits
No commits in common. "3e1a2f6b5b97f729223a0f3e22a54891b6ceb863" and "5684e19582f6dbd4ea9f4a27e31f3fdabf0bab60" have entirely different histories.
3e1a2f6b5b
...
5684e19582
|
|
@ -10,25 +10,17 @@ const Avatar = ({ user }: any) => {
|
||||||
const [firstLoad, setFirstLoad] = useState(true);
|
const [firstLoad, setFirstLoad] = useState(true);
|
||||||
|
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
fetch(gravatarUrl)
|
fetch(gravatarUrl).then((response) => {
|
||||||
.then((response) => {
|
if (response.status === 200) {
|
||||||
if (response.ok) {
|
setAvatar(gravatarUrl);
|
||||||
setAvatar(gravatarUrl);
|
}
|
||||||
}
|
setFirstLoad(false);
|
||||||
setFirstLoad(false);
|
});
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
setFirstLoad(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="avatar shrink-0">
|
<div className="avatar shrink-0">
|
||||||
<Image
|
<Image src={avatar} alt="avatar" className="rounded-full w-12 h-12 md:w-16 md:h-16 transition-all cursor-pointer" />
|
||||||
src={avatar}
|
|
||||||
alt="avatar"
|
|
||||||
className="rounded-full w-12 h-12 md:w-16 md:h-16 transition-all cursor-pointer"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -40,17 +40,14 @@ const Message = ({ message }: any) => {
|
||||||
</div>
|
</div>
|
||||||
<Text text={message.content} />
|
<Text text={message.content} />
|
||||||
{message.image && <Image src={message.image} alt="image" className="w-fit rounded-lg cursor-pointer" />}
|
{message.image && <Image src={message.image} alt="image" className="w-fit rounded-lg cursor-pointer" />}
|
||||||
<div className="flex justify-between">
|
<div className="text-grey-light date">
|
||||||
<div className="text-grey-light date">
|
{new Date(message.createdAt).toLocaleDateString(undefined, {
|
||||||
{new Date(message.createdAt).toLocaleDateString(undefined, {
|
year: 'numeric',
|
||||||
year: 'numeric',
|
month: 'long',
|
||||||
month: 'long',
|
day: 'numeric',
|
||||||
day: 'numeric',
|
hour: 'numeric',
|
||||||
hour: 'numeric',
|
minute: 'numeric',
|
||||||
minute: 'numeric',
|
})}
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
{message.edited && <div className="text-grey-light italic">Modifié</div>}
|
|
||||||
</div>
|
</div>
|
||||||
{me.data?.id === message.author.id ? null : (
|
{me.data?.id === message.author.id ? null : (
|
||||||
<Like
|
<Like
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ model Post {
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
likes Int @default(0)
|
likes Int @default(0)
|
||||||
likedBy Like[]
|
likedBy Like[]
|
||||||
edited Boolean @default(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Like {
|
model Like {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
const storage = multer.diskStorage({
|
const storage = multer.diskStorage({
|
||||||
destination: path.join(__dirname, '../../public/uploads'),
|
destination: path.join(__dirname, '../../public/uploads'),
|
||||||
|
|
@ -11,12 +10,3 @@ const storage = multer.diskStorage({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const upload = multer({ storage });
|
export const upload = multer({ storage });
|
||||||
|
|
||||||
export const deleteFile = (filename: string) => {
|
|
||||||
const filePath = path.join(__dirname, '../../public/uploads', filename);
|
|
||||||
fs.unlink(filePath, (err) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { PrismaClient, Post as PrismaPost, Like } from '@prisma/client';
|
||||||
import { Post } from '@/models/PostModel';
|
import { Post } from '@/models/PostModel';
|
||||||
import { exclude } from '@/lib/utils';
|
import { exclude } from '@/lib/utils';
|
||||||
import { getUserById } from './UserController';
|
import { getUserById } from './UserController';
|
||||||
import { deleteFile } from './FileController';
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
|
@ -67,7 +66,6 @@ const editPost = async (post: Post): Promise<PrismaPost | null | Error> => {
|
||||||
data: {
|
data: {
|
||||||
content: post.content,
|
content: post.content,
|
||||||
image: post.image,
|
image: post.image,
|
||||||
edited: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -96,9 +94,6 @@ const deletePost = async (id: number, userId: number): Promise<PrismaPost | Erro
|
||||||
if (post.authorId !== userId && user.role === 'USER') {
|
if (post.authorId !== userId && user.role === 'USER') {
|
||||||
return new Error('User is not the author of this post');
|
return new Error('User is not the author of this post');
|
||||||
}
|
}
|
||||||
if (post.image) {
|
|
||||||
deleteFile(post.image);
|
|
||||||
}
|
|
||||||
return prisma.post.delete({
|
return prisma.post.delete({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ interface Post {
|
||||||
authorId: number;
|
authorId: number;
|
||||||
likes?: number | undefined;
|
likes?: number | undefined;
|
||||||
likedBy?: Like[] | undefined;
|
likedBy?: Like[] | undefined;
|
||||||
edited?: boolean | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Post: z.ZodType<Post> = z.object({
|
const Post: z.ZodType<Post> = z.object({
|
||||||
|
|
@ -18,7 +17,6 @@ const Post: z.ZodType<Post> = z.object({
|
||||||
authorId: z.number(),
|
authorId: z.number(),
|
||||||
likes: z.number().optional(),
|
likes: z.number().optional(),
|
||||||
likedBy: z.array(Like).optional(),
|
likedBy: z.array(Like).optional(),
|
||||||
edited: z.boolean().optional(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export { Post };
|
export { Post };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue