-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticles.js
56 lines (51 loc) · 1.41 KB
/
articles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import articles from '../controllers/articles';
import { validate } from '../lib/tokens';
import { isAdmin } from '../lib/auth';
const routes = (fastify) => {
fastify.get(
'/articles/range/:offset/:limit/:order',
articles.getRange,
);
fastify.get('/articles/by/title', articles.getByTitle);
fastify.get(
'/articles/unpublished/:offset/:limit/:order',
articles.getUnpublished,
);
fastify.get(
'/articles/:limit/:order',
articles.getWithLimitAndOrder,
);
fastify.get('/articles/count/published', articles.countPublished);
fastify.get('/articles/count', articles.count);
fastify.get('/articles/:limit', articles.getWithLimit);
fastify.get('/articles', articles.get);
fastify.get('/article/next/:id', articles.getNext);
fastify.get('/article/prev/:id', articles.getPrev);
fastify.get('/article/:slug', articles.getOneBySlug);
fastify.post(
'/article',
{ beforeHandler: [validate, isAdmin] },
articles.create,
);
fastify.patch(
'/article',
{ beforeHandler: [validate, isAdmin] },
articles.update,
);
fastify.patch(
'/article/publish',
{ beforeHandler: [validate, isAdmin] },
articles.publish,
);
fastify.patch(
'/article/unpublish',
{ beforeHandler: [validate, isAdmin] },
articles.unpublish,
);
fastify.delete(
'/article',
{ beforeHandler: [validate, isAdmin] },
articles.del,
);
};
export default routes;