From ec6041320999eeefc6a3232ce3f6f456c79f34e3 Mon Sep 17 00:00:00 2001
From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com>
Date: Wed, 3 Mar 2021 18:32:00 +0100
Subject: [PATCH] fix(post) : fix review ENUM logic + type properties

---
 .../post-card/post-card.component.html          |  8 +++++++-
 .../components/post-card/post-card.component.ts |  2 ++
 .../components/post-list/post-list.component.ts | 17 ++++++++---------
 src/app/post/enum/tag.enum.ts                   |  4 ++++
 src/app/post/services/post.service.ts           |  3 ++-
 5 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 src/app/post/enum/tag.enum.ts

diff --git a/src/app/post/components/post-card/post-card.component.html b/src/app/post/components/post-card/post-card.component.html
index 272aac44e..4ba85dbbe 100644
--- a/src/app/post/components/post-card/post-card.component.html
+++ b/src/app/post/components/post-card/post-card.component.html
@@ -1,6 +1,12 @@
 <div fxLayout="column" *ngIf="post" class="post" [ngClass]="class" fxLayoutGap="12px">
   <div fxLayout="column" fxLayoutGap="4px">
-    <div fxLayout="row" class="tag" fxLayoutAlign=" center" fxLayoutGap="12px" *ngIf="post.tags[0].slug != 'appels'">
+    <div
+      fxLayout="row"
+      class="tag"
+      fxLayoutAlign=" center"
+      fxLayoutGap="12px"
+      *ngIf="post.tags[0].slug != tagEnum.appels"
+    >
       <app-svg-icon
         [iconClass]="'icon-32'"
         [iconColor]="'inherit'"
diff --git a/src/app/post/components/post-card/post-card.component.ts b/src/app/post/components/post-card/post-card.component.ts
index e73dd03b3..a7d648e31 100644
--- a/src/app/post/components/post-card/post-card.component.ts
+++ b/src/app/post/components/post-card/post-card.component.ts
@@ -1,4 +1,5 @@
 import { Component, Input, OnInit } from '@angular/core';
+import { TagEnum } from '../../enum/tag.enum';
 import { Post } from '../../models/post.model';
 
 @Component({
@@ -9,6 +10,7 @@ import { Post } from '../../models/post.model';
 export class PostCardComponent implements OnInit {
   @Input() post: Post;
   @Input() class: string;
+  public tagEnum = TagEnum;
   constructor() {}
 
   ngOnInit(): void {}
diff --git a/src/app/post/components/post-list/post-list.component.ts b/src/app/post/components/post-list/post-list.component.ts
index 5b95ba4f8..8a3a96883 100644
--- a/src/app/post/components/post-list/post-list.component.ts
+++ b/src/app/post/components/post-list/post-list.component.ts
@@ -1,6 +1,6 @@
 import { Component, OnInit } from '@angular/core';
+import { TagEnum } from '../../enum/tag.enum';
 import { Post } from '../../models/post.model';
-import { PostWithMeta } from '../../models/postWithMeta.model';
 import { PostService } from '../../services/post.service';
 
 @Component({
@@ -10,18 +10,17 @@ import { PostService } from '../../services/post.service';
 })
 export class PostListComponent implements OnInit {
   constructor(private postService: PostService) {}
-  postsMobileView: Post[] = [];
-  leftColumnPosts: Post[] = [];
-  rightColumnPosts: Post[] = [];
-  projectsNew: Post[] = [];
-  bigNews: Post;
+  public postsMobileView: Post[] = [];
+  public leftColumnPosts: Post[] = [];
+  public rightColumnPosts: Post[] = [];
+  public projectsNew: Post[] = [];
+  public bigNews: Post;
 
   ngOnInit(): void {
     this.postService.getPosts().subscribe((news) => {
       news.posts.forEach((val, index) => {
         val = this.addAuthorToPost(val);
         this.postsMobileView.push(val);
-
         if (index % 2 == 0) {
           this.leftColumnPosts.push(val);
         } else {
@@ -29,10 +28,10 @@ export class PostListComponent implements OnInit {
         }
       });
     });
-    this.postService.getPosts(['a-la-une']).subscribe((news) => {
+    this.postService.getPosts([TagEnum.aLaUne]).subscribe((news) => {
       this.bigNews = this.addAuthorToPost(news.posts[0]);
     });
-    this.postService.getPosts(['appels']).subscribe((news) => {
+    this.postService.getPosts([TagEnum.appels]).subscribe((news) => {
       let projectNews = news.posts;
       projectNews.forEach((news) => {
         news = this.addAuthorToPost(news);
diff --git a/src/app/post/enum/tag.enum.ts b/src/app/post/enum/tag.enum.ts
new file mode 100644
index 000000000..0b6c049d9
--- /dev/null
+++ b/src/app/post/enum/tag.enum.ts
@@ -0,0 +1,4 @@
+export enum TagEnum {
+  aLaUne = 'a-la-une',
+  appels = 'appels',
+}
diff --git a/src/app/post/services/post.service.ts b/src/app/post/services/post.service.ts
index 848e6a58e..688b9c31b 100644
--- a/src/app/post/services/post.service.ts
+++ b/src/app/post/services/post.service.ts
@@ -2,6 +2,7 @@ import { HttpClient } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { Observable } from 'rxjs';
 import { map } from 'rxjs/operators';
+import { TagEnum } from '../enum/tag.enum';
 import { PostWithMeta } from '../models/postWithMeta.model';
 
 @Injectable({
@@ -14,7 +15,7 @@ export class PostService {
   public getPosts(tags?: string[]): Observable<PostWithMeta> {
     if (!tags) {
       return this.http
-        .get<PostWithMeta>(`${this.baseUrl}?include=tags,authors&filter=tag:-[appels,a-la-une]`)
+        .get<PostWithMeta>(`${this.baseUrl}?include=tags,authors&filter=tag:-[${TagEnum.aLaUne},${TagEnum.appels}]`)
         .pipe(map((item: PostWithMeta) => new PostWithMeta(item)));
     }
     let tagsString = '';
-- 
GitLab