|
|
@@ -39,6 +39,7 @@ open class TeamService( |
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun saveTeam(req: NewTeamRequest): Team { |
|
|
|
val ids = req.addStaffIds!! |
|
|
|
println(ids) |
|
|
|
val teamLead = staffRepository.findById(ids[0]).orElseThrow() |
|
|
|
val teamName = "Team " + teamLead.name |
|
|
|
|
|
|
@@ -46,6 +47,7 @@ open class TeamService( |
|
|
|
val teamCode = initials.joinToString("") |
|
|
|
|
|
|
|
val team = Team().apply { |
|
|
|
this.staff = teamLead |
|
|
|
name = teamName |
|
|
|
code = teamCode |
|
|
|
description = req.description |
|
|
@@ -88,7 +90,15 @@ open class TeamService( |
|
|
|
code = teamCode |
|
|
|
description = req.description |
|
|
|
} |
|
|
|
// println(!req.deleteStaffIds.isNullOrEmpty()) |
|
|
|
|
|
|
|
for (id in addIds) { |
|
|
|
val staff = staffRepository.findById(id.toLong()).orElseThrow() |
|
|
|
staff.apply { |
|
|
|
this.team = team |
|
|
|
} |
|
|
|
staffRepository.save(staff) |
|
|
|
} |
|
|
|
|
|
|
|
if (!req.deleteStaffIds.isNullOrEmpty()) { |
|
|
|
for (id in req.deleteStaffIds) { |
|
|
|
val staff = staffRepository.findById(id).orElseThrow() |
|
|
@@ -99,13 +109,6 @@ open class TeamService( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (id in addIds) { |
|
|
|
val staff = staffRepository.findById(id.toLong()).orElseThrow() |
|
|
|
staff.apply { |
|
|
|
this.team = team |
|
|
|
} |
|
|
|
staffRepository.save(staff) |
|
|
|
} |
|
|
|
return team |
|
|
|
} |
|
|
|
|
|
|
|