Magical Import using two mappedKeyName for relationship - magicalrecord

I have Team model and Player model
So When I create Player I have response that return me this:
"palyer":
{
teamID = 10
...
I have the next setting in xcdatamodel for Player.team relationship
mappedKeyName - player.teamID
mappedKeyName.1 - teamID
relatedByAttribute - teamID
mappedKeyName.1 I am using because when I request player list api it return me
{
teamID = 10,
...
},
{
teamID = 11,
}
...
so then I am using MR_importFromArray for Player entities.
but seems magical import won't work in the second case. I have checked response and it return me teamID for each request.
I have noticed that it works only with one mappedKeyName
Or maybe I confused about goals of mapped keys?

This was a bug in MagicalRecord 2.2 and earlier. It is fixed in the upcoming 2.3 release.

Related

DynamoDB PartiQL pagination using SDK

I'm currently working on pagination in DynamoDB using the JS AWS-SDK's executeStatement using PartiQL, but my returned object does not contain a NextToken (only the Items array), which is used to paginate.
This is what the code looks like (pretty simple):
const statement = `SELECT "user", "id" FROM "TABLE-X" WHERE "activity" = 'XXXX'`;
const params = {Statement: statement};
try {
const posted = await dynamodb.executeStatement(params).promise();
return { posted: posted };
} catch(err) {
throw new Error(err);
}
I was wondering if anyone has dealt with pagination using PartiQL for DynamoDB.
Could this be because my partition key is a string type?
Still trying to figure it out.
Thanks, in advance!
It turns out that if you want a NextToken DO NOT use version 2 of the AWS SDK for JavaScript. Use version 3. Version 3 will always return a NextToken, even if it is undefined.
From there you can figure out your limits, etc (default limit until you actually get a NextToken is 1MB). You'll need to look into the dynamodb v3 execute statement method.
You can also look into dynamodb paginators, which I've never used, but plan on studying.

Is there any Microsoft API to get the group Id from channel id?

I have list of channel id of particular group, I want the group Id and name from channel Id.
Is there any such api in Microsoft graph api?
This is not possible with the Graph API. This has been confirmed by Microsoft.
However, when you are working with a channel object and have its id, you usually also have an id of the team it belongs to - for example in the bot framework, it's part of the activity's channelData.
Be prepared not to always have this information, since not all channels of conversations might be Teams channels! But let's assume you're working with Teams channels exclusively.
The id of the team is also the id of its implicitly-generated General channel. You can distinguish that one by the id format 19:…#thread.tacv2 - a normal channel has a hex string whereas the team itself has a longer base62 string and includes a -. Without this id, you're basically lost.
Unfortunately, this team id is still mostly useless. It is not the UUID that you use in the Graph API for the Team resources (at /teams/{team-id}), Channel resources (at /teams/{team-id}/channels/{channel-id}) and Group resources ("Every team is associated with a Microsoft 365 group. The group has the same ID as the team - for example, /groups/{id}/team is the same as /teams/{id}").
Rather, it is the value of the internalId property of the team. It is also the main part of its webUrl. So how to get the groupId/teamId UUID of the team from its internalId string?
The best you can do with the Graph API is to get a list of all teams (either via /groups or via /teams, or at least the teams that you are part of or are otherwise associated with), and then for each team fetch the whole object by id and compare its internalId with the channel id / internal team id that you are looking for.
Unfortunately, /teams?$filter=internalId eq '19%3A…%40thread.tacv2' only gives the response Filter on property 'internalId' is not supported. :-/
However, looking outside of the Graph API, there is the Bot Framework REST API (part of Azure Bot Services), which does provide an undocumented endpoint. I discovered it via this StackOverflow answer, which shows that the Bot Framework SDK for .NET does have a method to fetch this information: FetchTeamDetailsWithHttpMessagesAsync. It takes an internal teamId (which is not distinguished in the documentation) and returns a TeamDetails object which contains an AadGroupId property: "Azure Active Directory (AAD) Group Id for the team." That's the one we want!
And since the code is open-sourced on Github, we can find its implementation:
// Construct URL
var baseUrl = Client.BaseUri.AbsoluteUri;
var url = new System.Uri(new System.Uri(baseUrl + (baseUrl.EndsWith("/", System.StringComparison.InvariantCulture) ? string.Empty : "/")), "v3/teams/{teamId}").ToString();
url = url.Replace("{teamId}", System.Uri.EscapeDataString(teamId));
This works similar in JavaScript/TypeScript, except the SDK doesn't expose the method itself. Turns out I need to look better, it's available as TeamsInfo.getTeamDetails (working from the current TurnContext) or new Teams(client).fetchTeamDetails. Looking at its implementation, it uses
const fetchTeamDetailsOperationSpec: msRest.OperationSpec = {
httpMethod: 'GET',
path: 'v3/teams/{teamId}',
…
};
I'll leave my custom implementation up for posterity still, it has slightly more accurate types:
const SERVICE_URL = 'https://smba.trafficmanager.net/…/';
async function fetchTeamDetails(teamInternalId: string): Promise<TeamDetails> {
const adapter = new BotFrameworkAdapter({
…
});
const client = adapter.createConnectorClient(SERVICE_URL);
const response = await client.sendRequest({
method: 'GET',
url: `${SERVICE_URL}/v3/teams/${encodeURIComponent(teamInternalId)}`,
});
return response.parsedBody as TeamDetails;
}
/** Details related to a team. Modelled after https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.schema.teams.teamdetails (which is lacking `tenantId` though) */
interface TeamDetails {
/** Unique identifier representing a team. */
id: string;
/** Tenant Id for the team. */
tenantId: string; // UUID
/** Azure Active Directory (AAD) Group Id for the team. */
aadGroupId: string; // UUID
/** type of the team */
type: 'standard' | 'sharedChannel' | 'privateChannel';
/** Name of team. */
name: string;
/** Number of channels in the team. */
channelCount: number;
/** Number of members in the team. */
memberCount: number;
}
Reverse is possible.
If you have Group/team id, can get channels. But no API to get Group id based on Channel id.

Can we use NgRx Data with pagination style REST API response?

I am currently using NgRx Data to perform CRUD operation on couple of entities on my project. Now, I've to develop pagination. Hence, REST API response is going to be like:
{
"page": 1,
"per_page": 10,
"total": 100,
"total_page": 10,
"data": [
{ ... },
{ ... },
{ ... }
]
}
AFAIK, NgRx Data works well with entities, I've no clue how to deal with this. Could you please redirect me to some light? Thank you.
Even I was facing a similar issue. So for people who are new to NgRx data, I have created an EntityDataListInterface which was similar to:
{
page: number,
per_page: number,
total: number,
total_page: number,
data: EntityDataItem[]
}
For each section I am working on I create a different service. Lets call it ComponentService. Inside this ComponentService I access the EntityService(which implements EntityCollectionServiceBase<EntityDataItem>) and entity's DataService (which implements DefaultDataService<EntityDataListInterface>).
Once the API returns EntityDataListInterface data, you can use addManyToCache to add them into the entity cache.
Inside the module, register the EntityDataItem by passing the filterFn. Now you can call setFilter to filter the entities based on indexes(or any pagination logic like shown below) and the result would be accessible via filteredEntities$.
//eds: EntityDefinitionService in the constructor
const entityMetadata: EntityMetadataMap = {
EntityDataItem: {
filterFn:(entities: EntityDataItem[], pattern:{startIndex: number, endIndex: number}) => {
return entities.filter((entity, index) => {
return ((index >= pattern.startIndex) && (index <= pattern.endIndex));
})
}
}
};
eds.registerMetadataMap(entityMetadata);
Subscribe to filteredEntities$ in your component and it will solve the pagination issue.

Google Analytics dimension pagePathLevel more than 4

I have very long web pages paths reported to google analytics:
/#/legends_g01/games/legends_g01_02_academy_i-170909-55/notes/1/dynamics
/#/legends_02_academy_i/games/legends_g01_02_academy_i-170912-64/notes/12/players
/#/legends_05/games/legends_05-170912-84/notes/22/players
/#/legends_g01_02_academy_i/games/legends_g01_02_academy_i-170919-78/notes/34/levels
I'm using Core API to create a query where I need to have a metric ga:users with dimension by the last path part (7th). The starting part of the path doesn't matter here and should be ignored.
So if there is ga:pagePathLevel7 then I can use
dimension: ga:pagePathLevel7
metrics: ga:users
And see the result like this:
dynamics: 34
players: 45
levels: 87
How can I do this without ga:pagePathLevel7?
It seems that I'm the only one here with such a problem.
As I failed to find a direct solution I ended up adding custom dimensions to my google analytics. I added the dimensions for the last important path parts and changed the code on the site to supply this data together with the pageView url.
import ReactGA from 'react-ga';
export const statDimension = (dimensionName, value) => {
if(value)
{
let obj = {};
obj[dimensionName] = value;
ReactGA.set(obj);
}
};
export const statPageView = (url, game_id, clip_num) => {
if(!url)
{
url = window.location.hash;
}
//set game_id
statDimension(STAT_DIM_GAME_ID, game_id);
//set clip number
statDimension(STAT_DIM_CLIP_NUM, clip_num);
ReactGA.pageview(url);
return null;
};
I use react-ga npm module for submitting data to google analytics.
Now I can use custom dimensions together with filters on my urls to get stats based on the parts of the path with depth > 4.
May be that's not an elegant solution but is a working one.
Hope this will be helpful for somebody like me.

In Sequelize, How do you perform a where query on an association inside of an $or statement?

I have three models, User, Project and ProjectMember. Keeping things simple, the models have the following attributes:
User
- id
Project
- id
- owner_id
- is_published
ProjectMember
- user_id
- project_id
Using sequelize.js, I want to find all projects where the project owner is a specific user, or where there is a project member for that project whose user is that user, or where the project is published. I imagine the raw SQL would look something like this:
SELECT p.*
FROM Project p
LEFT OUTER JOIN ProjectMember m
ON p.id = m.project_id
WHERE m.user_id = 2
OR p.owner_id = 2
OR p.is_published = true;
There are plenty of examples out there on how to perform a query on an association, but I can find none on how to do so conditionally. I have been able to query just the association using this code:
projModel.findAll({
where: { },
include: [{
model: memberModel,
as: 'projectMembers',
where: { 'user_id': 2 }
}]
})
How do I combine this where query in an $or to check the project's owner_id and is_published columns?
It's frustrating, I worked for hours to try to solve this problem, and as soon as I ask here I found a way to do it. As it turns out, sequelize.js developers recently added the ability to use raw keys in your where query, making it (at long last) possible to query an association inside of the main where clause.
This is my solution:
projModel.findAll({
where: {
$or: {
'$projectMembers.user_id$': 2,
owner_id: 2,
is_published: true
}
},
include: [{
model: memberModel,
as: 'projectMembers'
}]
})
Note: this solution breaks if you use 'limit' in the find options. As an alternative, you can fetch all results and then manually limit them afterwards.

Resources