I am trying do find what is the problem with my code below, I am using the plugin Tedious (SQL Server), sequelize and NodeJs:
exports.getCreditsGeneral = function(sgecode) {
return sequelize.query('[dbo].[SP_ListaCreditos](:sgecode1)',
{ replacements:{sgecode1: sgecode}})
.then(total => {
return total.length ? total : 0
})
}
Can someone help me please?
Thanks.
you are missing exec parameter
exports.getCreditsGeneral = function(sgecode) {
return sequelize.query('exec [dbo].[SP_ListaCreditos](:sgecode1)',
{ replacements:{sgecode1: sgecode}})
.then(total => {
return total.length ? total : 0
})
}
Related
why eslint throw error ( no-unused-expression ). I simply want to check if array is empty or not, and execute dispatch.
useEffect(() => {
let totalPrice = 0;
// eslint-disable-next-line no-unused-expressions
cart.length
? cart.forEach((item: AsideItemInterface) => {
totalPrice += item.quantity * item.price;
dispatch(setTotal(totalPrice));
})
: dispatch(setTotal(0));
}, [cart]);
If, I remove eslint-disable-next-line, get error.
The problem is you're writing an expression that has a value result, but you're not using that result. More specifically, you're using the ? : operators like an if statement. The solution is to write the if statement that you're actually using (i.e if (cart.length) { ... } else { ... }).
I am trying to get a text from an element with Cypress in the first test from the first domain and then type it in the second test in another domain, here is a code
I have to grab code from h4.
I implemented next part of code:
get studentCouponValue() {
return cy.get('h4').then(($span) => {
const couponValue = $span.text();
cy.log(couponValue);
})
}
in logs, I see the correct coupon's value, but when I am trying to type it into the field I get an error
The chain approach doesn't fit my expectation, cause i am going to use it in different tests.
Try this:
get studentCouponValue() {
return cy.get('h4').then(($span) => {
const couponValue = $span.innerText;
cy.log(couponValue);
})
}
i resolved
initStudentCouponValue() {
const self = this;
return cy.get('main > .container-fluid').find('h4').then((span) => {
self.couponValue = span.text();
cy.log('First log '+ self.couponValue);
return new Cypress.Promise((resolve) => {
return resolve(self.couponValue);
});
});
}
getStudentCouponValue() {
return this.couponValue;
}
in the test where we want to use value
let couponValue;
admin.initStudentCouponValue().then(() => {
couponValue = admin.getStudentCouponValue()
});
and later we can use
coupoValue
for inputs
I am trying to access a detail page that i have for a list of items in my html(ionic). So when I click on 1 item I need to go on a detail page with information about that specific item. I am using mongo database for the items , the model of the items are : name and ingredients.
I am stuck here and don't know what to do , please help if you have a bit of time , thank you.
My code :
<ion-list *ngFor="let recipe of recipes ; let i = index">
<ion-item>
<ion-label>{{recipe.name}}</ion-label>
</ion-item>
</ion-list>
Request for the database trying to get the id to access the item (I get the
public findByName(id: string) {
return this.http.get<any>(
"http://localhost:9020/:id" + id
);
}
This is what I tried in typescript
this.route.paramMap.subscribe((paramMap) => {
if (!paramMap.has("id")) {
this.navCtrl.navigateBack("/home");
return;
}
this._recipeDetail = this.nutService
.findByName(paramMap.get("id"))
.subscribe((id) => {
this.id = id;
});
});
Also in route module :
{
path: "name/:id",
loadChildren: () =>
import("./r-d/r-d.module").then(
(m) => m.RDPageModule
),
},
But its not working , maybe I don't have the right approach? Can someone please guide me a bit ?
Thank you for your time
this._recipeDetail = this.nutService
.findByName(paramMap.get("id"))
.subscribe((id) => {
this.id = id;
});
You should be expecting your api to return you the recipeDetail.. you are not storing it properly.
this.nutService.findByName(paramMap.get("id"))
.toPromise().then((data) => {
this.recipeDetail = data;
});
And then, you can display your recipeDetail inside your template. I have also changed .subscribe() to .toPromise().then(). This is a better approach to avoid memory leaks in your app.
I'm trying to put a JSON object "Synced" (Which you will see in the code)
This is the code for a function "addServer(userid, serverid)"
The function is being required from another javascript file
db.all(`SELECT * FROM Users WHERE Tag = ? LIMIT 1`, userid, async(error,element) => {
if(element[0].Synced === '') {
var sJSON = {
users:{
[userid]:4,
},
servers:[`${serverid}`]
}
var serverJSON = JSON.stringify(sJSON)
console.log(serverJSON)
} else {
//Else statement not done yet
}
db.run(`UPDATE Users SET Synced = "${serverJSON}" WHERE Tag = "${userid}"`)
})
Solved. Needed to change quoting.
As Dave Newton said, I had to check my quoting. What I did was change my double quotes to single quotes which solved the problem.
Below is my event.
{
"system":{
"cpu":{
"cores":2,
"system":{
"pct":1.1988
},
"user":{
"pct":0.5487
}
}
},
"type":"metricsets"
}
the value of system.cpu.user.pct should be divided by system.cpu.cores and new value should be stored in system.cpu.user.pct.
I tried as mentioned below but it did not work:
ruby {
code => "event.set('system.cpu.user.pct', system.cpu.user.pct / system.cpu.cores)"
}
ruby {
code => "event['system.cpu.user.pct'] = event['system.cpu.user.pct'] / event['system.cpu.cores']"
}
ruby {
code => "event['[system][cpu][user][pct]'] = event['[system][cpu][user][pct]'] / event['[system][cpu][cores]']"
};
This worked:
ruby {
code => "event.set('[system][cpu][user][pct]',
event.get('[system][cpu][user][pct]') / event.get('[system][cpu][cores]'))"
}
You can read more on how it works here.