loopbackio / loopbackio/loopback-next
error 500 when using an array in post method.
@Sharonee đang làm issue này rồi.
Từ ngày 19/11/2019.
- Ngôn ngữ chính
- TypeScript
- Star
- 5.1k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 27
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.