A way to preload options in select from http but not using javascript functions Need directly in JSON - angular-formly

If I load this field from query to the server (examples: REST, AJAX, HTTP)
[{
"key": "countries",
"type": "select",
"className": "col-xs-6",
"templateOptions": {
"label": "Countries",
"options": [
{"name": "UK", "id":1},
{"name": "France", "id":2},
{"name": "Japan", "id":3}
],
"valueProp": "id",
"labelProp": "name",
"required":true
}
}]
This JSON is loaded from server like a txt string and I do not want to use functions in options, only a name of a service predefined inside angular which will load the data (key-value format).
I do not know if it is possible that after resolving the promise of the load in the service the list is reflected in the options of the select.
Do you think it is better to create a new type of customize select?
And within the definition of the new type create a controller where receive the data of the default resource from where load the data.
Even it could be a simple URL wi can fill in templateOptions to make it more general and use in the controller for get the data for the options and refresh the select.
Is there an example of this?

just load the data asynchronously in the controller. Something like:
[{
"key": "countries",
"type": "select",
"className": "col-xs-6",
"templateOptions": {
"label": "Countries",
"options": [],
"valueProp": "id",
"labelProp": "name",
"required":true
},
controller: function($scope) {
$.get('whatever').then(function(response) {
$scope.to.options = response;
});
}
}]

Related

How to send more than one cookie in header using Swagger UI?

I'm documenting and API written in Node, using OpenAPI and Swagger UI. The API uses authentication by API keys in cache. I have configured global cookie authentication in my OpenAPI definition. The problem is that it only sends one cookie with the petitions, and I need to send three. When I send the request using Swagger UI, the cookie header is sent using the following format: "cookie1=value; cookie2=value".
I tried to create three global security schemes, one for each cookie I need to send, and I managed to do it, but Swagger UI sends the cookie header using the following format: "cookie1=value&cookie2=value" and it returns an authentication error even with the proper values.
This is the configuration in my swagger.json:
...
"components": {
"securitySchemes": {
"cookieAuth": {
"name": "user",
"type": "apiKey",
"in": "cookie"
}
}
},
"security": [
{
"cookieAuth": []
}
],
...
And this is the second approach I tried:
...
"components": {
"securitySchemes": {
"user": {
"name": "user",
"type": "apiKey",
"in": "cookie"
},
"password": {
"name": "user",
"type": "apiKey",
"in": "cookie"
},
"hashFunc": {
"name": "user",
"type": "apiKey",
"in": "cookie"
}
}
},
"security": [
{
"user": [],
"password": [],
"hashFunc": []
}
],
...
What I really need is to know how to configure this so that Swagger UI will interpret it in the same format as the browser.
It's a known issue with Swagger UI:
https://github.com/swagger-api/swagger-ui/issues/4218
You can try using another doc renderer and see if it can handle cookies properly.

Include query results in application insights alert to webhook

I try to setup an application insights alert to a webhook (MS Teams to be precise). I already successfully managed to create the alert and the data is already sent to the webhook and displayed in Teams.
This is a log-alert.
All I am now missing is the query-RESULT of that log-alert.
The documentation [https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-log-webhook#log-alert-with-a-custom-json-payload] simply states that I need to add a simple configuration-parameter into the payload:
"IncludeSearchResults":true
Which I did. But still no Json-Attachment (or anything else) to be seen containing the query result.
My complete payload (which works fine apart from the result-part) looks like this:
{
"#context": "http://schema.org/extensions",
"#type": "MessageCard",
"IncludeSearchResults":true,
"themeColor": "CC4216",
"title": "#alertrulename",
"text": "#alertrulename returned #searchresultcount records which exceeds the threshold of #thresholdvalue .",
"summary": "Query: #searchquery",
"potentialAction": [{
"#type": "OpenUri",
"name": "See details in AppInsights",
"targets": [{
"os": "default",
"uri": "#linktosearchresults"
}]
}],
"sections": [{
"facts": [{
"name": "Severity:",
"value": "#severity"
},
{
"name": "Query:",
"value": "#searchquery"
},
{
"name": "ResultCount:",
"value": "#searchresultcount"
},
{
"name": "Search Interval StartTime:",
"value": "#searchintervalstarttimeutc"
},
{
"name": "Search Interval End time:",
"value": "#searchintervalendtimeutc"
},
{
"name": "AppInsights Application ID:",
"value": "#applicationid"
}]
}]
}
What I want to achieve is that the "top 10 results" that are automatically added to any email-notification also be shown in Teams:
O365 connector card schema does not contain IncludeSearchResults property.
You will need to fetch the result and then bind the data to card.
Are you able to fetch the results?

uploading multiple files of the same field having diffrent categories using multer

I am using node express and multer for single file uploads which are working fine!
I am new to multer. And I am posting an array something like this:
Array [
Object {
"images": Array [
Object {
"name": "download.jpeg",
"type": "image/jpg",
"uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540asxce%252Fvenuefy/ImageManipulator/a7175dfe-e5b2-4a01-841a-4ef2b6b79778.jpg",
},
Object {
"name": "images (1).jpeg",
"type": "image/jpg",
"uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540asxce%252Fvenuefy/ImageManipulator/9795f940-5b9c-4653-96bd-cb445ff0e735.jpg",
},
],
"title": "Bedroom",
},
Object {
"images": Array [
Object {
"name": "download.jpeg",
"type": "image/jpg",
"uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540asxce%252Fvenuefy/ImageManipulator/a7175dfe-e5b2-4a01-841a-4ef2b6b79778.jpg",
},
Object {
"name": "images (1).jpeg",
"type": "image/jpg",
"uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540asxce%252Fvenuefy/ImageManipulator/9795f940-5b9c-4653-96bd-cb445ff0e735.jpg",
},
],
"title": "Living Room",
},
]
Basically it's a Library field with nested categories "Bedroom" and "Living Room". Each category having their own photos.
Multer only gives options for Fileds and Array. Can anyone please help me understand how can i handle complex uploads like this with multer?
i don't think there is much of a choice here. you should send the nested categories bedroom etc seperately instead of nesting them and then use .field method to specify the path and count. in this way it will be more manageable.
upload.fields([
{
name: 'bedroom',
maxCount: 100,
},
{
name: 'livingRoom',
maxCount: 100,
},
...
]);

Creating a Node.js service for PostgreSQL: a json-patch runner

Having:
Some json-patch objects
A jsonb field in a PostgreSQL database
How to have a node.js code which take as input json-patch objects and which the output is SQL request that apply json-patches to database.
May I have to create this from scratch?
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]
Example of operations to apply to a PostgreSQL jsonb field.

