Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
Resin
Server
Commits
588f9bdf
Commit
588f9bdf
authored
4 years ago
by
Hugo SUBTIL
Browse files
Options
Downloads
Patches
Plain Diff
feat: add news tag handling
parent
1c281068
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!46
Recette
,
!45
Dev
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/posts/enums/tag.enum.ts
+10
-0
10 additions, 0 deletions
src/posts/enums/tag.enum.ts
src/posts/posts.controller.ts
+20
-13
20 additions, 13 deletions
src/posts/posts.controller.ts
src/posts/posts.service.ts
+34
-1
34 additions, 1 deletion
src/posts/posts.service.ts
with
64 additions
and
14 deletions
src/posts/enums/tag.enum.ts
0 → 100644
+
10
−
0
View file @
588f9bdf
export
enum
TagEnum
{
aLaUne
=
'
a-la-une
'
,
appels
=
'
appels
'
,
projets
=
'
projets
'
,
formations
=
'
formations
'
,
infos
=
'
infos
'
,
dossiers
=
'
dossiers
'
,
etudes
=
'
etudes
'
,
ressources
=
'
ressources
'
,
}
This diff is collapsed.
Click to expand it.
src/posts/posts.controller.ts
+
20
−
13
View file @
588f9bdf
import
{
Controller
,
Get
,
HttpService
,
Param
,
Query
}
from
'
@nestjs/common
'
;
import
{
Controller
,
Get
,
HttpService
,
Logger
,
Param
,
Query
}
from
'
@nestjs/common
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
map
}
from
'
rxjs/operators
'
;
import
{
catchError
,
map
}
from
'
rxjs/operators
'
;
import
{
ApiQuery
}
from
'
@nestjs/swagger
'
;
import
{
Post
}
from
'
./schemas/post.schema
'
;
import
{
PostsService
}
from
'
./posts.service
'
;
...
...
@@ -32,7 +32,24 @@ export class PostsController {
page
:
query
.
page
?
query
.
page
:
null
,
},
})
.
pipe
(
map
((
response
)
=>
response
.
data
));
.
pipe
(
map
((
response
)
=>
response
.
data
),
catchError
((
err
)
=>
{
Logger
.
error
(
err
);
return
new
Observable
();
})
);
}
@
Get
(
'
tags
'
)
public
async
findAllTags
():
Promise
<
{
public
:
Tag
[];
commune
:
Tag
[];
others
:
Tag
[]
}
>
{
return
Promise
.
all
([
this
.
postsService
.
getLocationTags
(),
this
.
postsService
.
getPublicTags
(),
this
.
postsService
.
getRegularTags
(),
]).
then
((
data
)
=>
{
return
{
commune
:
data
[
0
],
public
:
data
[
1
],
others
:
data
[
2
]
};
});
}
@
Get
(
'
:id
'
)
...
...
@@ -46,14 +63,4 @@ export class PostsController {
})
.
pipe
(
map
((
response
)
=>
response
.
data
));
}
@
Get
(
'
tags
'
)
public
async
findAllTags
():
Promise
<
{
public
:
Tag
[];
commune
:
Tag
[];
others
:
Tag
[]
}
>
{
return
Promise
.
all
([
this
.
postsService
.
getLocationTags
(),
this
.
postsService
.
getPublicTags
(),
this
.
postsService
.
getRegularTags
(),
]).
then
((
data
)
=>
{
return
{
commune
:
data
[
0
],
public
:
data
[
1
],
others
:
data
[
2
]
};
});
}
}
This diff is collapsed.
Click to expand it.
src/posts/posts.service.ts
+
34
−
1
View file @
588f9bdf
...
...
@@ -3,6 +3,7 @@ import { Logger } from '@nestjs/common';
import
*
as
GhostAdminAPI
from
'
@tryghost/admin-api
'
;
import
*
as
_
from
'
lodash
'
;
import
{
map
}
from
'
rxjs/operators
'
;
import
{
TagEnum
}
from
'
./enums/tag.enum
'
;
import
{
Tag
}
from
'
./schemas/tag.schema
'
;
@
Injectable
()
...
...
@@ -27,6 +28,24 @@ export class PostsService {
public
getTags
():
Promise
<
Tag
[]
>
{
return
this
.
api
.
tags
.
browse
({
limit
:
'
all
'
});
}
// public getTags(): Promise<Tag[]> {
// return new Promise((resolve) => {
// this.api.tags.browse({ limit: 'all' }).then((tags: Tag[]) => {
// tags.sort((x, y) => {
// if (x < y) {
// return -1;
// }
// if (x > y) {
// return 1;
// }
// return 0;
// });
// console.log(tags);
// resolve(tags);
// });
// });
// }
/**
* Get all locations tags. Ex: Oullins, Sainte-foy etc...
...
...
@@ -49,6 +68,20 @@ export class PostsService {
*/
public
async
getRegularTags
():
Promise
<
Tag
[]
>
{
const
tags
=
await
this
.
getTags
();
return
_
.
filter
(
tags
,
{
description
:
null
});
let
publicTags
=
_
.
filter
(
tags
,
{
description
:
null
});
// Remove 'Appel a projet'
_
.
remove
(
publicTags
,
{
slug
:
TagEnum
.
appels
});
// Move 'a la une' at index 0
publicTags
=
this
.
arraymove
(
publicTags
,
_
.
findIndex
(
publicTags
,
{
slug
:
TagEnum
.
aLaUne
}),
0
);
// Move 'info' at index 1
publicTags
=
this
.
arraymove
(
publicTags
,
_
.
findIndex
(
publicTags
,
{
slug
:
TagEnum
.
infos
}),
1
);
return
publicTags
;
}
public
arraymove
(
arr
,
fromIndex
,
toIndex
):
Array
<
any
>
{
const
element
=
arr
[
fromIndex
];
arr
.
splice
(
fromIndex
,
1
);
arr
.
splice
(
toIndex
,
0
,
element
);
return
arr
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment