SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. user_1 = User.first
  2. user_2 = User.second
  3. manager = Manager.first
  4.  
  5. # usuario que solicita, el usuario y manager solicitado
  6. # en qué día y qué turno?
  7. Request.new(
  8.   requester_id: user_1.id,
  9.   requested_id: user_2.id,
  10.   type: "user",
  11.   status: "PENDING",
  12.   date_work_shift: "01-10-19",
  13.   requested_shift_id: 1,
  14.   current_shift_id: 3
  15. )
  16.  
  17. if type == "user" && status == "ACCEPTED"
  18.   # sucede despues
  19.   Request.new(
  20.     requester_id: user_1.id,
  21.     requested_id: manager.id,
  22.     type: "manager",
  23.     status: "PENDING",
  24.     date_work_shift: "01-10-19",
  25.     requested_shift_id: 1,
  26.     current_shift_id: 3
  27.   )
  28. end
  29.  
  30. schedule_1 = Schedule.new(
  31.   month: "October",
  32.   user_id: 2,
  33.   work_shifts: [
  34.     {
  35.       date: "01-10-19",
  36.       shift_id: 1 # mañana
  37.     },
  38.     {
  39.       date: "02-10-19",
  40.       shift_id: 1 # mañana
  41.     },
  42.     {
  43.       date: "03-10-19",
  44.       shift_id: 2 # tarde
  45.     },
  46.     {
  47.       date: "04-10-19",
  48.       shift_id: 4 # DAY OFF
  49.     }
  50.   ]
  51. )
  52.  
  53. schedule_1 = user_1.schedules.find_by_month("October")
  54. work_shifts = schedule_1.work_shifts
  55. work_shifts.map! do |work_shift|
  56.   work_shift[:shift_id] = 3 if work_shift[:date] == "01-10-19"
  57. end
  58. schedule_1.update(work_shifts: work_shifts)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top