我正在使用MEAN堆栈构建应用程序。我有一个可以通过单击事件选择的高尔夫球手列表。一旦用户单击高尔夫球手,高尔夫球手便被推到该用户选择阵列。 该功能适用于从列表中选择的前5或6个播放器,然后后端停止响应任何将来的选择。 UI继续按预期工作。
golfers.component.ts
draftGolfer(g) {
// front end logic
this.postGolfer(g, this.users[i])
}
postGolfer(golfer, user){
this.post.postToDB(golfer, user).subscribe(data => {
console.log(data)
});
}
post-service.ts
postToDB(golfer, user){
let payload = {
user: user,
golfer: golfer
}
return this.http.post("http://localhost:3010/post", payload)
.pipe(
tap(_ => this.log()),
catchError(this.handleError('addGolferUser'))
)
}
posts.js
router.post("", (req, res) => {
Register.findOneAndUpdate({username: req.body["user"]["username"]},
{$push: {picks: req.body["golfer"]}},
function (error, success) {
if (error) {
console.log("ERRRORRRR");
} else {
console.log(`success: ${req.body.golfer.Name}`);
}
});
})
Model.js
const registerSchema = new Schema({
username: {type: String},
password: {type: String},
picks: [],
active: {type: Boolean}
});