add templates and submissions search

This commit is contained in:
Alex Turchyn
2023-09-15 02:11:48 +03:00
parent 7f6c0af0e8
commit 53fa35fd01
12 changed files with 101 additions and 23 deletions
+14
View File
@@ -5,6 +5,20 @@ module Submissions
module_function
def search(submissions, keyword)
return submissions if keyword.blank?
term = "%#{keyword.downcase}%"
arel_table = Submitter.arel_table
arel = arel_table[:email].lower.matches(term)
.or(arel_table[:phone].matches(term))
.or(arel_table[:name].lower.matches(term))
submissions.joins(:submitters).where(arel).distinct
end
def update_template_fields!(submission)
submission.template_fields = submission.template.fields
submission.template_schema = submission.template.schema
+6
View File
@@ -17,4 +17,10 @@ module Templates
hash
end
def search(templates, keyword)
return templates if keyword.blank?
templates.where(Template.arel_table[:name].lower.matches("%#{keyword.downcase}%"))
end
end