Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Azure:无法调用方法';然后';在exports.post中未定义的_Javascript_Azure_Mobile_Service_Promise - Fatal编程技术网

Javascript Azure:无法调用方法';然后';在exports.post中未定义的

Javascript Azure:无法调用方法';然后';在exports.post中未定义的,javascript,azure,mobile,service,promise,Javascript,Azure,Mobile,Service,Promise,我使用的是azure移动服务,具有以下自定义API: var returnVal = new Object; exports.post = function (request, response) { // Use "request.service" to access features of your mobile service, e.g.: // var tables = request.service.tables; // var push = req

我使用的是azure移动服务,具有以下自定义API:

var returnVal = new Object;


exports.post = function (request, response) {
    // Use "request.service" to access features of your mobile service, e.g.:
    //   var tables = request.service.tables;
    //   var push = request.service.push;

    var merchantdetailsTable = request.service.tables.getTable("merchantdetails");
    var resourceName;
    //console.log(JSON.stringify(request.parameters));
    merchantdetailsTable.insert({
        name: request.body.workerNameInput,
        emailid: request.body.workerEmailIDInput,
        contact: request.body.workerContactNumberInput
    }).then(function (merchantInserted) {
        returnVal.workerId = merchantInserted.id;
        resourceName = returnVal.workerId.toLowerCase();
        var shopworkersTable = request.service.tables.getTable("shopworkers");
        return shopworkersTable.insert({
            id: merchantInserted.id,
            shopid: request.body.shopId
        });
    }, function(err){
        return response.send(statusCodes.INTERNAL_SERVER_ERROR, err);
    }).then(function () {
        var accountName = appSettings.STORAGE_ACCOUNT_NAME;
        var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
        var host = accountName + '.blob.core.windows.net';
        var blobService = azure.createBlobService(accountName, accountKey, host);
        return blobService.createContainerIfNotExists("merchant-image", { publicAccessLevel: 'blob' });
    }, function (err) {
        return response.send(statusCodes.INTERNAL_SERVER_ERROR, err);
    }).then(function(error){
        if (!error) {
            // Provide write access to the container for the next 5 mins. 
            var sharedAccessPolicy = {
                AccessPolicy: {
                    Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
                    Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
                }
            };

            // Generate the upload URL with SAS for the new image.
            var sasQueryUrl =
         blobService.generateSharedAccessSignature("merchant-image",
         '', sharedAccessPolicy);
            // Set the query string.
         returnVal["merchantImage"].sasQueryString = qs.stringify(sasQueryUrl.queryString);

            // Set the full path on the new new item, 
            // which is used for data binding on the client. 
         returnVal["merchantImage"].imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path + '/'
                + resourceName;

         var accountName = appSettings.STORAGE_ACCOUNT_NAME;
         var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
         var host = accountName + '.blob.core.windows.net';
         var blobService = azure.createBlobService(accountName, accountKey, host);
         return blobService.createContainerIfNotExists("pharmacy-certificate", { publicAccessLevel: 'blob' });
        }
        else {
            return response.send(statusCodes.INTERNAL_SERVER_ERROR);
        }
    }, function (err) {
        return response.send(statusCodes.INTERNAL_SERVER_ERROR, err);
    }).done(function (error) {

        if (!error) {
            // Provide write access to the container for the next 5 mins. 
            var sharedAccessPolicy = {
                AccessPolicy: {
                    Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
                    Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
                }
            };

            // Generate the upload URL with SAS for the new image.
            var sasQueryUrl =
         blobService.generateSharedAccessSignature("pharmacy-certificate",
         '', sharedAccessPolicy);
            // Set the query string.
            returnVal["pharmacyCertificate"].sasQueryString = qs.stringify(sasQueryUrl.queryString);

            // Set the full path on the new new item, 
            // which is used for data binding on the client. 
            returnVal["pharmacyCertificate"].imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path + '/'
                   + resourceName;
            response.send(statusCodes.OK, returnVal);
        }
        else {
            return response.send(statusCodes.INTERNAL_SERVER_ERROR);
        }
    }, function (err) {
        return response.send(statusCodes.INTERNAL_SERVER_ERROR, err);
    });

    response.send(statusCodes.OK, { message : 'Hello World!' });
};

exports.get = function(request, response) {
  response.send(statusCodes.OK, { message : 'Hello World!' });
};
我遇到以下错误:

TypeError:无法调用未定义的方法“then” 在exports.post(D:\home\site\wwwroot\App\u Data\config\scripts\api\addWorker.js:17:8)


Azure移动服务不会从表操作返回承诺。您需要传递包含成功和错误回调的options对象,如中所述


我强烈建议您看看该产品的较新实现Azure Mobile Apps-。(免责声明:我在Azure移动应用程序团队中为Microsoft工作)

Azure移动服务不返回表操作的承诺。您需要传递包含成功和错误回调的options对象,如中所述


我强烈建议您看看该产品的较新实现Azure Mobile Apps-。(免责声明:我在Azure移动应用程序团队为Microsoft工作)

你有什么问题?你有什么办法来解决这个问题?那么?显然,
merchantdetailsTable.insert(…)
不会返回承诺。你为什么认为它应该这样做?你有一些API链接吗?一旦你解决了@Bergi注意到的问题,你可能想看看你是如何链接的-几乎每一个
然后
都有一个onRejected回调,它做完全相同的事情,并确保下一个onFullfilled回调将被称为dhi@Bergi,这里解释了azure的承诺。如果我将.done()与insert一起使用,它的效果非常好。但是,then()给出了错误。你的问题是什么?你有什么办法来解决这个问题?那么?显然,
merchantdetailsTable.insert(…)
不会返回承诺。你为什么认为它应该这样做?你有一些API链接吗?一旦你解决了@Bergi注意到的问题,你可能想看看你是如何链接的-几乎每一个
然后
都有一个onRejected回调,它做完全相同的事情,并确保下一个onFullfilled回调将被称为dhi@Bergi,这里解释了azure的承诺。如果我将.done()与insert一起使用,它的效果非常好。但是,then()给出了错误。