@@ -11,6 +11,22 @@ interface SigleRaccomandata {
1111 id : string ;
1212}
1313
14+ interface SingleTelegramma {
15+ mittente : TelegrammaMittente ;
16+ creation_timestamp : number ;
17+ update_timestamp : number ;
18+ confirmed : boolean ;
19+ state : string ;
20+ error ?: any ;
21+ id : string ;
22+ }
23+
24+ interface TelegrammaMittente {
25+ nome : string ;
26+ cognome : string ;
27+ email : string ;
28+ }
29+
1430interface Mittente {
1531 nome : string ;
1632 cognome : string ;
@@ -90,7 +106,7 @@ interface Documentovalidato {
90106 size : number ;
91107}
92108
93- interface Tracking {
109+ interface TrackingStatus {
94110 timestamp : number ;
95111 descrizione : string ;
96112 type : string ;
@@ -108,39 +124,42 @@ export class UfficioPostale implements Service {
108124 this . environment = environment ;
109125 }
110126
111- async listRaccomandate ( state ?: 'NEW' | 'CONFIRMED' | 'SENDING' | 'SENT' | 'ERROR' ) : Promise < SigleRaccomandata [ ] > {
112- return await ( await this . client . get ( this . url + '/raccomandate/' , state ? { params : { state } } : { } ) ) . data ;
127+ async listDug ( ) : Promise < { codice_dug : string ; dug : string } [ ] > {
128+ return await ( await this . client . get ( this . url + '/dug' ) ) . data . data ;
113129 }
114130
115- async getRaccomandata ( id : string ) {
116- return await ( await this . client . get ( this . url + '/raccomandate' + `/${ id } ` ) ) . data . data ;
131+ async addresses ( cap : string , comune : string , dug : string ) {
132+ return await ( await this . client . get ( this . url + '/indirizzi' , { params : { cap, comune, dug} } ) ) . data . data ;
133+ }
134+
135+ async pricing ( cap : string , comune : string , dug : string ) : Promise < Array < any > > {
136+ return await ( await this . client . get ( this . url + '/pricing' ) ) . data . data ;
117137 }
118138
119- async createRaccomandataRequest ( mittente : Mittente , destinatari : Destinatari , documento : string [ ] , opzioni : Opzioni = { } , autoconfirm = false ) : Promise < RaccomandataResponse [ ] | any [ ] > {
120- if ( opzioni && ! ( 'autoconfirm' in opzioni ) ) opzioni = { ...opzioni , autoconfirm }
121- return await ( await this . client . post ( this . url + '/raccomandate/' , JSON . stringify ( { mittente, destinatari, documento, opzioni} ) ) ) . data . data ;
139+ async track ( id : string ) : Promise < TrackingStatus [ ] > {
140+ return await ( await this . client . get ( this . url + '/tracking/' + id ) ) . data . data ;
122141 }
123142
124- /**
125- * Conferma l'invio della raccomandata.
126- * Accetta un id od un oggetto `RaccomandataResponse` ritornato durante la richiesta; se viene passato un array di richieste, ne prende in considerazione solo la prima
127- */
128- async confirmRequest ( request_id : string | RaccomandataResponse ) {
129- if ( Array . isArray ( request_id ) ) {
130- request_id = request_id [ 0 ]
131- }
143+ async comuni ( postalCode : string ) {
144+ return await ( await this . client . get ( this . url + '/comuni/' + postalCode ) ) . data . data ;
145+ }
132146
147+ // @todo Raccomandate
148+ async listRaccomandate ( ) : Promise < SigleRaccomandata [ ] > {
149+ return await ( await this . client . get ( this . url + '/raccomandate' ) ) . data . data ;
150+ }
133151
134- const id : string = ( typeof request_id === 'object' && 'id' in request_id ) ? request_id . id : request_id ;
135- return await ( await this . client . patch ( this . url + '/raccomandate/' + id , JSON . stringify ( { 'confirmed' : true } ) ) ) . data . data ;
152+ async getRaccomandata ( id : string ) {
153+ return await ( await this . client . get ( this . url + '/raccomandate/' + id ) ) . data . data ;
136154 }
137155
138- async track ( tracking_number : string ) : Promise < Tracking [ ] > {
139- return await ( await this . client . get ( this . url + '/traking/' + tracking_number ) ) . data . data ;
156+ // @todo Telegrammi
157+ async listTelegrammi ( ) : Promise < SingleTelegramma [ ] > {
158+ return await ( await this . client . get ( this . url + '/telegrammi' ) ) . data . data ;
140159 }
141160
142- async listDug ( ) : Promise < { codice_dug : string ; dug : string } [ ] > {
143- return await ( await this . client . get ( this . url + '/dug' ) ) . data . data ;
161+ async getTelegramma ( id : string ) {
162+ return await ( await this . client . get ( this . url + '/telegrammi/' + id ) ) . data . data ;
144163 }
145164
146165 get url ( ) {
0 commit comments