How to use the google-ads-node/build/lib/utils.getFieldMask function in google-ads-node

To help you get started, we’ve selected a few google-ads-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Opteo / google-ads-api / src / services / customer.ts View on Github external
if (!operation_mode) {
                operation_mode = 'create'
            }

            if (operation_mode !== 'create' && operation_mode !== 'update' && operation_mode !== 'delete') {
                throw new Error(`"_operation" field must be one of "create"|"update"|"delete"`)
            }

            if (operation_mode === 'create') {
                resource_operation.setCreate(pb)
            }

            if (operation_mode === 'update') {
                resource_operation.setUpdate(pb)
                const update_mask = getFieldMask(operation)
                resource_operation.setUpdateMask(update_mask)
            }

            if (operation_mode === 'delete') {
                // @ts-ignore Types are no use here
                if (!pb.toObject().hasOwnProperty('resourceName') || !pb.toObject().resourceName) {
                    throw new Error(`Must specify "resource_name" to remove when using "delete"`)
                }
                // @ts-ignore Types are no use here
                resource_operation.setRemove(pb.toObject().resourceName)
            }

            /* Add operation of resource type to global mutate operation e.g. "MutateOperation.setCampaignBudgetOperation" */
            const op = new grpc.MutateOperation()
            const operation_set_method = `set${operation_resource_name}Operation`
            // @ts-ignore Types are no use here
github Opteo / google-ads-api / src / services / service.ts View on Github external
const operationType = (grpc as any)[options.operation]

        const operations = []

        // If the user passed in only one entity, convert it to an array of length 1
        if (!Array.isArray(options.entity[1])) {
            options.entity[1] = [options.entity[1]]
        }

        for (const entity of options.entity[1] as Array) {
            const operation = new operationType()

            const pb = this.buildResource(options.entity[0], entity)
            operation.setUpdate(pb)

            const mask = getFieldMask(entity)
            operation.setUpdateMask(mask)

            operations.push(operation)
        }

        return this.mutate(request, operations, options)
    }
github Opteo / google-ads-api / src / services / customer.ts View on Github external
public async update(customer: Customer, options?: ServiceCreateOptions): UpdateResponse {
        const request = new grpc.MutateCustomerRequest()
        const operation = new grpc.CustomerOperation()

        const pb = this.buildResource('Customer', customer) as grpc.Customer
        operation.setUpdate(pb)

        const mask = getFieldMask(customer)
        operation.setUpdateMask(mask)

        request.setCustomerId(this.cid)
        request.setOperation(operation)

        if (options && options.hasOwnProperty('validate_only')) {
            request.setValidateOnly(options.validate_only as boolean)
        }

        await this.service.mutateCustomer(request)
    }