Aurelia TS pulling map from a map - aurelia

I have a Map<string, Map<string, boolean>> defined in my appConfig.json and when I try and get values from the map using .get() I get an error that it is not a function.
This is in my appConfig.json
"rolePermissions" : [
{"name" : "Admin", "value" : [
{"name" : "customerList", "value" : "true"},
{"name" : "customerDetails", "value" : "true"},
{"name" : "addCustomerUser", "value" : "true"},
{"name" : "editCustomer", "value" : "true"},
{"name" : "updateBackend", "value" : "true"},
{"name" : "createCustomer", "value" : "true"},
{"name" : "jobsList", "value" : "true"},
{"name" : "jobsView", "value" : "true"},
{"name" : "jobsEdit", "value" : "true"},
{"name" : "jobsDownload", "value" : "true"},
{"name" : "usersList", "value" : "true"},
{"name" : "usersEdit", "value" : "true"},
{"name" : "usersDelete", "value" : "true"},
{"name" : "usersCreate", "value" : "true"}
]}
and I have set the property in my appConfig.ts as:
public rolePermissions: Map>;
This is how I'm accessing rolePermissions:
let rolePerms = this.appConfig.rolePermissions;
let rolePerm = rolePerms.get("Admin");
When I try and pull the "Admin" value from the map I get an error:
ERROR [app-router] TypeError: rolePerms.get is not a function
at Utils.userRoleAuthorized (utils.ts:29)
at NewCustomer.canActivate (newCustomer.ts:42)
at iterate (index.ts:7)
at processActivatable (index.ts:7)
at CanActivateNextStep.run (index.ts:7)
at next (index.ts:7)
at Object.<anonymous> (shell.ts:58)
at step (vendor-bundle.js:4344)
at Object.next (vendor-bundle.js:4325)
at vendor-bundle.js:4318
at Promise._execute (vendor-bundle.js:824)
at Promise._resolveFromExecutor (vendor-bundle.js:2601)
at new Promise (vendor-bundle.js:2197)
at __awaiter (vendor-bundle.js:4314)
at Object.run (shell.ts:45)
at next (index.ts:7)

EDIT:
I didn't catch that you file is a json, the original post still applies though.
If you cannot convert your rolePermissions to a Map, you'll need to process it like a regular array:
rolePerms.find(x => x.name === "Admin").value
ORIGINAL:
The way you initialize rolePermissions is your problem.
You're actually not creating a Map, but an Array.
Therefore the function get is not available, since get is not a function defined on the array prototype.
Here's how you'd need to do it:
const rolePermissions = new Map<string, Map<string, boolean>>(
[
[
"Admin", new Map<string, boolean>([
["customerList", true],
["customerDetails", true],
["addCustomerUser", true],
["editCustomer", true],
["updateBackend", true],
["createCustomer", true],
["jobsList", true],
["jobsView", true],
["jobsEdit", true],
["jobsDownload", true],
["usersList", true],
["usersEdit", true],
["usersDelete", true],
["usersCreate", true]
])
]
]);

Related

In cloudwatch how to group by key inside a nested json?

For example
[{
"date" : "xx",
"user" : "user1",
"hostname" : "hostname1",
"ostype" : "os1",
"package" : {
"smplepackage" : "v3",
"package2" : "v2",
"package3" : "v5",
"package6" : "v10",
"package5" : "v11",
"package7" : "v2"
}
},
{
"date" : "xx",
"user" : "user2",
"hostname" : "hostname2",
"ostype" : "Mac1",
"package" : {
"smplepackage" : "v1",
"dx-package2" : "v2",
"package4" : "v3",
"package6" : "v4",
"package8" : "v5",
"package7" : "v6"
}
}
]
How can I get the user's count group by package in cloudwatch? I Could not find related examples to group by keys inside nested json.

How can I insert an array of objects into my realm database with react native?

I have a Realm db model as follow :
export const JourneyStateSchema = {
name : JOURNEY_STATE_SCHEMA,
primaryKey: 'lvlNumber',
properties: {
lvlNumber: {type : 'int'},
stateWords: {type : 'data'},
words: {type : 'data'},
answers: {type : 'data'},
hints: {type : 'data?'},
}
};
When I want to insert into that, I get this error :
JourneySchema.stateWords must be of type 'binary', got 'object'
I neet to insert arrays of objects ito that, how can I manage that?
my insert model is as follow:
let model = {
lvlNumber : this.lvlNumber,
stateWords : this.state.words,//==>Array of objects
words : this.words,//==>Array of objects
answers : this.answers,//==>Array of objects
hints : this.hints//==>Array of objects
}
insertToJourney(model).then(()=>{
console.log(`inserted ${model} in db`)
}).catch((err)=>{
console.log(err)
})
Also here is a sample of my 'stateWords' data :
stateWords = [
{"value": "china", "solution": "26|36|46|56|66" , "letters" : [
{"letter" : "c" , "find" : false},
{"letter" : "h" , "find" : false},
{"letter" : "i" , "find" : false},
{"letter" : "n" , "find" : false},
{"letter" : "a" , "find" : false},
]},
{"value": "germany", "solution": "23|33|43|53|63|73|83" , "letters" : [
{"letter" : "g" , "find" : false},
{"letter" : "e" , "find" : false},
{"letter" : "r" , "find" : false},
{"letter" : "m" , "find" : false},
{"letter" : "a" , "find" : false},
{"letter" : "n" , "find" : false},
{"letter" : "y" , "find" : false},
]},
{"value": "france", "solution": "35|45|55|65|75|85" , "letters" : [
{"letter" : "f" , "find" : false},
{"letter" : "r" , "find" : false},
{"letter" : "a" , "find" : false},
{"letter" : "n" , "find" : false},
{"letter" : "c" , "find" : false},
{"letter" : "e" , "find" : false},
]}
]
and here is my insertToJourney function :
export const insertToJourney = (item) => new Promise((resolve, reject) => {
Realm.open(databaseOptions).then(realm => {
realm.write(()=>{
realm.create(JOURNEY_STATE_SCHEMA, item);
resolve(item);
})
}).catch((error) => reject(error));
});

Is it possible to use multiple json_object functions under one json_arrayagg function in Oracle?

I need to create JSON that has two sets of json objects under one array. These objects contain aggregated data from several tables. When I use json_arrayagg I get this error:
ORA-02000: missing ) keyword
The code should help explain more of what I've done and what I need.
SELECT JSON_OBJECT(
'rData' VALUE JSON_ARRAYAGG(
JSON_OBJECT(
'datapoints' VALUE JSON_ARRAY(JSON_OBJECT('key' VALUE 'ENM008137Q00190',
'value' VALUE tab3.column_6)),
'datatype' VALUE 'DATA_TYPE',
'id' VALUE tab1.column_4,
'key' VALUE tab3.column_1,
'timestamp' VALUE tab1.column_7),
JSON_OBJECT(
'id' VALUE tab1.column_4,
'key' VALUE tab3.column_1,
'timestamp' VALUE tab1.column_7,
'datatype' VALUE 'DATA_TYPE_2',
'datapoints' VALUE JSON_ARRAYAGG(JSON_OBJECT(
'key' VALUE tab5.column_8,
'value' VALUE tab2.column_9))))RETURNING CLOB)
FROM table_3 tab3,
table_4 tab4,
table_2 tab2,
table_1 tab1,
table_5 tab5
WHERE tab1.column_1 = tab2.column_1
AND tab3.column_2 = tab4.column_2
AND tab3.column_1 = tab2.column_1
AND tab1.column_1 = tab3.column_1
AND tab2.column_3 = tab5.column_3
AND tab2.latenttypeid = 1
AND tab3.column_2 = 2952326910
AND tab2.column_10 = 8878887
AND tab3.column_10 = 8878887
AND tab1.date BETWEEN '19-jun-19'
AND '25-jun-19'
GROUP BY tab1.column_4, tab3.column_1, tab3.column_6, tab1.column_7;
And here is the json output I would like:
{
"rData": [{
"datapoints": [
{"key" : "ENM008137Q00190","value" : "10"}
],
"datatype": "DATA_TYPE",
"id": "H2hnJikUKAhGVzslBVBHqg86DnwGhh8V",
"key": "534421188",
"timestamp": "2019-07-05T05:33:12.000Z"
},
{
"key":"534421188",
"id":"H2hnJikUKAhGVzslBVBHqg86DnwGhh8V" ,
"timestamp": "2019-07-05T05:33:12.000Z",
"datatype": "DATA_TYPE_2",
"datapoints": [
{"key" : "ENM008137L0001","value" : "56.0869029"},
{"key" : "ENM008137L0002","value" : "59.79244788"},
{"key" : "ENM008137L0003","value" : "73.34481183"},
{"key" : "ENM008137L0004","value" : "43.94661396"},
{"key" : "ENM008137L0005","value" : "80.71909567"},
{"key" : "ENM008137L0006","value" : "97.2707082"}
]
},{
"datapoints": [
{"key" : "ENM008137Q00190","value" : "9"}
],
"datatype": "DATA_TYPE",
"id": "A1JnnNjUKAhGVzslBVBHqg86Dnw52Ccj",
"key": "534421164",
"timestamp": "2019-07-05T04:27:45.000Z"
},
{
"key":"534421164",
"id":"A1JnnNjUKAhGVzslBVBHqg86Dnw52Ccj" ,
"timestamp": "2019-07-05T04:27:45.000Z",
"datatype": "DATA_TYPE_2",
"datapoints": [
{"key" : "ENM008137L0001","value" : "88.0869029"},
{"key" : "ENM008137L0002","value" : "88.79244788"},
{"key" : "ENM008137L0003","value" : "88.34481183"},
{"key" : "ENM008137L0004","value" : "82.94661396"},
{"key" : "ENM008137L0005","value" : "99.71909567"},
{"key" : "ENM008137L0006","value" : "88.2707082"}
]
}]
}
There are 2 json_objects under the "rData" array, these are the two data sources that I wanted aggregated, but I'm not sure if that's possible with the current functions.
I apologize for the code, I've tried to give you the least amount of info needed to help with this. And of course any help is always appreciated.

