I’d like to return a Promise on a spécific function that is not async.
The result is undefined when I call the function.
My code :
async function _callAccessControl(response, rpaReservation) {
if (rpaResource.access_control_identifier && !accessControlExist) {
return soap.createClientAsync('https://ipevia.com/public/files/onvif/credential.wsdl', {
endpoint: 'https://ipevia.com/index.php?OnvifServer',
forceSoap12Headers: true
}).then((credentialClient) => {
return credentialClient.CredentialService.CredentialPort.CreateCredential({
Credential: {
CredentialHolderReference: holderReference,
CredentialIdentifier: {
Type: {
Name: 'pt:PIN',
FormatType: 'SIMPLE_NUMBER16'
},
Value: rpaReservation.access_code
},
CredentialAccessProfile: {
AccessProfileToken: rpaResource.access_control_identifier,
ValidFrom: `${rpaReservationDateFormatted} ${rpaScheduleGrid.start_hour}:00`,
ValidTo: `${rpaReservationDateFormatted} ${rpaScheduleGrid.end_hour}:00`
}
}
}, function(err, result) {
return rpaReservation.update({
access_control_identifier: parseInt(result.Token, 10)
}).then((updatedReservation) => {
return updatedReservation;
});
}, { auth });
});
} else {
return rpaReservation;
}
}
_callAccessControl(response, rpaReservation).then((result) => {
// result is undefined
})
2
Answers
Is this what you want?
I think
resolve
will resolve your problem. 🙂And
reject
will handle the error part.You need to wrap
credentialClient.CredentialService.CredentialPort.CreateCredential
in a promise as shown below:and you can use it as shown below:
or, you can use the
async-await
syntax: