What is the difference between idParam, idProperty and clientIdProperty - extjs

I am curios about the implementations of the idProperty one in the model and one in the reader
and then a idParam for the proxy and a clientIdProperty on the model
How do we I use them in a right way?

if you get this as a response from the server:
{data: [{userid: 1234, username: "foo"}, {userid: 1235, username: "bar"}]}
so in your UserModel you will have idProperty: "userid" this will tell ExtJS which field to use for functions like getId(), getById(). You could also define this in the reader to share between some models, but usually you should define the idProperty in the model.
idParam seems very unclear to me, it is used only 2 time in the whole framework. is only used to modify the request id parameter send to the server. I don't think this is a parameter you will ever need to change.
clientIdProperty is needed for create operations if proxy.batchActions == true. For example: model.clientIdProperty = "extid" this will send to the server if we create 2 users:
{data: [
{extid: "ext-user-1", username: "foo"},
{extid: "ext-user-2", username: "bar"}
]}
server response:
{data: [
{extid: "ext-user-1", userid: 1234, username: "foo"},
{extid: "ext-user-2", userid: 1235, username: "bar"}
]}
this will tell ExtJS how to map the server ids to the pre-generated ext ids.
(if clientIdProperty is null, ExtJS assumes the same order of request and response for the mapping)

Related

Updating model with GraphQL Mutation

