update count_groups in project_supervisor

This commit is contained in:
Patryk Drzewiński 2022-06-13 20:03:27 +02:00
parent 0a04a86a00
commit 1470c4f50f
4 changed files with 11 additions and 4 deletions

View File

@ -50,6 +50,13 @@ def create_group(data: dict) -> dict:
# elif result <= 0: # elif result <= 0:
# abort(400, "Can't create new group, project supervisor achieved a limit of groups") # abort(400, "Can't create new group, project supervisor achieved a limit of groups")
project_supervisor = ProjectSupervisor.query.filter_by(id=project_supervisor_id).first()
if project_supervisor is None:
abort(400, "Project Supervisor with id {project_supervisor_id} doesnt exist")
elif project_supervisor.limit_group == project_supervisor.count_groups:
abort(400, "Can't create new group, project supervisor achieved a limit of groups")
group = Group(name=name, project_supervisor_id=project_supervisor_id) group = Group(name=name, project_supervisor_id=project_supervisor_id)
students_without_groups = db.session.query(Student).join(Group, isouter=True) \ students_without_groups = db.session.query(Student).join(Group, isouter=True) \
@ -59,6 +66,7 @@ def create_group(data: dict) -> dict:
abort(400, "One or more students have already belonged to group!") abort(400, "One or more students have already belonged to group!")
students = db.session.query(Student).filter(Student.index.in_(students_indexes)).all() students = db.session.query(Student).filter(Student.index.in_(students_indexes)).all()
project_supervisor.count_groups += 1
for student in students: for student in students:
student.group_id = group.id student.group_id = group.id

View File

@ -13,7 +13,7 @@ export interface Leader {
last_name: string last_name: string
email: string email: string
limit_group: number limit_group: number
count_group: number count_groups: number
mode: number mode: number
} }

View File

@ -41,7 +41,6 @@ const AddGroup = () => {
data.project_supervisor_id = data.project_supervisor_id.value data.project_supervisor_id = data.project_supervisor_id.value
data.students = data.students.map((st: any) => st.value) data.students = data.students.map((st: any) => st.value)
mutateCreateGroup(data) mutateCreateGroup(data)
console.log(data)
} }
const [studentOptions, setStudentOptions] = useState<SelectValue[]>([]) const [studentOptions, setStudentOptions] = useState<SelectValue[]>([])

View File

@ -80,13 +80,13 @@ const Leaders = () => {
</thead> </thead>
<tbody className="divide-y divide-gray-100"> <tbody className="divide-y divide-gray-100">
{leaders?.data?.project_supervisors {leaders?.data?.project_supervisors
.map(({ id, first_name, last_name, email, limit_group, count_group, mode }) => ( .map(({ id, first_name, last_name, email, limit_group, count_groups, mode }) => (
<tr key={id}> <tr key={id}>
<td>{first_name}</td> <td>{first_name}</td>
<td>{last_name}</td> <td>{last_name}</td>
<td>{email}</td> <td>{email}</td>
<td>{limit_group}</td> <td>{limit_group}</td>
<td>{count_group}</td> <td>{count_groups}</td>
<td>{mode==0 ? "Stacjonarny" : mode==1 ? "Niestacjonarny" : "Nie/stacjonarny"}</td> <td>{mode==0 ? "Stacjonarny" : mode==1 ? "Niestacjonarny" : "Nie/stacjonarny"}</td>
<td><button onClick={() => deleteLeader(id).then(() => refetchLeaders())}>X</button></td> <td><button onClick={() => deleteLeader(id).then(() => refetchLeaders())}>X</button></td>
</tr> </tr>