@@ -109,19 +109,28 @@ export class UfficioPostale implements Service {
109109 }
110110
111111 async listRaccomandate ( state ?: 'NEW' | 'CONFIRMED' | 'SENDING' | 'SENT' | 'ERROR' ) : Promise < SigleRaccomandata [ ] > {
112- return await ( await this . client . get ( this . url + '/raccomandate' + ( state ? `/ ${ state } ` : '' ) ) ) . data . data ;
112+ return await ( await this . client . get ( this . url + '/raccomandate/' , state ? { params : { state } } : { } ) ) . data ;
113113 }
114114
115115 async getRaccomandata ( id : string ) {
116116 return await ( await this . client . get ( this . url + '/raccomandate' + `/${ id } ` ) ) . data . data ;
117117 }
118118
119119 async createRaccomandataRequest ( mittente : Mittente , destinatari : Destinatari , documento : string [ ] , opzioni : Opzioni = { } , autoconfirm = false ) : Promise < RaccomandataResponse [ ] | any [ ] > {
120- if ( ! ( 'autoconfirm' in opzioni ) ) opzioni = { ...opzioni , autoconfirm }
121- return await ( await this . client . post ( this . url + '/raccomandate' , JSON . stringify ( { mittente, destinatari, documento, opzioni} ) ) ) . data . data ;
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 ;
122122 }
123123
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+ */
124128 async confirmRequest ( request_id : string | RaccomandataResponse ) {
129+ if ( Array . isArray ( request_id ) ) {
130+ request_id = request_id [ 0 ]
131+ }
132+
133+
125134 const id : string = ( typeof request_id === 'object' && 'id' in request_id ) ? request_id . id : request_id ;
126135 return await ( await this . client . patch ( this . url + '/raccomandate/' + id , JSON . stringify ( { 'confirmed' : true } ) ) ) . data . data ;
127136 }
0 commit comments