I have been having trouble figuring out how to update a User with graphQL. The functionality I'm currently aiming for is for the user to be able to update their account/profile information. I have some things set up for the user like a bio field for their profile, and a profile picture field that's set up to take a URL and display that as their profile picture.
I have no problems when it comes to creating using graphQL. A user can sign up, log in, make posts, etc without issue. I can also update the User in regards to other models, for example, a new post pushes to the users Post data just fine.
I have not been able to figure out how to update a user directly though. Essentially I can get around this by creating a new model for "profile pic" and pushing that to the User, but that seems like it's just extra steps that might slow things down, as well as shortchanging myself being able to learn something new.
This is the User model. I have omitted a few fields due to the exact block of code being large, but this includes the "image" and "bio" fields (the fields I would like to update) as well as the reference to the Post model which I mentioned above that functions appropriately.
User.js
const userSchema = new Schema(
{
username: {
type: String,
required: true,
unique: true,
trim: true
},
email: {
type: String,
required: true,
unique: true,
match: [/.+#.+\..+/, 'Must match an email address!']
},
password: {
type: String,
required: true,
minlength: 8
},
image: {
type: String
},
bio: {
type: String,
maxLength: 500
},
posts: [
{
type: Schema.Types.ObjectId,
ref: 'Post'
}
],
},
Below is the mutation in Explorer, including the variables and the result.
Profile Pic Resolver
addProfilePic: async (parent, { image }, context) => {
if (context.user) {
const updatedUser = await User.findOneAndUpdate(
{ _id: context.user._id },
{ image: image },
{ new: true, runValidators: true }
);
return updatedUser;
}
throw new AuthenticationError('You need to be logged in!');
},
typeDefs.js (relevant only)
type Mutation {
addProfilePic(_id: ID!, image: String!): Auth
}
I notice that in the Explorer page it returns "null" for user with a 200 status. I am led to believe that means that it's not able to even access the "image" field on the user to be able to update it. When compared to my other mutations in regards to users, this is set up very similarly and I'm not sure what the difference is.
I feel like I am missing something very basic here in regards to being able to update. I haven't been able to find an update mutation example that works. Could anyone assist? My main questions would be:
Why does the mutation return "null" for user?
How can I set up my resolver to appropriately update information on an already-created object?
Thank you to anyone who is able to take a look and assist, I will be closely watching this post for replies and will update any other code someone may need to be able to assist. I've been stuck in regards to updating information for a long time, but my site is getting to the point where it's nearly ready and I need to tackle this updating issue in order to progress. Thank you!
Quick Edit: I want to add that "Auth" is referenced. The appropriate authorization headers are in place to retrieve the data. Just wanted to add that in as I highly doubt authorization has anything to do with this!
I have solved this issue and would like to leave the answer here for anyone who may find it useful.
In the mutation typeDefs, I changed the "Auth" to "User",
type Mutation {
addProfilePic(_id: ID!, image: String!): User
}
and then in the mutation itself, took away the user field like such:
mutation addProfilePic($_id: ID!, $image: String!) {
addProfilePic(_id: $_id, image: $image) {
_id
username
image
}
}
This has allowed the user to update their profile photo information. Hope this helps!

Posting to mongoDb with ObjectId Many to one relationship

Mongoose/MongoDB Question
I have an Owners model containing basic profile data.
I have a secondary model: OwnersImages
e.g
{
owner: {
type: Schema.Types.ObjectId,
ref: 'Owners'
},
name: String,
imageUrl: String,
},
);
From the client I want to post the imageUrl and the name to the OwnersImages table.
e.g
let values = {
owner: this.state.user._id,
name: this.state.field,
imageUrl: this.state.url
}
axios.post(`${serverPath}/api/addFieldImage`, values)
However Im unsure how best to go about this, link it etc.
I can do a GET request on the Owners table to get the Owner data, but then posting this as part of the values to OwnerImages doesn't successfully link the two tables.
Do i need to just store a string reference to the Owner id in OwnerImages or is there a smarter way of doing this?
Or should I just post the string of the user Id to mongoose and then do a map to the Owner table from within there?
Tried to explain this best way I could but the eyes are tired so please ask if any confusion!
Many thanks
Without seeing your exact setup, I think you could modify this to fit your needs:
// In the Schema/Model files
const ownersSchema = Schema({
// other fields above...
images: [{ type: Schema.Types.ObjectId, ref: 'OwnersImages' }]
});
const ownersImagesSchema = Schema({
// other fields above...
owner: { type: Schema.Types.ObjectId, ref: 'Owners' },
});
// in the route-handler
Owners.findById(req.body.owner, async (err, owner) => {
const ownersImage = new OwnersImages(req.body);
owner.images.push(ownersImage._id);
await ownersImage.save();
await owner.save();
});
As a side-note, I think the Models generally have singular names, so Owner and OwnerImage. The collection will then automatically take on the plural form. Just food for thought.
When you want to load these, you can link them with populate(). Consider loading all of the OwnersImages associated with an Owners in some route-handler where the /:id param is the Owners id:
Owners
.findOne({ _id: req.params.id })
.populate('images')
.exec(function (err, images) {
if (err) return handleError(err);
// do something with the images...
});

Encrypt all data with nodejs + angularjs + mongoose

I would like to encrypt all the datas that is being saved in mongoose. Do you know some plugins or some moduls, in nodejs, that does this ? And how could i do it efficiently with angularjs in frontend ?
For example : i'm using a chat system, using socket.io. And i store the messages in this model :
var messageSchema = new Schema({
type: {
type: String,
required: false
},
user: {
type: String,
default: '',
trim: true
},
content: {
type: String,
default: '',
trim: true
},
slug: {
type: String,
lowercase: true,
trim: true
},
created: Date,
updated: [Date],
roomCreator: {
type: Schema.ObjectId,
ref: 'Room'
},
});
I want all this data to be encrypted in the most secure way as possible, so nobody should be able to see any of the contents of the messages.
Thanks in advance
There is this:
ChatSafe
Though I am not sure how I feel about it though. It has the ability to use different cipher keys, but it has no inherent way to get keys from one client to the other, which is necessary to decrypt messages (apparently you have to send them a url, which is how other clients get the cipher key). It is cool that it does all the encryption client-side though.
I think I would work this one though: Implement AES Strength Encryption With JavaScript
It shows you how to build a client-side angular based encryption service.
Encrypt everything client side > shoot it to node > save/do whatever > send it to other clients > decrypt client side.

How to add contact from a rails app to salesforce using restforce gem?

I am using restforce gem to connect to salesforce api. I have successfully connected to it and initialised the client using username/password like below
client = Restforce.new :username => 'foo',
:password => 'bar',
:security_token => 'security token',
:client_id => 'client_id',
:client_secret => 'client_secret'
I am able to create Account in saleforce using the command that is given in gem docs
client.create('Account', Name: 'Foobar Inc.')
Now i want to know how to create contacts? I tried
client.create('Contact', Email: 'demo#example.com')
but it returns false.
I tried
client.create!('Contact', Email: 'demo#example.com')
which showed me the error that LastName is a required field as specified in the comment.
So the solution is to specify LastName also like shown below:
client.create('Contact', Email: 'demo#example.com', LastName: 'Bar')
Thanks and Happy Coding.

MEAN-stack mongoose, where do functions go?

So I'm fairly new to the mean-stack and I'm using mean.js as a framework.
Using Yeoman I've made a new CRUD module called groups. In a group I want to be able to have an owner, the user who made the group, and a collection of members. According to the mongoose docs I gave the GroupSchema the following structure:
var GroupSchema = new Schema({
name: {
type: String,
default: '',
required: 'Please fill Group name',
trim: true
},
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
members: [{type: Schema.ObjectId, ref: 'Member'}]
});
Now, when a group is created the only member will be the owner. I've got the following app structure:
Project:
- app (server side code)
- controllers
- models
- routes
- public (client side code)
- modules
- groups
-controllers
Where do I put the method to add the current user to a certain group? My best guess is that the controller should take care of that, but is it the server or the client side controller?
I wouldn't set it on the client or trust the client. Your server side create function should ignore members completely and just push the current user onto the members array.

Resources