Improve merge on update
This commit is contained in:
@@ -107,21 +107,17 @@ export class TeamRoutes {
|
||||
}
|
||||
|
||||
let Team = this.db.Team
|
||||
let teamUpdates = null
|
||||
let team = await Team.findById(req.body._id)
|
||||
|
||||
try {
|
||||
teamUpdates = new Team(req.body)
|
||||
} catch (err) {
|
||||
throw createError.BadRequest("Invalid data")
|
||||
if (!team) {
|
||||
throw createError.NotFound(`Team with _id ${req.body_id} was not found`)
|
||||
}
|
||||
|
||||
const foundTeam = await Team.findById(teamUpdates._id)
|
||||
let teamUpdates = new Team(req.body)
|
||||
|
||||
if (!foundTeam) {
|
||||
throw createError.NotFound(`Team with _id ${_id} was not found`)
|
||||
}
|
||||
foundTeam.merge(teamUpdates)
|
||||
const savedTeam = await foundTeam.save()
|
||||
team.merge(teamUpdates)
|
||||
|
||||
const savedTeam = await team.save()
|
||||
|
||||
res.json(savedTeam.toClient())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user