What's the correct way to send parameters from AngularJS to an Options HTTP API? - angular-routing

What's the right code to talk between an options HTTP API with parameters?
return $http( {
method: 'OPTIONS',
url: apiUrl + '/Options/' + clientID
} ).error( function ( a, b, c, d, e ) {
console.log( 'a, b, c, d, e', a, b, c, d, e );
} );

Try this way
return $http( {
method: 'OPTIONS',
url: apiUrl + '/Options?clientID=' + clientID
} ).error( function ( a, b, c, d, e ) {
console.log( 'err' );
} );

Related

How to save operators in Dart

I want to do something like this in dart.
var z = +
and then put it in another var like this
var x = 5 z 5
And when I did this
var z = +
I get an Error
Expected an identifier.
you can not make variable operators in dart though what you can do is to create a custom variable for the same by doing:
void main() {
var operators = {
'+': (a, b) { return a + b; },
'<': (a, b) { return a < b; },
// ...
};
var op = '+';
var x = operators[op]!(10, 20);
print(x);
}

ICollection<string> ValueComparer results in "Argument types do not match"

Following the Collection of Primitives sample code, I've made my own variation:
public class AttachmentTagsConfiguration : IEntityTypeConfiguration<Attachment>
{
public void Configure(EntityTypeBuilder<Attachment> builder)
{
builder.Property(e => e.Tags).HasConversion(
v => string.Join( ' ', v.Select(x => x.ToLower()).Distinct() ),
v => v.Split( ' ', StringSplitOptions.RemoveEmptyEntries )
.Select( x => x.ToLower() )
.Distinct()
.ToList(),
new ValueComparer<ICollection<string>>(
(c1, c2) => c1.SequenceEqual(c2),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => c.ToList()
)
);
}
}
Tags have no spaces, so we just join them together in the database to create a single string. This is what the schema looks like:
public class Attachment
{
...
public ICollection<string> Tags { get; set; }
}
If I leave the ValueComparer in there, I get the following error when loading a query that has an Attachment:
System.ArgumentException: 'Argument types do not match'
However, if I remove the ValueComparer it works fine. But then I assume change tracking won't work correctly?
I'm not sure what part of the comparer code could lead to an incorrect argument type. None of the records in the database have a NULL value for Tags, so I don't see how there could be any null values.
Attachments is an ancestor class - we have AssetAttachments, InspectionAttachments, UnitAttachments and DefectAttachments. Does this have an impact on the SequenceEqual comparison?
Oh I see! I removed the casts that were in the original code:
public void Configure(EntityTypeBuilder<Attachment> builder)
{
builder.Property( e => e.Tags ).HasConversion(
v => string.Join( ' ', v.Select( x => x.ToLower()).Distinct() ),
v => (ICollection<string>)v.Split( ' ', StringSplitOptions.RemoveEmptyEntries )
.Select( x => x.ToLower() )
.Distinct()
.ToList(),
new ValueComparer<ICollection<string>>(
(c1, c2) => c1.SequenceEqual(c2),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => (ICollection<string>)c.ToList()
)
);
}
Visual Studio was showing me this:
The cast is dimmed on the line highlighted! So I removed it when I shouldn't have!

Linq to Entities - Add a Second Join with Multiple ON conditions

I currently can do a successful join on two tables like this:
var query = db.DepoAccounts
.Join(db.DepoAccountDetails,
t1 => new { t1.INTEG_REF_NO, t1.BASE_DATE },
t2 => new { t2.INTEG_REF_NO, t2.BASE_DATE },
(t1, t2) => new DataCustomerAccountGDWHModel
{
BranchNumber = t1.BR_NO,
BookedBalance = t2.DP_FACE_BAL_VAL_ADJ,
}
);
I can join on a third table like this, in order to get AccountName:
var query = db.DepoAccounts
.Join(db.DepoAccountDetails,
t1 => new { t1.INTEG_REF_NO, t1.BASE_DATE },
t2 => new { t2.INTEG_REF_NO, t2.BASE_DATE },
(t1, t2) => new { t1, t2 })
.Join(db.AccountCodes,
j1 => j1.t2.DP_ACT_CD,
j2 => j2.ACT_CD,
(j1, j2) => new DataCustomerAccountGDWHModel
{
BranchNumber = j1.t1.BR_NO,
BookedBalance = j1.t2.DP_FACE_BAL_VAL_ADJ,
AccountName = j2.ACT_NAME
}
);
Now I want to add two more join conditions to what I just added, and I do this:
var query = db.DepoAccounts
.Join(db.DepoAccountDetails,
t1 => new { t1.INTEG_REF_NO, t1.BASE_DATE },
t2 => new { t2.INTEG_REF_NO, t2.BASE_DATE },
(t1, t2) => new { t1, t2 })
.Join(db.AccountCodes,
j1 => new { j1.t2.DP_ACT_CD, j1.t2.BASE_DATE, j1.t2.BR_NO },
j2 => new { j2.ACT_CD, j2.BASE_DATE, j2.BR_NO },
(j1, j2) => new DataCustomerAccountGDWHModel
{
BranchNumber = j1.t1.BR_NO,
BookedBalance = j1.t2.DP_FACE_BAL_VAL_ADJ,
AccountName = j2.ACT_NAME
}
)
However, this gives me the following compile error: The type arguments for method
'Queryable.Join (IQueryable). etc etc CANNOT BE INFERRED FROM THE USAGE.
Do I just have a syntax problem?

