Skip to content

Commit 54440c1

Browse files
aggiornato ws imprese
1 parent 2e4229a commit 54440c1

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

src/Services/Imprese.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ export interface SearchImprese {
99
cf?: string;
1010
}
1111

12+
interface AutocompleteImprese {
13+
id: string;
14+
denominazione: string;
15+
}
16+
17+
interface NaturaGiuridica {
18+
codice_natura_giuridica: string;
19+
valore: string;
20+
}
21+
1222
export class Imprese implements Service {
1323
client: AxiosInstance;
1424
readonly service = 'imprese';
@@ -42,6 +52,15 @@ export class Imprese implements Service {
4252
const res = (await this.client.get(this.url + '/pec/' + partitaIva)).data.data
4353
return res.pec ? res.pec : res;
4454
}
55+
56+
/**
57+
* Autocomplete service
58+
* Wildcards (*) can be used at the beginning or at the end of the string.
59+
*/
60+
async autocomplete(query: string): Promise<AutocompleteImprese[]> {
61+
if (!query.match(/\*/)) query = `*${query}*`
62+
return await (await this.client.get(this.url + '/autocomplete/' + query)).data.data;
63+
}
4564

4665
/**
4766
* Richiede accesso ad /advance
@@ -50,6 +69,14 @@ export class Imprese implements Service {
5069
return await (await this.client.get(this.url + '/advance', { params: searchQuery })).data.data;
5170
}
5271

72+
async listFormeGiuridiche(): Promise<NaturaGiuridica[]> {
73+
return await (await this.client.get(this.url + '/forma_giuridica')).data.data;
74+
}
75+
76+
async getFormaGiuridica(legalCode: string): Promise<NaturaGiuridica> {
77+
return await (await this.client.get(this.url + '/forma_giuridica/' + legalCode)).data.data;
78+
}
79+
5380
get url() {
5481
return getBaseUrl(this.environment, this.baseUrl)
5582
}

test/client.test.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ let OpenApi = require('../dist/index').default;
44
const scopes = [
55
"GET:ws.ufficiopostale.com/raccomandate",
66
"GET:imprese.altravia.com/autocomplete",
7-
// "GET:test.imprese.altravia.com/base",
8-
// "GET:imprese.altravia.com/advance",
9-
// "GET:imprese.altravia.com/pec",
10-
// "GET:imprese.altravia.com/autocomplete",
11-
// "GET:imprese.altravia.com/closed",
127
"*:imprese.altravia.com/*",
138
"GET:comuni.openapi.it/cap",
149
"GET:comuni.openapi.it/istat",
@@ -29,7 +24,7 @@ const scopes = [
2924
"POST:ws.marchetemporali.com/verifica",
3025
"POST:ws.marchetemporali.com/analisi",
3126
'imprese.altravia.com',
32-
// 'pa.openapi.it',
27+
'pa.openapi.it',
3328
];
3429

3530
// test('init', async function() {
@@ -39,13 +34,13 @@ const scopes = [
3934
// expect(typeof token === 'string').toBeTruthy()
4035
// })
4136

42-
test('initWithString', async function() {
37+
// test('initWithString', async function() {
4338

44-
let client = await OpenApi.init('production', process.env.OPENAPI_USERNAME, process.env.API_KEY);
45-
const token = await client.generateToken('imprese.altravia.com');
46-
expect(typeof token === 'string').toBeTruthy()
47-
console.log(client.scopes);
48-
})
39+
// let client = await OpenApi.init('production', process.env.OPENAPI_USERNAME, process.env.API_KEY);
40+
// const token = await client.generateToken('imprese.altravia.com');
41+
// expect(typeof token === 'string').toBeTruthy()
42+
// console.log(client.scopes);
43+
// })
4944

5045
// test('initWithToken', async function() {
5146
// let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
@@ -102,22 +97,30 @@ test('initWithString', async function() {
10297
// })
10398

10499
// test('testImprese', async function() {
105-
// let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
106-
100+
// let client = await OpenApi.init('production', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
101+
// console.log(JSON.stringify(client.scopes, null, 2));
102+
107103
// const piva = await client.imprese.getByPartitaIva('12485671007')
108104
// expect(piva).toBeDefined();
109105
// console.log(piva);
110106

111107
// const pivaAvd = await client.imprese.getAdvancedByPartitaIva('12485671007')
112108
// expect(pivaAvd).toBeDefined();
109+
113110
// const pec = await client.imprese.getPec('12485671007')
114111
// expect(pec).toBeDefined();
115112
// console.log(pec);
116113

117-
// const imprese = await client.imprese.search({ provincia: 'RM' })
118-
119-
// expect(imprese).toBeDefined();
114+
// const imprese = await client.imprese.search({ provincia: 'RM' })
115+
// expect(imprese).toBeDefined();
120116
// console.log(imprese);
117+
118+
// const auto = await client.imprese.autocomplete('pizzeria')
119+
// expect(auto).toBeDefined()
120+
// console.log(auto);
121+
122+
// const fg = await client.imprese.listFormeGiuridiche()
123+
// expect(fg).toBeDefined()
121124
// })
122125

123126
// test('testPa', async function() {

0 commit comments

Comments
 (0)