Not sure how to display this object property in my react app - javascript

I tried console.log(response.sql.sql) but it's returning the following error: Unhandled Rejection (TypeError): Cannot read property 'sql' of undefined.
Following is the JSON.stringify of this same object-
{
"sql":{
"external":false,
"sql":[
],
"timeDimensionAlias":"line_items__created_at_day",
"timeDimensionField":"LineItems.createdAt",
"order":{
},
"cacheKeyQueries":{
},
"preAggregations":[
],
"dataSource":"default",
"aliasNameToMember":{
},
"rollupMatchResults":[
],
"canUseTransformedQuery":{
}
}
}

I am assuming the response takes a while so, at the beginning, sql is undefined.
Try to do:
console.log(response && response.sql && response.sql.sql)

try response.data.sql.sql
From my experience, anything in the response, on client-side can be read via response.data object

Related

Exception when checking if an issue field becomes "In Progress" with workflow

My issue fields have a State and an option called In Progress
So I wrote a Youtrack Workflow that launches a http post to my discord channel when an issue becomes "In Progress".
Here is the JavaScript code for that:
var entities = require('#jetbrains/youtrack-scripting-api/entities');
var http = require('#jetbrains/youtrack-scripting-api/http');
exports.rule = entities.Issue.onChange({
// TODO: give the rule a human-readable title
title: 'Open-discord-channel',
guard: function(ctx) {
return ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress);
},
action: function(ctx) {
var issue = ctx.issue;
var connection = new http.Connection('https://discordapp.com');
connection.addHeader('Content-Type', 'application/json');
var response = connection.postSync('/api/webhooks/123/1DJucC8-vdZR-xxx', [], issue.description);
if (response && response.code === 200) {
issue.addComment(response.response);
}
// TODO: specify what to do when a change is applied to an issue
},
requirements: {
// TODO: add requirements
}
});
When activating this workflow this exception gets thrown:
TypeError: Cannot read property "InProgress" from undefined (open-discord-channel/open-discord-channel#16)
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4198)
org.mozilla.javascript.gen.open_discord_channel_open_discord_channel_2052._c_anonymous_1(open-discord-channel/open-discord-channel:16)
It tells me Cannot read property "InProgress" but in fact return ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress); the value InProgress was suggested by the embedded Youtrack Workflow editor.
Can anybody tell me how I can access the real "In Progress" value to make this code running?
EDIT
tried this
return ctx.issue.fields.becomes(ctx.State.name, "In Progress");
Still gave me an exception
Processing issue COOPR-85:
TypeError: Cannot read property "name" from undefined (open-discord-channel/open-discord-channel#16)
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4198)
org.mozilla.javascript.gen.open_discord_channel_open_discord_channel_2076._c_anonymous_1(open-discord-channel/open-discord-channel:16)
If you want to use the ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress) syntax, add a definition for the 'In Progress' state to the requirements section:
requirements: {
State: {
type: entities.State.fieldType,
InProgress: {
name: 'In Progress'
}
}
}
Alternatively, to avoid the Cannot read property "name" from undefined error, check the State field for null values:
return ctx.issue.fields.State && ctx.issue.fields.becomes(ctx.State.name, "In Progress");
I hope it will be helpful.

error in calling data to view in laravel and vue js

i am trying to show some table data in view using vue js and laravel :
here is what i have tried :
this is comment controller :
public function index()
{
$comment = Comment::Latest()->paginate(10);
return new CommentResource($comment);
}
here is my vue js comment script
export default {
data: function() {
return {
comments: {}
}
},
created() {
this.loadComments();
}
,
methods: {
loadComments(){
axios.get("../api/comment").then(
({ data })=>(this.comments - data.data)
// response => this.comments = response.data
);
},
}
}
and finally the html part of vue html
<div v-for="comment in comments" >
{{ comment.title }}
</div>
the result is this error i get in browser :
[Vue warn]: Error in render: "TypeError: Cannot read property 'title' of undefined"
and here
[Vue warn]: Property or method "comment" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
and
TypeError: Cannot read property 'title' of undefined
btw i am sure that i have this because this is my api that i recice on
http://localhost:8000/api/comment
{"current_page":1,"data":[{"id":1,"title":"asd","body":"asd","user_id":1,"user_email":"asd","status":1,"created_at":null,"updated_at":null}],"first_page_url":"http:\/\/localhost:8000\/api\/comment?page=1","from":1,"last_page":1,"last_page_url":"http:\/\/localhost:8000\/api\/comment?page=1","next_page_url":null,"path":"http:\/\/localhost:8000\/api\/comment","per_page":10,"prev_page_url":null,"to":1,"total":1}
and when i console log this :
axios.get("../api/comment").then(({ data }) => (console.log(data)))
i get this result :
You're already extracting data from the response. So either you use the response object like this :
axios.get("../api/comment").then((response) => (this.comments = response.data.data)));
Or you extract the data property and use it.
axios.get("../api/comment").then(({ data }) => (this.comments = data.data)));
This is because axios returns a response object that has a data property that contains the server response. As your server response also has a data property that you want to use, you want to use response.data.data

