Commit e54b8a31 by Tô Ngọc Ánh

fix bug can't access /admin/applies

parent 4552c30b
Pipeline #1095 failed with stages
in 0 seconds
class AppliedJob < ApplicationRecord class AppliedJob < ApplicationRecord
scope :of_email, ->(email) { where(email: email) if email.present? } scope :of_email, ->(email) { where(email: email) if email.present? }
scope :order_desc, -> { order(created_at: :desc) }
EMAIL_REGEXN = /\A[a-zA-Z][\w\.]+@[a-zA-Z]+\.[a-zA-Z]+\z/ EMAIL_REGEXN = /\A[a-zA-Z][\w\.]+@[a-zA-Z]+\.[a-zA-Z]+\z/
CSV_ATTRIBUTES = %w(job_id job_title email full_name curriculum_vitae created_at).freeze CSV_ATTRIBUTES = %w(job_id job_title email full_name curriculum_vitae created_at).freeze
......
...@@ -2,7 +2,11 @@ module SearchAppliedJobsService ...@@ -2,7 +2,11 @@ module SearchAppliedJobsService
def self.search(params) def self.search(params)
date = {} date = {}
if params[:email].nil? if params[:email].nil?
applied_jobs = AppliedJob.includes(:job).order(created_at: :desc).page(params[:page]).decorate applied_jobs = AppliedJob.joins(:job)
.select("applied_jobs.*, jobs.title as job_title")
.order_desc
.page(params[:page])
.decorate
date[:from] = Date.today date[:from] = Date.today
date[:to] = Date.today date[:to] = Date.today
else else
...@@ -13,6 +17,7 @@ module SearchAppliedJobsService ...@@ -13,6 +17,7 @@ module SearchAppliedJobsService
.select("applied_jobs.*, jobs.title as job_title") .select("applied_jobs.*, jobs.title as job_title")
.of_email(params[:email]) .of_email(params[:email])
.where(created_at: date[:from]..date[:to], job_id: job_ids) .where(created_at: date[:from]..date[:to], job_id: job_ids)
.order_desc
.page(params[:page]) .page(params[:page])
end end
[date, applied_jobs] [date, applied_jobs]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment