Add task for set mission to regulated - #291
Conversation
f8b49e8 to
cb19536
Compare
| def check_member_if_member_is_already_enrolled(input) | ||
| mission = input.mission | ||
| member = input.member | ||
| failure_message = I18n.t('activerecord.errors.models.enrollment.member_already_enrolled') |
There was a problem hiding this comment.
If you need a namespace for the transaction object locale, you can go for
'transactions.admin.enrollments.create.the_key_that_you_want' (just follow the folder structure basically)
You could use activerecord locale namespace if you were using these keys elsewhere ; e.g. for model validation feeback
| def match_a_time_slot?(input) | ||
| mission = input.mission | ||
| return false unless ((input.end_time.to_i - input.start_time.to_i) % (60 * 90)).zero? | ||
|
|
||
| current_time_slot = mission.start_date | ||
| while current_time_slot < mission.due_date | ||
| return true if current_time_slot == input.start_time | ||
|
|
||
| current_time_slot += 90.minutes | ||
| end | ||
| false | ||
| end |
There was a problem hiding this comment.
Do you think this could belong to the Enrollment model?
it set future mission which are -name: 'permanence clac' -genre: 'standard' -with enrollments are matching timeslots
cb19536 to
7e373b2
Compare
Mate2xo
left a comment
There was a problem hiding this comment.
I left a few comments if you want to improve some wordings.
Also a minor SQL optimization
| missions = Mission.where('start_date > ? and genre = ? and name = ?', | ||
| DateTime.current + 1.day, | ||
| 0, | ||
| 'permanence clac') |
There was a problem hiding this comment.
If you think that checking case-insensively could be useful, you can use pgsql's LOWER() method in the .where query string for the name
| end | ||
| end | ||
|
|
||
| def match_all_enrollment_a_time_slot?(mission) |
There was a problem hiding this comment.
Did you mean something like
def all_enrollments_match_a_time_slot?(mission)
?
| 'permanence clac') | ||
| missions.each do |mission| | ||
| unless match_all_enrollment_a_time_slot?(mission) | ||
| puts("the mission at #{mission.start_date} has not been setted, an enrollment mismatch the mission's timeslots") |
There was a problem hiding this comment.
puts("the mission starting at #{mission.start_date} has not been set to the :regulated status : an enrollment doesn't match with the mission's timeslots")
| next | ||
| end | ||
|
|
||
| puts("the mission at #{mission.start_date} has been setted") if mission.update(genre: 1) |
it set future mission which are
-name: 'permanence clac'
-genre: 'standard'
-with enrollments are matching timeslots