Calling update method on custom model - backbone.js

I have created a custom model which I plan to use to change a custom field attached to the Contacts record. I have created the SuiteScript file, JavaScript file and Service Controller.
I am not too sure how SCA communicates with the server but I assume that you call the frontend model from the View, which then calls the Service Controller which in turn calls the backend model.
I am able to call the frontend model so I think it is set up correctly, the problem I am having is calling the update function on the backend.
The code below is the part of the frontend model that is called.
updateEmbroidery: function updateEmbroidery(newValue, contactId) {
this.set('id', '56');
this.set('value', newValue);
}
The new values show when the model is logged. Trying this.sync also throws an error.

there is a frontend model and a backend model. the frontend model merely says, "here is the URL of the backend model", which, as you noted, has an intermediary, which is the service controller.
The service controller just says, "call x function for put, get, post", etc, and you have to define "x" in the backend model.
the backend model should contain all the standard SuiteScript 1.0 code needed for your CRUD matrix.

Related

How to call internal APEX methods provided by B2B Commerce for Visualforce using REST request

Our team has a web application developed on top of B2B Commerce for Visualforce, there is a button on Product page, Add to Cart, it will call an Apex remote action method using Javascript when clicking on the button, I checked the network traffic in DevTools, found the following XHR request
the above XHR request should be made with the similar code
CCRZ.CloudCrazeView.addItem(event), there is the doc for the class, https://developer.salesforce.com/docs/atlas.en-us.b2b_commerce_dev_guide.meta/b2b_commerce_dev_guide/ccrz_CloudCrazeView.htm
does it have a REST API for the method in the picture? if yes any documentation or sources for it, so that I can call the method using HTTP REST requests, I mean calling it with curl, python or java remotely instead of Javascript.
the APEX class is ccrz.cc_RemoteActionController and the method is addItem, I know B2B Commerce provides a collection of REST API, REST API Endpoints for B2B Commerce for Visualforce, but this page doesn't include the method.
It's 2 different annotations and developer might have not used both. For Javascript usage it's #AuraEnabled and for being exposed as REST webservice it's #RestResource annotation on whole class + possibly #HttpPost on the method itself.
The problem is that in given class you can have only 1 of each HTTP "verbs" so if the class supports say 3 different buttons, they all would be accepting data as POST - problem. (in a pinch that dev could have done 1 master method inspecting the service url used, the input params and dispatching to right method for processing but it's bit meh...)
But. You should be able to patch that. Inspect cc_RemoteActionController in setup -> apex classes to confirm the method signature (it should be marked global meaning you can call it from apex too).
Create your own class that will act as REST wrapper
#RestResource(urlMapping='/HiStackoverflow/*')
global with sharing class HiStackoverflow{
#HttpPost
global static void addItem(Event e) {
ccrz.cc_RemoteActionController.addItem(e);
}
}

Karma Jasmine AngularJS testing with real HTTP requests

I want to test my code with real API calls (so I can test the API as well, and when I change the API I don't have to change the JS test as well, and a lot more benefits.) instead of the regular $httpBackend.expectPOST('http://api.com/login').response(200).
Essentially, I want to test a ProductsController that expects to be logged in through an AuthService.login() method and receive a list of products through ui-router's resolve feature.
In this case, the login method receives data that needs to be used to gather products.
From the $httpBackend documentation found here: https://docs.angularjs.org/api/ngMockE2E/service/$httpBackend
As opposed to unit-testing, in an end-to-end testing scenario or in scenario when an application is being developed with the real backend api replaced with a mock, it is often desirable for certain category of requests to bypass the mock and issue a real http request (e.g. to fetch templates or static files from the webserver). To configure the backend with this behavior use the passThrough request handler of when instead of respond
So, something like: $httpBackend.whenGET(/.*/).passThrough(); should suffice.

Accessing Session values in Angular.js

I am unable to access the session values which is set by node.js in Angular.js controller. I am using the Express framework. How to resolve it? Here is my code.
app.use(express.cookieParser());
app.use(express.session({
secret: '1234567890QWERTY',
cookie: { httpOnly: false }
}));
//setting the values
cookies.set('username',username);
req.session.username=username;
Presumably you want to do something like show the username in your angular app. As I mentioned in this answer, the hard part to Angular is not thinking about what data the server has, but thinking about data the server should provide to the browser via API.
My general model is to have the angular page start up without any data and have a low-level controller invoke a service (say AuthenticationService or IdentityService) that requests relevant data from the server, e.g. HTTP GET /api/identity. That will return a block of JSON that the page can then store in that low-level controller. Any deeper controller can then access the identity (or whatever) data loaded in that first request.

How to secure Resource or controller route in Laravel and Backbone

I am integrating laravel and backbone. I have routes like
Route::resource('tasks', 'TaskController'); and backbone model uses this route for get, post and put requests. and this route simply displays raw data. I want to hide/secure this link/url so that users can't see raw data.How can I achieve this??
Short answer : you can't.
If your Backbone application can access to something, a user can access to. For your server, backbone requests are exactly like a user requests. In fact, the browser make this requests for both.
You could put a password in your Backbone code to protect the access... but it's useless because the Backbone code is public (it is client side).
The only thing you can do is to put restrictions on what Backbone (or a user) can see. For example, authenticate the user and verify that he is allowed to access data before to send it.
If your Backbone app can access data there is no reason to hide them to your users. It's like if you want to hide the raw html code in a web site, that's senseless !

Setting the JSONP callback function in AngularJS

I'm trying to fetch data from a web API via Angular $resource service. The service exposes JSONP interface, but does not allow setting the callback name. Everything works well, my requests goes out, the data returns, the script is injected and then it fails because the callback function is not defined.
Angular documentation is very sparse on this, but it seems that the default callback function Angular sets up is: JSON_CALLBACK, and there's no info how to change that so that it matches the function returned by the foreign API.
Thanks.
I don't think that there is any provision to override that callback.
$resource is high level Restful api based on $http service.
You can use $http apis which returns http promise object and letting you write your success callback wherein you can process data returned from ajax request.
e.g. http://docs.angularjs.org/api/ng.$http#jsonp

Resources