anomaly.prototype.acknowledgeVehicleAnomaly = function()

in source/services/vehicle/lib/anomaly.js [169:237]


    anomaly.prototype.acknowledgeVehicleAnomaly = function(ticket, vin, anomalyId, cb) {

        // verify user owns vehicle
        let params = {
            TableName: ownerTable,
            Key: {
                owner_id: ticket['cognito:username'],
                vin: vin
            }
        };

        let docClient = new AWS.DynamoDB.DocumentClient(dynamoConfig);
        docClient.get(params, function(err, data) {
            if (err) {
                console.log(err);
                return cb(err, null);
            }

            if (!_.isEmpty(data)) {
                let anomaly_params = {
                    TableName: ddbTable,
                    Key: {
                        vin: vin,
                        anomaly_id: anomalyId
                    }
                };

                let docClient = new AWS.DynamoDB.DocumentClient(dynamoConfig);
                docClient.get(anomaly_params, function(err, anomaly_data) {
                    if (err) {
                        console.log(err);
                        return cb(err, null);
                    }

                    if (!_.isEmpty(anomaly_data)) {

                        anomaly_data.Item.acknowledged = true;

                        let updateparams = {
                            TableName: ddbTable,
                            Item: anomaly_data.Item
                        };

                        docClient.put(updateparams, function(err, data) {
                            if (err) {
                                console.log(err);
                                return cb(err, null);
                            }

                            return cb(null, anomaly_data.Item);
                        });
                    } else {
                        return cb({
                            error: {
                                message: 'The anomaly record requested does not exist.'
                            }
                        }, null);
                    }
                });
            } else {
                return cb({
                    error: {
                        message: 'The vehicle requested is not registered under the user.'
                    }
                }, null);
            }
        });

    };