Access Token is not generating when extending User and Access Token Model - Loopback 3

I am new to loopback. So as a part of the learning process, started creating a sample API. Also extended User model as Customer and AccessToken as CustomerAccessToken. But the problem is that access token is not being generated, when we tried to login data that is already send using a POST request.
Response body when login using credentials:
{
"id": "oiMDjErGGVkeSMtnt1SfHzGuERZf6OCId5FUulvir6A04htUbIV656FOBlXn9vDS",
"ttl": 1209600,
"created": "2019-05-09T09:41:05.184Z",
"userId": "5cd3f59594d45186b411bb02"
}
No accessToken is generated. I have removed the inbuilt User and AccessToken model and used extended ones.
model-config.json
{
"CustomerAccessToken": {
"dataSource": "db",
"public": false
}
"Customer": {
"dataSource": "db",
"public": true
}
}
customer.json
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "CustomerAccessToken",
"foreignKey": "userId",
"options": {
"disableInclude": true
}
}
}
customerAccessToken.json
{
"name": "CustomerAccessToken",
"base": "AccessToken",
"properties": {},
"validations": [],
"relations": {
"user": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "userId"
}
},
"acls": [],
"methods": {}
}
One more query: Will login functionality work, when we try to extend User & AccessToken models or Do I need to write login functionality in the customer.js file in order to make it work.
Any help would be really appreciated.
Try to use the DEBUG variable to get more details about the error. from loopback root call
export DEBUG=loopback:security:access-context
npm start
to run the server in the debug mode. Then you can check what exactly is going on - which method is called and why you don't have access.
Probably it's ACL setting: by default, you cannot get users data in loopback, so you may want to add ACL rule to the Customer entity. I suggest to use loopback-cli for that - it's less error-prone. Then you select a model where you want to add a new rule and following the step-by-step instruction. You can read more about ACL here
Do not use CustomerAccessToken unless you want to implement multiple user models.
This is the configuration that works great for me:
model-config.json
{
"User": {
"dataSource": "mysql",
"public": false
},
"AccessToken": {
"dataSource": "mysql",
"public": false,
"relations": {
"Customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "userId"
}
}
},
"Customer": {
"dataSource": "mysql",
"public": true
}
}
server.js
app.use(loopback.token({
model: app.models.accessToken,
currentUserLiteral: 'me'
}))
Customer model must extend the User model:
customer.json
{
"name": "Customer",
"plural": "customers",
"base": "User"
}
In addition to Antonio Trapanis response. If you want to use your own AccessToken model to have to set it in server.js
app.use(loopback.token({
model: app.models.CustomerAccessToken,
}));
I followed this tutorial.
https://youtu.be/Jx39u8IssRg
I received Token in response body when logged in with 'user' through user controller.
I am able to to hit the end points of to-do model by passing that 'token' in the headers as 'Bearer Token'. I used "postman" to hit the to-do end points
( I was unable to insert/attach the received token into the to-do requests of loopback4 app)

Resources