healthreport.prototype.getVehicleHealthReport = function()

in source/services/vehicle/lib/healthreport.js [107:160]


    healthreport.prototype.getVehicleHealthReport = function(ticket, vin, reportId, 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 hr_params = {
                    TableName: ddbTable,
                    Key: {
                        vin: vin,
                        report_id: reportId
                    }
                };

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

                    if (!_.isEmpty(hr_data)) {
                        return cb(null, hr_data.Item);
                    } else {
                        return cb({
                            error: {
                                message: 'The health report record requested does not exist.'
                            }
                        }, null);
                    }
                });
            } else {
                return cb({
                    error: {
                        message: 'The vehicle requested is not registered under the user.'
                    }
                }, null);
            }
        });

    };