Breezejs SaveChanges: custom nodejs SaveResult - node.js

Is there an example showing the structure of the SaveResult object. I'm working with nodeJS and Mongoose on the back-end; thus I would like to manually construct that object and return it back to breezeJS.

The SaveResult structure is defined in the api docs as the result of the EntityManager.saveChanges method: http://www.breezejs.com/sites/all/apidocs/classes/EntityManager.html#method_saveChanges
Note that the SaveResult structure is actually processed thru the appropriate 'dataService' library (i.e. breeze.dataService.mongo or breeze.dataService.webApi) 'saveChanges' method before being passed onto the EntityManager.

Related

What is the proper way of parsing query parameters using nestJS?

Let's say we make the following GET API call to our REST API running with NestJS (and fastify):
http://localhost:5000/api/test?arrayParam=["abc","def"]&anotherParam="value"
Without parsing anything, the query object on the backend looks like this:
{
arrayParam: '["abc","def"]',
anotherParam: '"value"'
}
We can see that parameter values are strings, but in the case of arrayParam we would obviously like to work with the actual array.
I come from an expressJS background, and coming from there, there are a couple of approaches. First would be just using a JSON parser middleware, like body-parser. Or just using JSON.parse().
But what is the "proper", NestJS approach? I thought about using type decorators defined in a DTO, and assumed they would be automatically parsed to the type that I defined. But that doesn't work like I assumed it would.
I defined it like this:
#IsOptional()
#IsArray()
arrayParam?: string[];
But validation fails, since arrayParam is a string and not an array. So I assume this is not the correct approach
You are sending it incorrectly
http://localhost:5000/api/test?arrayParam[]=abc&arrayParam[]=def&anotherParam

No MessageBodyWriter for Single

I'm trying to use resteasy-rxjava2 to provide an XML document using jaxb, within a vertx application (using a non-vertx legacy library we have). But I get:
Could not find MessageBodyWriter for response object of type:
org.jboss.resteasy.rxjava2.propagation.ContextPropagatorOnSingleAssemblyAction$ContextPropagatorSingle of media type:
application/xml;charset=UTF-8
From what I can tell, this comes down to the difference between a MessageBodyWriter and the AsyncResponseProvider that is in the resteasy-rxjava2 dependency for a Single (SingleProvider).
I have the following resteasy service definition
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
// CHECKSTYLE:OFF too many parameters
public Response getQuery(...)
How do I get resteasy to properly serve the data asynchrously, using the SingleProvider or otherwise.
The #Get method must return the Single explicitly or it doesn't work. (Can't use Response or Object). In my case, the Single contains the jaxb xml root element.
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
public Single<FDSNStationXML> getQuery(...)
Then, to make things more complicated, in order to handle specific exception types and map them to specific response status codes, I have to create a custom ExceptionMapper which creates the Response object I used to be able to create directly in the method. (in resteasy-vertx, I found no documentation on how to do this, but in my case, I am creating my own VertxRestEasyDeployment object so I can register the class of the ExceptionMapper(s) like this:
VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.getActualProviderClasses().addAll(providerClasses);
For reference, this is all being done with:
RestEasy 5.0.3.Final (including resteasy-rxjava2)
RxJava 2.2.20
Vertx 3.9.5

Calling methods with Node/Expressjs

I have a controller that has a method that uses GET to return an object (json format). I want to call it from another controller.
In order to make it easier to understand, let's call the controllers controllerSrc (source) and controllerTgt (target).
First, I import the controller and instantiate the variable of the method.
const controllerSrc = require('controllerSrc')
const controllerSrcGET= controllerSrc.get
In theory, the controllerSrcGET returns a json object, so when I try to do:
console.log(controlerSrcGET._id)
I should have there the id of the object and work arount it. However, I get undefined.
Extra info
I am working with Morgan, and I've noticed that the GET request that should be printed is not. So I'm guessing that it is not enough to instantiate the controllerSrcGET(?)

Why TypeOrm advises to create empty object via `new EntityClass()` THEN only pass fields value?

I'm using NestJS (not Next) NodeJS framework
When I'm creating new objects I used to use new OjbectClass({...fieldsValues});
It's great especially when you use transform pipes from class-transformer;
Besides this approach is used for entity creating:
https://docs.nestjs.com/techniques/database#separating-entity-definition
But as far I see in different guides of TypeOrm usage
here: https://typeorm.io/#/ ,
and here: https://orkhan.gitbook.io/typeorm/docs/entities .
They show first to create an empty object, then only set fields with values:
const object = new EntityObject();
object.field = 'value';
Why? Does it make sense?
Does NodeJS create a redundant hidden class of properties passed via object into Entity Class constructor? If yes - then we can pass coma-separated arguments
I believe it's just cause that's how the docs are. Looking at the code for BaseEntity it does not look like having a constructor to assign the fields would be a problem

How ejs Extract values from object

I am using Sequelize where I fetch all the data from a table using findAll. Which is basically an Array of objects. What seems to be confusing is that the data I am showing as output nested under objects. (Sounds Confusing? Let me clarify)
So, Let's I have this Short Code
Here if I run this code, it will give me undefine because father lies in parent, for which I have to use user.parent.father, Right?
Okay, now on Fetching data from table in my code,
I console.log my first row, for which I get this.
Now here the values which I need lies in dataValues.
In my ejs file. I am using simple for-of loop
Now my Question is why am I not getting undefined for product.title , product.imageUrl and so on? It is supposed to get those data by product.dataValues.title. Because It lies in another object names dataValues.
Technically, when a value is initialized by Sequelize, your object's prototype is set to Model (the class is too long to copy-paste it here).
When you create your model, Sequelize calls init on it (line 424) and which in turn calls refreshAttributes.
This one calls Object.defineProperty to define both the getter and the setter for each property you have defined in the metadata (line 1238).
The getter and setter are set to get and set functions respectively (lines 1095 to 1103).
This actually means that
instance.field
is just a property wrapped over
instance.get('field')
This corresponds with their docs which says
Instance instances operate with the concept of a dataValues property, which stores the actual values represented by the instance. By default, the values from dataValues can also be accessed directly from the Instance, that is:
instance.field
is the same as
instance.get('field')
is the same as
instance.getDataValue('field')

Resources