Vuelidate "OR" validator example - vuelidate

OK - searched for quite a while all over and cannot find an example or using the OR validator from Vuelidate. The one mentioned in this github issue is not valid and the issue resolves without providing a valid OR example. The docs mention it exists but do not have any example that we could find. Anyone have or know of an valid example?

If you want a field that take multiple validation types, like signing in with a username or email address, you can do something like this
data () {
return { {
multiusername: '',
}
},
validations: {
multiusername: {
required,
mycustomval: or(email, alphaNum)
}
}

Related

Property 'name' does not exist on type 'string'

I have a list of objects and I need to iterate over the list and add a certain property (string) from the object to a map of <string, boolean>. Here is my code:
this.selectedPeople.forEach(element => {
this.checkedPeople.set(element.name, true);
}
The purpose of this is to set checkboxes to be checked for certain people (if they are in the selectedPeople list) using [checked] in Angular. For some reason, I get this error when trying to build the project:
Property 'name' does not exist on type 'string'
I tried to change element.name to just element and that provides errors during compilation but when I look at the frontend, none of the checkboxes are checked (as you would expect since the key in the map is not a string as required). I have done similar things with other lists and they seem to be working fine, so why is this an issue here?
Edit1: I have seen some other solutions on here but they do not seem to be relevant to my case or have not worked.
Edit2: This is not the actual code as it is company code so I have tried to recreate the issue using a different scenario so as not to run into any confidentiality issues. To elaborate further, the selectedPeople array would be something like this:
[
{
"name":"Paul",
"age":24,
"sport":"Football"
},
{
"name":"Tom",
"age":22,
"sport":"Tennis"
}
]
Edit3: For further clarification, here is what my checkedPeople map looks like:
0: {"Paul" => false}
1: {"Jennifer" => false}
2: {"Georgia" => false}
3: {"Tom" => false}
And I am trying to change the value to true for each person who is in the selectedPeople array.
I tried using element['name'] instead of element.name and that seemed to do the trick. I do not quite understand why this works (especially given that element.name is used elsewhere and works fine) so if anyone has any idea, feel free to comment.
Without seeing your project setup, I'm betting that typescript thinks that element can be a string or an object... something like this:
type SelectedPeople = Array<string | { name: string }>
In such as case, you will need to make sure the item is not a string before accessing the name property:
this.selectedPeople.foreach(element => {
if(typeof element === 'string') {
this.checkedPeople.set(element, true);
} else {
this.checkedPeople.set(element.name, true);
}
}
Yes, you can either try what Ryan is suggesting above, or alternatively you can add a safe check before setting each element like so:
this.selectedPeople.forEach(element => {
If (element && element.Name){
this.checkedPeople.set(element.name, true);
}
}

AWS-SDK issue w/ deleteMessageBatch, telling me MissingParameter but I'm not

I'm getting the following message
UnhandledPromiseRejectionWarning: MissingParameter: The request must contain the parameter DeleteMessageBatchRequestEntry.1.Id.
I think I'm following the documentation to a T at AWS-SDK/SQS
I'm using this code
var params = {
Entries: _.map(_.uniqWith(data.Messages,d=>d.MessageId),d=>({
Id: d.MessageId,
ReceiptHandle: d.ReceiptHandle
})),
QueueUrl: xx.QueueUrl
};
await sqs.deleteMessageBatch(params).promise();
This is what params looks like at the time of sending; looks just like the docs if you ask me...
{
Entries: [
{
Id: "83ba1e18-someid",
ReceiptHandle: "AQEB79CDI1Q+blablabla"
}
]
QueueUrl: "https://sqs.us-west-2.amazonaws.com/somequeeuurl"
}
My system:
aws-sdk: "^2.354.0",
MacOS - current
node 8.12.0
UnhandledPromiseRejectionWarning: MissingParameter: The request must contain the parameter DeleteMessageBatchRequestEntry.1.Id.
I just spent a long time looking at this error and debugging my code. What I finally figured out is that it seems to be trying to say that there needs to be at least one DeleteMessageBatchRequestEntry element in the request – there can't be 0. When I refactored our code and added a check to make sure that we wouldn't make a request if there were no entries in the list, this problem went away.
Is it possible that you are actually sending the following in certain situations?
{
Entries: []
QueueUrl: "https://sqs.us-west-2.amazonaws.com/somequeeuurl"
}

Converting a JSON body into a REST URI

can someone please advise how can I convert this JSON body into a REST URI ?
GET api/_search
{
"age":"5",
"aggs" : {
"uniq_gender" : {
"terms" : { "field" : "Gender.keyword" }
}
}
}
You may proceed with one of two options:
Use POST with body
POST api/_search
{
"age":"5",
"aggs" : {
"uniq_gender" : {
"terms" : { "field" : "Gender.keyword" }
}
}
}
It may seem like a hack, but it is simple and frankly it is widely used. Basically from REST perspective it may be considered as resource creation (filter rather than seach might be a better word here).
Use query string with GET.
Something like:
GET api/_search?age=5,field=Gender.keyword
The problem with using query string is that it may be limited. In RFC there is a code for such a case. For example IE browser has such a limit - see details.
Generally speaking if there is no technical problem, readability issue may appear - it is hard to deal with 1000+ symbols string.

Grab data from Yahoo Finance using Meteor Package, some work some do not

I am using the following package for Meteor https://atmospherejs.com/ajbarry/yahoo-finance
I cant seem to get a specified field to work, here is a link that contains a list of all the available fields, however 'j2' and some others I tested don't work, in the sense there is no response in the result object, or no json key pair values.
Heres is my client side code.
Template.stock.rendered = function (){
if ( _.isEmpty(Session.get('ENW.V')) ) {
Meteor.call('getQuote', 'ENW.V', function(err, result) {
Session.set('ENW.V', result['ENW.V']);
console.log(result)
});
}
}
Template.stock.helpers({
stock: function() {
return Session.get('ENW.V');
}
})
Server side Method
Meteor.methods({
getQuote: function( stockname ) {
return YahooFinance.snapshot({symbols: [stockname] , fields:['n','a','b','j2'] });
}
});
Thanks for any Help in Advance. Happy to add any additional info if needed.
Did a test run after commenting out that line and it seems to work fine. Create an issue with the package owner to see if you can have it fixed for the long run.
The package you are using is deliberately excluding those fields. For what reason, I cannot say. For a full list of fields that it is avoiding, look here:
https://github.com/pilwon/node-yahoo-finance/blob/master/lib/index.js#L122

Is it ok to have JSON objects with varying number of attributes?

I am designing an API resonse for my mobile app right now, and response should contain array of operations. Some of them might have all attributes, some may not, see the example:
{
"operations":[
{
"type":"0",
"location":"01"
},
{
"type":"1",
"location":"1234"
"item_id":"",
"item_name":"Item A",
}
]
}
Is that a good way, or should I reconsider my design? I mean the varying number of attribues. Thank you!
Although It will be good for the bandwidth to keep the attributes out of the json string that doesn't have values. But I will suggest you to keep it other way, either send null or empty string "" it will be help at the decoding side
{
"operations":[
{
"type":"0",
"location":"01"
"item_id":null,
"item_name":null,
},
{
"type":"1",
"location":"1234"
"item_id":"",
"item_name":"Item A",
}
]
}
It depends on the code you'll be writing to handle the object :) As long as you write your code to handle missing elements you'll be fine.
Javascript couldn't give a hoot if an object in an array matches the structure of the other objects or not, if that's what you're concerned about.
p.s: Watch those comma's! They cause me more grief than anything else :p IE will break on a trailing comma :(