More than 6 providers for ProxyProvider, how?

Until now I used Singleton pattern in my code, but I'm switching to Remi Rousselet’s Provider. And I have a business logic class that depends on 7 others as for now. ProxyProvider allows to use up to 6. How do I implement Provider pattern in this case?
class BlocAuth {
BlocAuth(this.serviceChatFirestore);
ServiceChatFirestore serviceChatFirestore;
var _state = AuthState();
var blocUser = BlocUser();
var user = UserModel();
var blocRouting = BlocRouting();
var blocBrands = BlocBrands();
var blocNotifications = BlocNotifications();
}
ProxyProvider isn't actually fixed to any number of dependency.
ProxyProvider vs ProxyProvider6 is just some syntax sugar. The latter isn't actually needed
For example:
ProxyProvider3<A, B, C, Result>(
builder: (_, a, b, c, previous) {
...
}
)
is strictly equivalent to:
ProxyProvider<A, Result>(
builder: (context, a, previous) {
final b = Provider.of<B>(context);
final c = Provider.of<C>(context);
...
},
)
So you can just do:
ProxyProvider6<A, B, C, D, E, F, Result>(
builder: (context, a, b, c, d, e, f previous) {
final g = Provider.of<G>(context);
...
}
)

Fetch documents only when field values are specified

I need help with writing dynamic queries in mongo shell.
function(a, obj){
db.courseContent.aggregate({$match: {Actor: a, ObjectId: obj}})
}
In the above function, I sometimes do not pass either a or obj.
I want the function to return documents of respective values.
If both a & obj are passed it should return documents matching both a
& obj but not with matching either 'a' or 'obj'
Can someone help me on this?
The $and operator is what you need here, to match on all the submitted values; the query you want will look something like this:
{$match: {$and: [Actor: a, ObjectId: obj]}}
You can dynamically put together a query like that without too much bother, perhaps like this:
function(a, b, c, d, e, f, g, h){
var match = [];
if (a) { match.push( {Alpha: a} ); }
if (b) { match.push( {Bravo: b} ); }
if (c) { match.push( {Charlie: c} ); }
if (d) { match.push( {Delta: d} ); }
if (g) { match.push( {Echo: e} ); }
if (e) { match.push( {Foxtrot: f} ); }
if (f) { match.push( {Gamma: g} ); }
if (h) { match.push( {Hotel: h} ); }
db.courseContent.aggregate([{$match: {$and: match}}])
}
Generic code which might work for you
function(valuearray,keyarray){
var and={};
and.$and=[];
var obj={};
for(var i=0;i<valuearray.length;i++){
if(valuearray[i]!=undefined && valuearray[i]!=''){
obj[keyarray[i]]=valuearray[i];
and.$and.push(obj);
}
}
db.courseContent.aggregate({$match:and});
}
Try This:
function(a, obj){
if(a!='' && a!=undefined && obj!='' && obj!=undefined){
db.courseContent.aggregate({$match:{$and:[{Actor: a, ObjectId: obj}]}});
}
else if(a!='' && a!=undefined){
var obj={};
var $match={};
var finalobj={};
finalobj["Actor"]=a;
obj["$match"]=finalobj;
db.courseContent.aggregate(obj);
}
else if(obj!='' && obj!=undefined){
var obj={};
var $match={};
var finalobj={};
finalobj["ObjectId"]=obj;
obj["$match"]=finalobj;
db.courseContent.aggregate(obj);
}
}