|
|
@@ -49,8 +49,8 @@ open class TeamService( |
|
|
|
|
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun updateTeam(req: NewTeamRequest, team: Team): Team { |
|
|
|
val ids = req.addStaffIds |
|
|
|
val teamLead = staffRepository.findById(ids[0]).orElseThrow() |
|
|
|
val addIds = req.addStaffIds |
|
|
|
val teamLead = staffRepository.findById(addIds[0]).orElseThrow() |
|
|
|
val teamName = "Team " + teamLead.name |
|
|
|
|
|
|
|
val initials = teamLead.name.split(" ").map { it.first() } |
|
|
@@ -61,8 +61,18 @@ open class TeamService( |
|
|
|
code = teamCode |
|
|
|
description = req.description |
|
|
|
} |
|
|
|
println(!req.deleteStaffIds.isNullOrEmpty()) |
|
|
|
if (!req.deleteStaffIds.isNullOrEmpty()) { |
|
|
|
for (id in req.deleteStaffIds) { |
|
|
|
val staff = staffRepository.findById(id).orElseThrow() |
|
|
|
staff.apply { |
|
|
|
this.team = null |
|
|
|
} |
|
|
|
staffRepository.save(staff) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (id in ids) { |
|
|
|
for (id in addIds) { |
|
|
|
val staff = staffRepository.findById(id).orElseThrow() |
|
|
|
staff.apply { |
|
|
|
this.team = team |
|
|
@@ -73,7 +83,7 @@ open class TeamService( |
|
|
|
} |
|
|
|
|
|
|
|
open fun saveOrUpdate(req: NewTeamRequest): Team { |
|
|
|
val team = if(req.id != null) find(req.id).get() else Team() |
|
|
|
val team = if(req.id != null) find(req.id).get() else Team() |
|
|
|
if (req.id != null) { |
|
|
|
updateTeam(req, team) |
|
|
|
} else { |
|
|
|