UNPKG

2.46 kBJavaScriptView Raw
1var requestify = require('requestify');
2var config = require('./config');
3
4var repository = {};
5
6repository.getById = function(id) {
7 var url = 'http://' + config.host + '/contractor/get/' + id;
8 return new Promise(function(resolve, reject) {
9 requestify.get(url).then(function(response) {
10 var body = response.getBody();
11 if (response.code == 200) {
12
13 if (body.TipoErro) {
14 reject(null);
15 return;
16 }
17
18 if (!body.data) {
19 reject(null);
20 return;
21 }
22
23 resolve(body.data);
24 return;
25 } else {
26 reject(null);
27 return;
28 }
29 }).catch(function(ex) {
30 throw ex;
31 });
32 });
33};
34
35repository.getConnections = function() {
36 var url = `http://${config.host}/contractor/connection/list`;
37 return new Promise(function(resolve, reject) {
38 requestify.get(url).then(function(response) {
39 var body = response.getBody();
40 if (response.code == 200) {
41
42 if (body.TipoErro) {
43 reject(null);
44 return;
45 }
46
47 if (!body.data) {
48 reject(null);
49 return;
50 }
51
52 resolve(body.data);
53 return;
54 } else {
55 reject(null);
56 return;
57 }
58 }).catch(function(ex) {
59 throw ex;
60 });
61 });
62};
63
64repository.getConnectionsById = function(contractor_id, handle) {
65 var url = `http://${config.host}/contractor/connection/getByApplicationHandle/${contractor_id}/${handle}`;
66 return new Promise(function(resolve, reject) {
67 requestify.get(url).then(function(response) {
68 var body = response.getBody();
69 if (response.code == 200) {
70
71 if (body.TipoErro) {
72 reject(null);
73 return;
74 }
75
76 if (!body.data) {
77 reject(null);
78 return;
79 }
80
81 resolve(body.data);
82 return;
83 } else {
84 reject(null);
85 return;
86 }
87 }).catch(function(ex) {
88 throw ex;
89 });
90 });
91};
92
93module.exports = repository;
\No newline at end of file