fix endpoint of create exam enrollments - fix overwriting exam dates
This commit is contained in:
parent
03c0fb4bb2
commit
03ffd355ed
@ -28,6 +28,15 @@ def create_enrollments(examination_schedule_id: int, data: dict) -> dict:
|
||||
if start_date.date() != end_date.date():
|
||||
abort(400, "Invalid dates! Only hours can be different!")
|
||||
|
||||
enrollment = Enrollment.query.filter(Enrollment.start_date >= start_date,
|
||||
Enrollment.start_date < end_date).first()
|
||||
if enrollment is not None:
|
||||
abort(400, "You have just created enrollments for this range date!")
|
||||
|
||||
enrollment = Enrollment.query.filter(Enrollment.end_date > start_date, Enrollment.end_date <= end_date).first()
|
||||
if enrollment is not None:
|
||||
abort(400, "You have just created enrollments for this range date! `1")
|
||||
|
||||
delta = end_date - start_date
|
||||
delta_in_minutes = delta.total_seconds() / 60
|
||||
if delta_in_minutes % prt != 0:
|
||||
@ -37,9 +46,9 @@ def create_enrollments(examination_schedule_id: int, data: dict) -> dict:
|
||||
enrollments = []
|
||||
for i in range(amount):
|
||||
sd = start_date + datetime.timedelta(minutes=i * prt)
|
||||
ed = start_date + datetime.timedelta(minutes=(i + 1) * prt)
|
||||
enrollment = Enrollment(start_date=sd, end_date=ed, examination_schedule_id=examination_schedule_id)
|
||||
enrollments.append(enrollment)
|
||||
ed = start_date + datetime.timedelta(minutes=(i + 1) * prt)
|
||||
enrollment = Enrollment(start_date=sd, end_date=ed, examination_schedule_id=examination_schedule_id)
|
||||
enrollments.append(enrollment)
|
||||
db.session.add_all(enrollments)
|
||||
db.session.commit()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user