How to pass parameters thow callback functions - google-apps-script

I have created a button with this code:
CardService.newTextButton().setText('Akte in Flox öffnen').setOnClickOpenLinkAction(CardService.newAction().setFunctionName('testFunc').setParameters({test: "3"})).setTextButtonStyle(CardService.TextButtonStyle.TEXT);
the code of the callbackfunction:
function testFunc(e) {console.error(e);}
My problem:
How can I read the parameter "test"? In object "e" the property "parameters" is empty:
{ parameters: {},
userLocale: 'de',
commonEventObject:
{ timeZone: { id: 'Africa/Ceuta', offset: 3600000 },
userLocale: 'de',
platform: 'WEB',
hostApp: 'GMAIL' },
userCountry: '',
userTimezone: { offSet: '3600000', id: 'Africa/Ceuta' },
formInputs: {},
formInput: {},
clientPlatform: 'web',
gmail:
{ threadId: 'XXXXXXXXXXXXXXXXXXXXXXXXX',
accessToken: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
messageId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' },
messageMetadata:
{ accessToken: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
messageId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
threadId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' },
hostApp: 'gmail' }

You are using the wrong method
Your code:
CardService.newTextButton()
.setText("Akte in Flox öffnen")
.setOnClickOpenLinkAction( // ++++ THIS LINE +++++
CardService.newAction()
.setFunctionName("testFunc")
.setParameters({ test: "3" })
)
.setTextButtonStyle(CardService.TextButtonStyle.TEXT);
With modification:
CardService.newTextButton()
.setText("Akte in Flox öffnen")
.setOnClickAction( // SHOULD BE THIS
CardService.newAction()
.setFunctionName("testFunc")
.setParameters({ test: "3" })
)
.setTextButtonStyle(CardService.TextButtonStyle.TEXT);
Reference
setOnClickAction
setOnClickOpenLinkAction

The method "setOnClickOpenLinkAction" works fine and was not the problem. Apparently apps script cannot handle chaining in this case. I have restructured the code and it works:
var act = CardService.newAction(); act.setFunctionName('testFunc'); act.setParameters({test: "3"}); var btn = CardService.newTextButton().setText('AkteinFloxöffnen').setOnClickOpenLinkAction(act).setTextButtonStyle(CardService.TextButtonStyle.TEXT);

Related

Opensea Api returns Asset does not exist when creating an offer

Hi I use the opensea api to create an offer but all it returns is a 400 Error with the message "Asset does not exist". Even though I use the same API before to retrieve the asset. I use the seaport SDK to create the signature and it all works fine
const { executeAllActions } = await seaport.createOrder(
{
offer: [
{
amount: basePrice.toString(),
token: WETH,
}
],
consideration: [item, ...considerationFeeItems],
endTime: endTime.toString(),
zone: DEFAULT_ZONE_BY_NETWORK[opensea.Network.Main],
restrictedByZone: true,
allowPartialFills: false,
conduitKey: CROSS_CHAIN_DEFAULT_CONDUIT_KEY,
counter: 0
},
ourAddress
);
const order = await executeAllActions();
But as soon as I send it to that endpoint https://docs.opensea.io/v2.0/reference/create-an-offer
it gives me back an error.
The order object returned from executeAllActions looks like following:
{
parameters: {
offerer: '0x...',
zone: '0x004c00500000ad104d7dbd00e3ae0a5c00560c00',
zoneHash: '0x3000000000000000000000000000000000000000000000000000000000000000',
startTime: '1660557986',
endTime: '1660644385',
orderType: 2,
offer: [ [Object] ],
consideration: [ [Object], [Object], [Object] ],
totalOriginalConsiderationItems: 3,
salt: '0xc532bab0fd9ae9529b4d8cfc9fc2f02e',
conduitKey: '0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000',
counter: 0
},
signature: '0x....'
}
What is going wrong?

Sequelize findAll not returning expected output on sequelize-mock

I'm trying to do unit testing on my nodejs-express method with sequelize-mock.
Controller
const getDetailsByUserId = async (id) => {
try {
const userId = id ?? 0;
const details = await Model.findAll(
{
raw: true,
where: { user_id: userId }
}
);
if (details && details .length > 0) {
return {
status: 200,
success: true,
message: 'details found.',
data: details
}
}
return {
status: 404,
success: false,
message: 'details not found',
data: []
}
} catch (error) {
return {
status: 500,
success: false,
message: error.message || "An error occurred while getting details.",
data: null
}
}
}
Test
jest.mock('../models/details', () => () => {
const SequelizeMock = require("sequelize-mock");
const dbMock = new SequelizeMock();
return dbMock.define('users', [
{
id: 1,
user_id: 123
name: 'John Doe 1'
},
{
id: 2,
user_id: 456
name: 'John Doe 2'
},
{
id: 3,
user_id: 789
name: 'John Doe 3'
}
]);
});
test('should return 404 and an empty array', async () => {
const userId = 147;
const details = await controller.getDetailsByUserId(userId);
expect(details.status).toEqual(404);
});
I always get the status of 200 instead of 404 here. I checked the returned data and it's returning the records of the defined mocked model.
Actual Result:
[
fakeModelInstance {
options: {
timestamps: true,
paranoid: undefined,
createdAt: undefined,
updatedAt: undefined,
deletedAt: undefined,
isNewRecord: true
},
_values: {
'0': [Object],
'1': [Object],
'2': [Object],
user_id: 147,
id: 1,
createdAt: 2021-09-18T00:55:25.976Z,
updatedAt: 2021-09-18T00:55:25.976Z
},
dataValues: {
'0': [Object],
'1': [Object],
'2': [Object],
user_id: 147,
id: 1,
createdAt: 2021-09-18T00:55:25.976Z,
updatedAt: 2021-09-18T00:55:25.976Z
},
hasPrimaryKeys: true,
__validationErrors: []
}
]
QUESTIONS:
Is there something I can do to get the expected result (empty array) for this scenario?
the raw: true seems to be not working when it is mocked. Is there a way could log the result on raw object?
NOTE: This only happens on the unit testing. When accessing the endpoint on postman it returns the expected result.
According to the docs, findAll() will always return an array of a single result based on the where query in the options. This is why you will never get an empty array.
See more: https://sequelize-mock.readthedocs.io/en/stable/api/model/#findalloptions-promisearrayinstance

Failed to construct 'PaymentRequest': Iterator getter is not callable

I'm following a tutorial about new PaymentRequest API but I get an error:
Uncaught TypeError: Failed to construct 'PaymentRequest': Iterator
getter is not callable.
at startPayment ((index):45)
function startPayment(){
if (!window.PaymentRequest) {
// PaymentRequest API is not available. Forwarding to
// legacy form based experience.
location.href = '/checkout';
return;
}
const methods = {
supportedMethods: "basic-card",
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
},
}
const details = {
total: {
label: 'Tyle musisz zabulić',
amount: { currency: 'PLN', value : '22.15' }
},
displayItems: [{
label: 'Narkotyki',
amount: { currency: 'PLN', value: '22.15' }
}],
}
const options = {
requestShipping: true,
requestPayerEmail: true,
requestPayerPhone: true,
requestPayerName: true,
shippingType: 'delivery'
};
const request = new PaymentRequest(methods, details, options) // this line fails
request.show().then(response => {
// [process payment]
// send to a PSP etc.
response.complete('success');
});
}
What does it mean and how can I fix it?
MacOS Chrome version: 72.0.3626.121 64bit
payment methods should be an array:
const methods = [
{
supportedMethods: "basic-card",
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
},
}
]

