Closed harry-73 closed 1 month ago
How did you define the schema in createMethod
? Any other info you can provide would be helpful. Thanks.
Sure, it is like that as in the README file:
import { createMethod } from 'meteor/jam:method'; // can import { Methods } from 'meteor/jam:method' instead and use Methods.create if you prefer
export const create = createMethod({
name: 'todos.create',
schema: Todos.schema, // using jam:easy-schema in this example
async run({ text }) {
const todo = {
text,
done: false,
createdAt: new Date(),
authorId: Meteor.userId(), // can also use this.userId instead of Meteor.userId()
}
const todoId = await Todos.insertAsync(todo);
return todoId;
}
});
And the schema is defined:
const schema = {text: String, isPrivate: Optional(Boolean)}
The schema examples in the supported schemas
section of the Readme are there just to illustrate syntax differences.
If you use jam:easy-schema
, then your schema would need to look like this:
const schema = {
_id: String,
text: String,
done: Boolean,
createdAt: Date,
authorId: String,
}
This also assumes you're using Meteor-generated _id
s (not Mongo.ObjectIds
)
Sorry, I mixed up different things...
you can find a repo with the reproduction: https://github.com/harry-73/jam-method-meteor
I use jam:easy-schema package also.
I got the following error:
{
"isClientSafe": true,
"error": "validation-error",
"reason": "Validation failed",
"details": [
{
"name": "text",
"type": "condition",
"message": "Text Unknown key"
}
],
"message": "Validation failed [validation-error]",
"errorType": "Meteor.Error"
}
Thanks for the repo. You found an interesting issue when using vite
. I've addressed it in jam:easy-schema
v1.3.3
.
I confirm, v1.3.3
fixes the issue.
I have just tried to use the example in the README file but I get this error.