Skip to content

Commit 53c8754

Browse files
authored
Merge pull request #476 from CodingFactory-Repos/G7/feature/fixBabacarReturn
add capitalize to title && change design validation tuto && change ju…
2 parents 229d057 + b847dba commit 53c8754

8 files changed

Lines changed: 98 additions & 68 deletions

File tree

back-end/src/base/articles/articles.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ArticlesService {
2222
// add new object id to id
2323
queryArticle._id = new ObjectId();
2424

25-
queryArticle.owner = new ObjectId(queryArticle.owner);
25+
queryArticle.owner._id = new ObjectId(queryArticle.owner._id);
2626
queryArticle.date = new Date(queryArticle.date);
2727
queryArticle.updatedAt = new Date();
2828

front-end/src/components/blog/AddArticles.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,16 @@ const addArticle = async () => {
266266
return;
267267
}
268268
269+
const owner = {
270+
_id: authStore?.user?._id,
271+
firstName: authStore?.user?.profile?.firstName,
272+
lastName: authStore?.user?.profile?.lastName,
273+
};
274+
269275
// Groups all data for sending to the API
270276
if (type.value == 'Infos') {
271277
let data = {
272-
owner: authStore.user._id,
278+
owner: owner,
273279
title: title.value,
274280
descriptions: description.value,
275281
content: content.value,
@@ -286,7 +292,7 @@ const addArticle = async () => {
286292
await articleStore.addArticle(data);
287293
} else {
288294
let data = {
289-
owner: authStore.user._id,
295+
owner: owner,
290296
title: title.value,
291297
descriptions: description.value,
292298
content: content.value,

front-end/src/components/blog/CardArticle.vue

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!-- eslint-disable vue/no-v-html -->
22
<template>
3-
<div class="boxShadow w-full">
3+
<div class="boxShadow w-96">
44
<img
5-
class="object-cover h-48 w-96 rounded-t-lg"
5+
class="object-cover h-48 w-full rounded-t-lg"
66
:src="
77
item.picture && item.picture != ''
88
? item.picture
99
: 'https://cdn.discordapp.com/attachments/894865078824890408/1073218625718198342/Fof04PpacAQePOW.png'
1010
"
1111
alt=""
1212
/>
13-
<div v-if="item.owner === user._id || user.role === 2" class="absolute top-2 left-2">
13+
<div v-if="item.owner._id === user._id || user.role === 2" class="absolute top-2 left-2">
1414
<button
1515
type="button"
1616
@click="deleteArticle(item._id)"
@@ -19,7 +19,7 @@
1919
<DeleteLogo />
2020
</button>
2121
</div>
22-
<div v-if="item.owner === user._id || user.role === 2" class="absolute top-2 right-2">
22+
<div v-if="item.owner._id === user._id || user.role === 2" class="absolute top-2 right-2">
2323
<button
2424
type="button"
2525
@click="editArticle(item._id)"
@@ -29,20 +29,46 @@
2929
</button>
3030
</div>
3131
<div class="pt-3 pb-2" v-if="item.type == 'Tuto' && (user.role == 2 || user.role == 3)">
32-
<span
33-
v-if="item.status == 'Accepted'"
34-
class="bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300"
35-
>
36-
Accepté
37-
</span>
38-
<span
39-
v-else
40-
class="bg-yellow-100 text-yellow-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300"
32+
<div
33+
v-if="item.status != 'Accepted'"
34+
class="flex flex-row items-center justify-evenly space-x-2"
4135
>
42-
En attente
43-
</span>
36+
<button
37+
@click="updateStatus(item._id, 'Accepted')"
38+
class="text-green-700 border border-green-700 focus:ring-4 focus:outline-none font-small rounded-lg text-2xs p-1 text-center inline-flex items-center dark:text-green-500"
39+
>
40+
<Validate />
41+
</button>
42+
43+
<span
44+
class="bg-yellow-100 text-yellow-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300"
45+
>
46+
En attente
47+
</span>
48+
49+
<button
50+
@click="deleteArticle(item._id)"
51+
class="text-red-700 border border-red-700 focus:ring-4 focus:outline-none font-small rounded-lg text-2xs p-1 text-center inline-flex items-center dark:text-red-500"
52+
>
53+
<Cross class="!fill-red-700" />
54+
</button>
55+
</div>
56+
<div v-else class="flex flex-row items-center justify-evenly space-x-2">
57+
<span
58+
v-if="item.status == 'Accepted'"
59+
class="bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300"
60+
>
61+
Accepté
62+
</span>
63+
<button
64+
@click="updateStatus(item._id, 'Pending')"
65+
class="text-yellow-400 border border-yellow-400 focus:ring-4 focus:outline-none font-small rounded-lg text-2xs p-1 text-center inline-flex items-center dark:text-yellow-500"
66+
>
67+
<Pause class="!fill-yellow-400" />
68+
</button>
69+
</div>
4470
</div>
45-
<div class="pt-3 pb-2" v-else>
71+
<div class="pt-3.5 pb-3.5" v-else>
4672
<span
4773
class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300"
4874
>
@@ -51,17 +77,21 @@
5177
</div>
5278
<div class="pt-2 pb-5">
5379
<a href="#">
54-
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">
80+
<h5
81+
:class="item.title.length > 40 && 'text-xl'"
82+
class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white capitalize"
83+
>
5584
{{ item.title ? item.title : 'Pas de titre spécifié' }}
5685
</h5>
5786
</a>
5887
<p
88+
:class="item.descriptions.length > 60 && 'text-md'"
5989
class="min-h-[5rem] flex flex-col justify-center items-center justify-center font-normal text-gray-700 dark:text-gray-400"
6090
>
6191
{{ item.descriptions ? item.descriptions : 'Pas de description spécifiée' }}
6292
</p>
6393
</div>
64-
<div class="pt-2 pb-5 flex flex-row justify-around items-center">
94+
<div class="pt-2 pb-5 flex flex-row justify-evenly items-center">
6595
<button
6696
type="button"
6797
@click="addLike(item._id)"
@@ -117,36 +147,6 @@
117147
</div>
118148
</button>
119149
</div>
120-
121-
<!-- Validation -->
122-
<div
123-
v-if="item.type == 'Tuto' && (user.role == 2 || user.role == 3)"
124-
class="flex flex-row place-content-evenly mb-3 items-center text-dark-primary dark:text-light-primary"
125-
>
126-
<div class="flex flex-row space-x-2">
127-
<button
128-
v-if="item.status != 'Accepted'"
129-
@click="updateStatus(item._id, 'Accepted')"
130-
class="text-green-700 border border-green-700 focus:ring-4 focus:outline-none font-medium rounded-lg text-xs p-2 text-center inline-flex items-center dark:text-green-500"
131-
>
132-
<Validate />
133-
</button>
134-
<button
135-
v-else
136-
@click="updateStatus(item._id, 'Pending')"
137-
class="text-yellow-400 border border-yellow-400 focus:ring-4 focus:outline-none font-medium rounded-lg text-xs p-2 text-center inline-flex items-center dark:text-yellow-500"
138-
>
139-
<Pause class="!fill-yellow-400" />
140-
</button>
141-
<button
142-
v-if="item.status != 'Accepted'"
143-
@click="deleteArticle(item._id)"
144-
class="text-red-700 border border-red-700 focus:ring-4 focus:outline-none font-medium rounded-lg text-xs p-2 text-center inline-flex items-center dark:text-red-500"
145-
>
146-
<Cross class="!fill-red-700" />
147-
</button>
148-
</div>
149-
</div>
150150
</div>
151151
</template>
152152

front-end/src/components/blog/EditArticle.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,15 @@ const editArticle = async () => {
246246
return;
247247
}
248248
249+
const owner = {
250+
_id: authStore.user._id,
251+
firstName: authStore.user.profile.firstName,
252+
lastName: authStore.user.profile.lastName,
253+
};
254+
249255
// Groups all data for sending to the API
250256
let data = {
251-
owner: authStore.user._id,
257+
owner: owner,
252258
title: title.value,
253259
descriptions: descriptions.value,
254260
content: content.value,

front-end/src/components/blog/MarkdownViewer.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
class="mt-12 block max-w-xl p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700"
9090
>
9191
<h2>{{ description }}</h2>
92-
<p>Publié le : {{ formatDate(date)}}</p>
93-
<p>Par : {{ user }}</p>
92+
<p>Publié le : {{ formatDate(date) }}</p>
93+
<p>Par : {{ user }}</p>
9494
</div>
9595
</div>
9696

@@ -336,13 +336,15 @@ if (!props.markdown) {
336336
date.value = oneItems.value.date;
337337
title.value = oneItems.value.title;
338338
description.value = oneItems.value.descriptions;
339-
let tempUser = await materialStore.getUserById(oneItems.value.owner)
339+
let tempUser = await materialStore.getUserById(oneItems.value.owner._id);
340340
341-
// format for captital letters
342-
user.value =
343-
tempUser.profile.firstName.charAt(0).toUpperCase() + tempUser.profile.firstName.slice(1)
344-
+ ' '
345-
+ tempUser.profile.lastName.charAt(0).toUpperCase() + tempUser.profile.lastName.slice(1)
341+
// format for captital letters
342+
user.value =
343+
tempUser.profile.firstName.charAt(0).toUpperCase() +
344+
tempUser.profile.firstName.slice(1) +
345+
' ' +
346+
tempUser.profile.lastName.charAt(0).toUpperCase() +
347+
tempUser.profile.lastName.slice(1);
346348
347349
renderMarkdown();
348350
});
@@ -363,7 +365,7 @@ const step = ref(0);
363365
const title = ref('Your title here');
364366
const date = ref('The date it was uploaded');
365367
const description = ref('Your description here');
366-
const user = ref('Vous')
368+
const user = ref('Vous');
367369
368370
// visuals
369371
const open = ref(false);

front-end/src/components/blog/ShowArticle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
{{ comment.descriptions }}
219219
</p>
220220

221-
<div v-if="oneItems.owner === user._id || user.role === 2" class="absolute top-2 right-2">
221+
<div v-if="oneItems.owner._id === user._id || user.role === 2" class="absolute top-2 right-2">
222222
<button
223223
type="button"
224224
@click="removeComment(oneItems._id, comment)"

front-end/src/store/interfaces/article.interface.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface ArticleStore {
66

77
export interface Article {
88
_id?: string;
9-
owner: string;
9+
owner: Owner;
1010
date: Date;
1111
title: string;
1212
descriptions: string;
@@ -36,6 +36,12 @@ export interface Participants {
3636
email: string;
3737
}
3838

39+
export interface Owner {
40+
_id: string;
41+
firstName: string;
42+
lastName: string;
43+
}
44+
3945
export interface Comments {
4046
_id: string;
4147
email: string;

front-end/src/store/modules/article.store.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export const useArticleStore = defineStore('article', {
1616
items: [
1717
{
1818
_id: '',
19-
owner: '',
19+
owner: {
20+
_id: '',
21+
firstName: '',
22+
lastName: '',
23+
},
2024
date: new Date(),
2125
title: '',
2226
descriptions: '',
@@ -31,7 +35,11 @@ export const useArticleStore = defineStore('article', {
3135
],
3236
oneItems: {
3337
_id: '',
34-
owner: '',
38+
owner: {
39+
_id: '',
40+
firstName: '',
41+
lastName: '',
42+
},
3543
title: '',
3644
date: new Date(),
3745
descriptions: '',
@@ -92,9 +100,11 @@ export const useArticleStore = defineStore('article', {
92100

93101
//update article in the database
94102
updateArticle: withErrorHandler(async function (id: string, article: Article) {
95-
const response = await http.put(`/articles/update/${id}`, article);
96-
const oneItems = response.data;
97-
this.oneItems = oneItems;
103+
await http.put(`/articles/update/${id}`, article);
104+
105+
const index = this.items.findIndex((el) => el._id === id);
106+
this.items[index] = article;
107+
98108
return true;
99109
}),
100110

0 commit comments

Comments
 (0)