strongloop loopback id getting sent to the user owning the object - loopbackjs

I have a strongloop app in which I am trying to post some data to my REST APIs and then trying to retrieve it from another user but I am not getting the "id" of that record to the user not owning the object. How do I access the generated "id" from the user not owning the object. There are no ACLs in my model file
I am expecting the generated unique user identifiers to be returned along with the json response, for example if I make a request like this -
http://localhost:80/api/tuitions?access_token=qvpvtsbWOLZYydUDcbO0VP6YrlfHhbURHpkvPjnUyU9wRHpclAyJh44RKJ6VU36x
the output is -
[
{
"area": [
"901"
],
"city": "9",
"class": "9",
"subjects": [
"902"
],
"userId": "5696915dec62196433db7950",
"created": "2016-01-14T18:40:07.761Z",
"updated": "2016-01-14T18:40:07.761Z",
"identifier": "5697eb8767e585347755c23b"
}
]
in my loopback explorer and my loopback tuition model file defines identifier as -
{
"name": "tuition",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
// ...
"identifier": {
"type": "string",
"id": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
But when I make the same request with my Angular App in my controller with something like -
Tuition.find({
filter: {
order: 'created DESC'
}
}).$promise;
I get this -
[{"area":["901"],"city":"9","class":"9","subjects":["902"],"userId":"5696915dec62196433db7950","created":"2016-01-14T18:40:07.761Z","updated":"2016-01-14T18:40:07.761Z"}]
which does not have identifier

Related

Ember 4.1. Django rest json api. Access field choices from OPTIONS request in Ember data model or elsewhere

My DRF JSON API backend responds with a JSON on OPTIONS request.
The OPTIONS response includes field choices declared on Django model.
On my frontend, in my Ember 4.1 app with default JSONApiAdapter I want to use these exact same choices on my form select. Is there a way to access these choices on my Ember model or somewhere else? and if so, How do I do it?
Here's an example OPTIONS response:
{
"data": {
"name": "Names List",
"description": "API endpoint for Names",
"renders": [
"application/vnd.api+json",
"text/html"
],
"parses": [
"application/vnd.api+json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"allowed_methods": [
"GET",
"POST",
"HEAD",
"OPTIONS"
],
"actions": {
"POST": {
"name": {
"type": "String",
"required": true,
"read_only": false,
"write_only": false,
"label": "Name",
"help_text": "name",
"max_length": 255
},
"name-type": {
"type": "Choice",
"required": true,
"read_only": false,
"write_only": false,
"label": "Name type",
"help_text": "Name type",
"choices": [
{
"value": "S",
"display_name": "Short"
},
{
"value": "L",
"display_name": "Long"
]
}
}
}
}
}

Google People API detect merged contacts with syncToken - previousResourceNames not included

I am using the people API to allow users to create entities in my system from their google contacts, via the people API, and am storing the resourceName (i.e 'people/c7760106965272617307') to keep track of the google contact the entity was created from.
I want to be able periodically update the entities to match what is in google. i.e. if the contact updates the phone number the entity gets the updated phone number. So am a calling the list API passing the sync token to get the contacts that have changed since the last call. This works for updates, edits and deletes but I can't find a way to detect when two contacts have been merged in google contacts.
The docs state:
https://developers.google.com/people/api/rest/v1/people#Person.PersonMetadata
previousResourceNames[] Any former resource names this person has had.
Populated only for connections.list requests that include a sync
token.
So if I:
- Call the list API requesting a sync token
- Create Contact A and Contact B
- Call the list API passing the sync token, then I get just the two created contacts and a new sync token:
{
"resourceName": "people/c1465347538402693914",
"etag": "%EgcBAj0JPjcuGgQBAgUHIgxab0lZTFBvUU43bz0=",
"metadata": {
"sources": [
{
"type": "CONTACT",
"id": "1455f5d28afc531a",
"etag": "#ZoIYLPoQN7o=",
"updateTime": "2020-02-26T15:35:34.021Z"
}
],
"objectType": "PERSON"
},
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "1455f5d28afc531a"
}
},
"displayName": "Contact A",
"familyName": "A",
"givenName": "Contact",
"displayNameLastFirst": "A, Contact"
}
]
},
{
"resourceName": "people/c4555919836853785218",
"etag": "%EgcBAj0JPjcuGgQBAgUHIgx2WmJHUUtjNTcxQT0=",
"metadata": {
"sources": [
{
"type": "CONTACT",
"id": "3f39e0f40cd35282",
"etag": "#vZbGQKc571A=",
"updateTime": "2020-02-26T15:35:44.056Z"
}
],
"objectType": "PERSON"
},
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "3f39e0f40cd35282"
}
},
"displayName": "Contact B",
"familyName": "B",
"givenName": "Contact",
"displayNameLastFirst": "B, Contact"
}
}
If I then merge the two contacts, and then call the API passing the new sync token i get:
{
"resourceName": "people/c4555919836853785218",
"etag": "%EgcBAj0JPjcuGgQBAgUHIgxqNlFVYnIwaU9vVT0=",
"metadata": {
"sources": [
{
"type": "CONTACT",
"id": "3f39e0f40cd35282"
}
],
"deleted": true,
"objectType": "PERSON"
}
}
So TDLR; I can find out one of the contacts were deleted, but not that it was merged into another contact.
It seems like the previousResourceNames[] field would do exactly what I want, but I can't seem to make it return in the data, either on the try the API function on the docs:
https://developers.google.com/people/api/rest/v1/people.connections/list
or using the below nodjs code:
const service = google.people({version: 'v1', auth: authClient});
const result = await service.people.connections.list({
resourceName: 'people/me',
personFields: 'names,emailAddresses,phoneNumbers,metadata',
//requestSyncToken: true
syncToken: "insert token here"
});
console.info("Google Returned", JSON.stringify(result.data, null, 4));
I wonder if i need to grant extra scopes, or something else in the requested person fields.
Scopes Requested:
'https://www.googleapis.com/auth/contacts',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'

