loopbackio / loopbackio/loopback-next
error 500 when using an array in post method.
@Sharonee ya está trabajando en esto.
Desde el 19/11/2019.
- Lenguaje dominante
- TypeScript
- Estrellas
- 5.1k
- Forks
- 1.1k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 27
Descripción
Hi guys
Back to the issue why Loopback + MongoDB is not working? another problem I found:
I removed exclude from schema:
async create(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Use_r, { exclude: ['id'] }_),
},
},
})
user: Omit<User, 'id'>,
): Promise<User> {
return this.userRepository.create(user);
}
then I add generated: true and removed required: true from the user model .
@property({
type: 'number',
id: true,
generated: true
})
id: number;
it is looking fine when I used POST method, for one record/document when in add several records it ( array of records )I get:
[{
"email": "nunc.sed@semelit.net",
"password": "571087741"
},
{
"email": "lacus@dui.org",
"password": "346470131"
},
{
"email": "ipsum@aaliquetvel.org",
"password": "243339637"
}]
{
"error": {
"statusCode": 500,
"message": "Internal Server Error"
}
}
Unhandled error in POST /users: 500 TypeError: model.toObject is not a function
at UserRepository.toEntity (D:\apps\test\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:471:39)
at UserRepository.create (D:\apps\test\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:338:17)
But regardless of the error message, it was POSTed all records to MongoDB correctly data with autogenerated id.
Acceptance criteria
- Improve our REST validation to reject Array values for parameters accepting an object - see #4701
- Modify
DefaultCrudRepository.createto reject requests to create multiple model instances in a single call
🎆 Hacktoberfest 2020
Greetings 👋 to all Hacktoberfest 2020 participants!
Here are few tips 👀 to make your start easier, see also #6456:
- Before you start working on this issue, please leave a comment to let others know.
- This issue consists of several tasks to work on, it may feel like a too big effort to undertake. Don't worry! It's perfectly fine to pick just one item from the list and leave the rest for somebody else. In fact, we prefer to have a dedicated pull request for each part, to make it easier for us to review the changes and get the pull request landed faster. Baby steps FTW! Remember, every little helps.
- If you are new to GitHub pull requests, then you can learn about the process in Submitting a pull request to LoopBack 4.
- If this is your first contribution to LoopBack, then please take a look at our Developer guide
- Feel free to ask for help in
#loopback-contributorschannel, you can join our Slack workspace here.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.