node.js Error generating response. TypeError: response.json is not a function

In my node app, I'm trying to return a simple object and getting this error in my console:
Error generating response. TypeError: response.json is not a function
code in my messaging.js file :
module.exports = {
getConfig: function(res) {
getConfig(res);
}
};
function getConfig(response) {
response.json({
enabledForAll: false,
limit: 100
});
};
In main.js
const messaging = require("./modules/messaging.js");
Parse.Cloud.define("getConfig", messaging.getConfig);
Any advice? Thanks
A parse FunctionResponse only has two properties. success and error.
Additionally, the data portion of the define callback has two function inputs, FunctionRequest and FunctionResponse, so you may need something like function(req,res){ res.success();}

Asteroid Oauth loginServiceConfiguration: 'google' of undefined

I've followed the 'naive' implementation in the project README: https://github.com/mondora/asteroid-oauth-mixin
The only difference in my code from the example is changing the arrow function to a traditional for the usage of this.
asteroid.ddp.on("added", ({collection, id, fields}: { collection: string; fields: {}, id: string }) => {
if (collection === "meteor_accounts_loginServiceConfiguration") {
asteroid.loginServiceConfiguration = {
...asteroid.loginServiceConfiguration,
[id]: {
_id: id,
...fields
}
};
}
});
});
asteroid.getServiceConfig = function(providerName: string) { // ts file
return this.loginServiceConfiguration[providerName];
}
When I do asteroid.loginWith('google')
index.ts:50 Uncaught TypeError: Cannot read property 'google' of undefined
On the meteor backend I also installed meteor add accounts-base accounts-google because I assume this is a dependency.
What am I missing? Thanks!
I've tried adding DDP.loginServiceConfiguration = {} before the snippet above which resolves the error but creates a new error.
asteroid-oauth-mixin.js:787 Uncaught TypeError: Cannot read property 'clientId' of undefined
at getOauthClientId (asteroid-oauth-mixin.js:787)
at Object.getOptions (asteroid-oauth-mixin.js:720)
at Asteroid.loginWith (asteroid-oauth-mixin.js:104)
at LoginForm../src/routes/accounts/auth/LoginForm.tsx.LoginForm.handleLoginWithGoogle (
Also when I run meteor mongo should db.meteor_accounts_loginServiceConfiguration.find().count() be 0 ?
I needed to meteor add service-configuration and setup my configure-accounts.js and create a google clientId for the application.
This gets me to the point where I have a popup and can choose which user to auth with. Then I receive a new error about target origin mismatch, but I'm going to close this question as resolved.

Node-ACl throws uhandled rejection error

i am using ACL module in my express application.At the start of the server i define some roles and their permissions using the acl.allow() function.
But it logs in a error saying undefined rejection type.The error vanishes on giving a callback with error param.But i am not very sure about what is throwing the error and how it should be handled.
My snippet code which i am using is :
var aclmodule = new acl(new acl.mongodbBackend(config.db.URL, "accesscontrol_"));
aclmodule.allow([
{
roles:['rolea'],
allows:[
{resources:['a','b'], permissions:['*']}
]
},
{
roles:['roleb','rolec'],
allows:[
{resources:['a'], permissions:['view']}
]
},
{
roles:['rolec'],
allows:[
{resources:['o'], permissions:['view','edit']}
]
}
]);
});
The error logged in console is :
Unhandled rejection TypeError: undefined is not a function
at D:\user\web\myapp-web\node_modules\acl\lib\mongodb-backend.js:119:15
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:607:21
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:246:17
at iterate (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\l
ib\async.js:146:13)
at async.eachSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module
s\async\lib\async.js:162:9)
at _asyncMap (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async
\lib\async.js:245:13)
at Object.mapSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module
s\async\lib\async.js:228:23)
at Object.async.series (D:\myapp\web\myapp-web\node_modules\acl\node_mod
ules\async\lib\async.js:605:19)
at Object.MongoDBBackend.end (D:\myapp\web\myapp-web\node_modules\acl\li
b\mongodb-backend.js:35:11)
at Object.tryCatcher (D:\myapp\web\myapp-web\node_modules\acl\node_modul
es\bluebird\js\main\util.js:26:23)
at Object.ret [as endAsync] (eval at (D:\myapp\web\myapp-web
\node_modules\acl\node_modules\bluebird\js\main\promisify.js:163:12),
Is config.db.URL a string? If so, this is the cause of your errors. The line it is failing on is (in mongodb-backend.js):
self.db.collection(... -- it is saying that .collection() is undefined. (Which would make sense if "self.db" were only a string.)
Node-acl expects a database instance when creating a new mongodbBackend, like it says in the docs -- for example:
mongoose.connection.on('connected', function() {
var myAcl = new acl(new acl.mongodbBackend(mongoose.connection.db));
});

Categories

Resources