This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
53 lines (48 loc) · 1.63 KB
/
routes.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
const instagramProfiles = require('./Controllers/InstagramProfileController');
const tiktokProfiles = require('./Controllers/TiktokProfileController');
const twitterProfiles = require('./Controllers/TwitterProfileController');
const youtubeProfiles = require('./Controllers/YoutubeProfileController');
async function routes(fastify) {
fastify.get('/', (request, reply) => {
reply
.code(200)
.header('Content-Type', 'application/json; charset=utf-8')
.send({ healthcheck: 'Social Search Engine :)' });
});
fastify.route({
method: 'GET',
url: '/api/v1/profiles',
schema: {
querystring: {
search: { type: 'string' },
social: { type: 'string' },
is_premium: { type: 'boolean' },
},
},
handler: async (request, reply) => {
const { search, social } = request.query;
if (search) {
switch (social) {
case 'instagram':
return instagramProfiles.getAll(request, reply);
case 'tiktok':
return tiktokProfiles.getAll(request, reply);
case 'twitter':
return twitterProfiles.getAll(request, reply);
case 'youtube':
return youtubeProfiles.getAll(request, reply);
default:
return reply
.code(422)
.header('Content-Type', 'application/json; charset=utf-8')
.send({ code: 422, data: 'Rede social inválida!' });
}
}
return reply
.code(422)
.header('Content-Type', 'application/json; charset=utf-8')
.send({ code: 422, data: 'Busca inválida!' });
},
});
}
module.exports = routes;