Get Array Of Object On ajax Call success

I will make Ajax call on my Controller action method. I want result of JSON in this format.
// array of all brands
var brands = [
{ brandId: 1, name: "Ford" },
{ brandId: 2, name: "BMW" }
];
for this i will make another call
// array of all models
var models = [
{ modelId: 1, name: "Explorer", brandId: 1},
{ modelId: 2, name: "Focus", brandId: 1},
{ modelId: 3, name: "X3", brandId: 2},
{ modelId: 4, name: "X5", brandId: 2}
];
How can i do that please guide me.
You can use following code to solve your problem
public ActionResult SomeActionMethod(int id)
{
return Json(new {foo="bar", baz="Blech"});
}
Method from the jquery getJSON method by simply...
$.getJSON("../SomeActionMethod", { id: someId },
function(data) {
alert(data.foo);
alert(data.baz);
}
);
To serialize json in your controller, may be you can use http://www.newtonsoft.com/json/help/html/serializingjson.htm

$scope issue with gridOptions, angular-ui-grid and REST call from service

I seem to be having an issue getting my ng-grid directive to populate from a returned REST api json obj.
I have verfied that a valid json obj is returned and i have retrieved a nested obj of the data I need. It seems that it is not making it into the gridOptions function. Where myData is the correct valid json.
Any help will be greatly appreciated. I am pulling my hair out at this point.
Here is my service:
grid-service.js
'use strict';
app.factory('GridService', ['$http', '$q', function($http, $q) {
var apiUrl = "http://xx.xx.xx.xx/coName/public/index.php/";
// configure the send request
function sendRequest(config){
var deferred = $q.defer();
config.then(function(response){
deferred.resolve(response);
}, function(error){
deferred.reject(error);
});
return deferred.promise;
}
// retrieve all
function getRoles() {
var request = $http({
method: 'GET',
url: apiUrl + 'roles'
});
return sendRequest(request);
}
return {
getRoles: getRoles
};
}]);
I inject it into my ctrl here, and my init function and gridOption functions:
app.controller('ModuleCtrl', [ '$scope', '$http', '$modal', '$filter', 'GridService', function($scope, $http, $modal, $filter, gridService) {
var initializeGrid = function(){
getRoles();
};
var getRoles = function(){
gridService.getRoles().then(function(myRoles){
var myRolesData = myRoles.data._embedded.roles;
$scope.myData = myRoles.data._embedded.roles;
console.log($scope.myData);
});
};
$scope.gridOptions = {
data: 'myData',
enableRowSelection: true,
enableCellEditOnFocus: true,
showSelectionCheckbox: true,
selectedItems: $scope.selectedRows,
columnDefs: [{
field: 'ID',
displayName: 'Id',
enableCellEdit: false
}, {
field: 'APP_ID',
displayName: 'Module ID',
enableCellEdit: false
}, {
field: 'RLDESC',
displayName: 'Role Description',
enableCellEdit: true
}, {
field: 'APDESC',
displayName: 'Module Description',
enableCellEdit: true
}, {
field: 'ZEND_DB_ROWNUM',
displayName: 'Record number',
enableCellEdit: false
}]
};
// fire it up
initializeGrid();
}
My complete json:
{
"_links": {
"self": {
"href": "http://xx.xx.xx.xx/coName/public/index.php/roles?page=1"
},
"describedBy": {
"href": "Some Fun Stuff"
},
"first": {
"href": "http://xx.xx.xx.xx/coName/public/index.php/roles"
},
"last": {
"href": "http://xx.xx.xx.xx/coName/public/index.php/roles?page=1"
}
},
"_embedded": {
"roles": [
{
"ID": 1,
"APP_ID": 1,
"RLDESC": "Admin",
"APDESC": "authLive",
"ZEND_DB_ROWNUM": "1"
},
{
"ID": 2,
"APP_ID": 1,
"RLDESC": "User",
"APDESC": "authLive",
"ZEND_DB_ROWNUM": "2"
},
{
"ID": 4,
"APP_ID": 1,
"RLDESC": "SuperUser",
"APDESC": "authLive",
"ZEND_DB_ROWNUM": "3"
}
]
},
"page_count": 1,
"page_size": 25,
"total_items": 3
}
Remove the following line from the gridOptions
data: 'myData'
Then in getRoles() use
$scope.gridOptions.data = myRolesData;
instead of
$scope.myData = myRoles.data._embedded.roles;
(Maybe you need $scope.myData for some other reason than the grid, but if not I think the above is all you need. I have not tested this live, but it should work.)