User model giving email validation error in loopback3

I have created a model MyUser based on the User model as follows:
{
"name": "MyUser",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"ownerRelations": true,
"emailVerificationRequired": true,
"hidden": [
"email",
"emailVerified"
],
"properties": {
"firstName": {
"type": "string",
"required": true
},
"lastName": {
"type": "string",
"required": true
},
"email": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "CustomAccessToken",
"polymorphic": {
"foreignKey": "userId",
"discriminator": "principalType"
},
"options": {
"disableInclude": true
}
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "create"
}
],
"methods": {}
}
It works perfectly on my local server. But when I host it on aws ec2, only the first time user is created. Next time even if I give different email id, I get email verification error as follows:
The 'MyUser' instance is not valid. Details:emailEmail already exists (value: undefined).
Now if I delete the 1st record and try to create user, it works. So, only 1st record is getting inserted and post that for any unique email also, I am getting validation error. I am not sure why this is happening.
I was able to figure out the problem. I have kept email as a hidden field. loopback has "prohibitHiddenPropertiesInQuery": true by default which does not allow hidden properties in query. As a result, during user validation, email was ignored in the query in loopback-juggler/lib/validation.js. Upon setting prohibitHiddenPropertiesInQuery to false, it works.
However, I am still not sure why it was working in development mode on my local server. prohibitHiddenPropertiesInQuery is by default true, so it should not have worked in development mode also. If anyone have any answer to this, please do let me know.

I am using loopback 3 and idInjection false is not working

My database is in PostgreSQL.My model defination is as below -
{
"name": "City",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
I am using code below to auto update the tables but when I go to database after running the code below and I check fields, I see id field created with an auto increment. How can I prevent creation of "id" field ?
ds.autoupdate("City", function (er) {
if (er) throw err
});
How can I prevent creation of "id" field?
If you're using a database, you can't. See this issue.
A model without any id properties can only be used without attaching to a database.
Making the name property an Id looks like the only way to use it with a relational database.
"name": {
"type": "string",
"id": 1
}

How to query using numeric id in Loopback

I have a loopback model as
{
"name": "myModel",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"description": "Channel name"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
Now this is connected to a mongodb collection.This collection can have custom id in numeric like 1234 or Mongodb ObjectId when created using loopback.
Now when I query using GET
http://localhost:3000/api/myModel/1234.It is not able to get the object of that id.
I get an error message as
{"status":404,"statusCode":404,"code":"MODEL_NOT_FOUND","message": "Unknown \"myModel\" id \"1234\"}
If my id is alphanumeric like abcd1234 then I dont get this error.Is there a way in loopback to be able to process a numeric id.
The only reference I have is this that suggests to use alphanumeric ids.