Remove Subdocument items with $pull

I'm trying to remove items from subdocuments using ExpressJS and Mongoose but it is only removing the first items, not the sub items.
So I want to remove "subitem 2" in the messages Array
This is the structure:
{
"_id" : ObjectId("5c4ee94b30ebd71cbed89a35"),
"title" : "Test",
"subitem" : [
{
"_id" : ObjectId("5c4ee95630ebd71cbed89a36"),
"title" : "Item 1",
"messages" : [
{
"_id" : ObjectId("5c4ee95f30ebd71cbed89a37"),
"type" : "single_article",
"date" : "Jan 28, 2019",
"title" : "subitem 1",
"text" : ""
}
]
},
{
"_id" : ObjectId("5c4ee96830ebd71cbed89a38"),
"title" : "item 2",
"messages" : [
{
"_id" : ObjectId("5c4ee96e30ebd71cbed89a39"),
"type" : "single_article",
"date" : "Jan 28, 2019",
"title" : "subitem 2",
"text" : ""
}
]
}
],
"__v" : 0
}
And this is the $pull method:
getController.deleteRec = function(req,res,collection){
var id = req.params.id;
console.log(id);
collection.updateOne({'subitem.messages._id': id}, {$pull: {'subitem.0.messages': {"_id": id}}}).
then(function(result){
console.log(result);
});
};
Now I know why it is only deleting the first item because I have "subitem.0.messages". How can I loop over this, so it can delete all items?
You can use $ as a wildcard index, removing all elements in the array matching your query like this:
{$pull: {'subitem.$.messages': {"_id": id}}}
if you want to remove multiple documents:
{$pull: {'subitem.$.messages': {"_id": {$in : [id, id2, id3...]}}}}

Access Nested Array with Pug

I have the following that is being pulled froma MongoDB and I'm trying to display the "url" and "applications" in pug the data from url is displaying correctly but I'm having trouble accessing the data from "applications"
{
"_id" : ObjectId("5975cdfeb39f71f2fcc2a09d"),
"url" : "http://www.opencolleges.edu.au",
"applications" : [
{
"name" : "AppNexus",
"confidence" : "100",
"version" : "",
"icon" : "AppNexus.svg",
"website" : "http://appnexus.com",
"categories" : [
"Advertising Networks"
]
},
{
"name" : "CloudFlare",
"confidence" : "100",
"version" : "",
"icon" : "CloudFlare.svg",
"website" : "http://www.cloudflare.com",
"categories" : [
"CDN"
]
},
{
"name" : "Crazy Egg",
"confidence" : "100",
"version" : "",
"icon" : "Crazy Egg.png",
"website" : "http://crazyegg.com",
"categories" : [
"Analytics"
]
},
{
"name" : "Google AdSense",
"confidence" : "100",
"version" : "",
"icon" : "Google AdSense.svg",
"website" : "http://google.com/adsense",
"categories" : [
"Advertising Networks"
]
},
{
"name" : "Google Analytics",
"confidence" : "100",
"version" : "UA",
"icon" : "Google Analytics.svg",
"website" : "http://google.com/analytics",
"categories" : [
"Analytics"
]
},
{
"name" : "Google Font API",
"confidence" : "100",
"version" : "",
"icon" : "Google Font API.png",
"website" : "http://google.com/fonts",
"categories" : [
"Font Scripts"
]
},
{
"name" : "Google Tag Manager",
"confidence" : "100",
"version" : "",
"icon" : "Google Tag Manager.png",
"website" : "http://www.google.com/tagmanager",
"categories" : [
"Tag Managers"
]
},
{
"name" : "New Relic",
"confidence" : "100",
"version" : "",
"icon" : "New Relic.png",
"website" : "http://newrelic.com",
"categories" : [
"Analytics"
]
},
{
"name" : "Nginx",
"confidence" : "100",
"version" : "",
"icon" : "Nginx.svg",
"website" : "http://nginx.org/en",
"categories" : [
"Web Servers"
]
},
{
"name" : "Optimizely",
"confidence" : "100",
"version" : "",
"icon" : "Optimizely.png",
"website" : "http://optimizely.com",
"categories" : [
"Analytics"
]
},
{
"name" : "Sizmek",
"confidence" : "100",
"version" : "",
"icon" : "Sizmek.png",
"website" : "http://sizmek.com",
"categories" : [
"Advertising Networks"
]
},
{
"name" : "Twitter Bootstrap",
"confidence" : "100",
"version" : "",
"icon" : "Twitter Bootstrap.png",
"website" : "http://getbootstrap.com",
"categories" : [
"Web Frameworks"
]
},
{
"name" : "VideoJS",
"confidence" : "100",
"version" : "",
"icon" : "VideoJS.png",
"website" : "http://videojs.com",
"categories" : [
"Video Players"
]
},
{
"name" : "jQuery",
"confidence" : "100",
"version" : "",
"icon" : "jQuery.svg",
"website" : "http://jquery.com",
"categories" : [
"JavaScript Frameworks"
]
}
],
"originalUrl" : "http://www.opencolleges.edu.au",
"updatedAt" : ISODate("2017-07-26T23:23:19.756Z"),
"__v" : 0,
"createdAt" : ISODate("2017-07-24T10:37:50.247Z")
}
In the .pug file I use:
ul.list-group
each tech, i in techs
li.list-group-item
h5 #{tech.originalUrl}
h5 #{tech.applications.name}
However the result for tech.applications.name returns null value and when I use tech.applications it returns [Object, Object] is it possible to access this using PUG?