Class: Api::ProjectSerializer
Instance Method Summary
collapse
#badges, #documents, #documents_feed, #feed_id, #geoloc, #get_feed_attachments, #interests, #ressources, #skills
#creator, #get_user_json, #members, #reviewers, #users
#is_admin, #is_member, #is_owner, #is_pending, #is_reviewer
#has_clapped, #has_followed, #has_saved
Instance Method Details
#affiliated_spaces ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'app/serializers/api/project_serializer.rb', line 118
def affiliated_spaces
::Affiliation.where(affiliate_type: 'Project', parent_type: 'Space', affiliate_id: object.id).map do |affiliation_space|
Space.where(id: affiliation_space.parent_id).map do |space|
{
id: space.id,
title: space.title,
short_title: space.short_title,
short_description: space.short_description,
banner_url: space.banner_url,
banner_url_sm: space.banner_url_sm,
status: space.status,
affiliation_id: affiliation_space.id,
affiliation_status: affiliation_space.status
}
end
end
end
|
#challenges ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/serializers/api/project_serializer.rb', line 76
def challenges
includes = %i[program]
object.challenges.select('challenges.*, challenges_projects.project_status').includes(includes).map do |challenge|
program = if challenge.program.nil?
{
id: -1,
title: '',
title_fr: '',
short_title: ''
}
else
{
id: challenge.program.id,
title: challenge.program.title,
title_fr: challenge.program.title_fr,
short_title: challenge.program.short_title
}
end
{
id: challenge.id,
title: challenge.title,
title_fr: challenge.title_fr,
short_description: challenge.short_description,
short_description_fr: challenge.short_description_fr,
short_title: challenge.short_title,
banner_url: challenge.banner_url,
banner_url_sm: challenge.banner_url_sm,
project_status: ChallengesProject.project_statuses.key(challenge.project_status), status: challenge.status,
program: program,
space: space
}
end
end
|
#has_valid_proposal ⇒ Object
156
157
158
159
160
|
# File 'app/serializers/api/project_serializer.rb', line 156
def has_valid_proposal
object.proposals.any? do |proposal|
proposal.score && proposal.peer_review.score_threshold && proposal.score >= proposal.peer_review.score_threshold
end
end
|
#programs ⇒ Object
112
113
114
115
116
|
# File 'app/serializers/api/project_serializer.rb', line 112
def programs
Program.where(id: Challenge.where(id: ChallengesProject.where(project_id: object.id, project_status: 1).select(:challenge_id)).select(:program_id)).select(
:id, :title, :title_fr, :short_title
)
end
|
#proposals ⇒ Object
162
163
164
165
166
|
# File 'app/serializers/api/project_serializer.rb', line 162
def proposals
object.proposals.map do |proposal|
Api::ProposalSerializer.new(proposal)
end
end
|
#relation ⇒ Object
152
153
154
|
# File 'app/serializers/api/project_serializer.rb', line 152
def relation
object.respond_to?(:relation) ? object.relation : nil
end
|
#reviews_count ⇒ Object
168
169
170
171
172
173
174
|
# File 'app/serializers/api/project_serializer.rb', line 168
def reviews_count
if object.reviews_count == 1
object.reviews_count
else
has_valid_proposal ? 1 : 0
end
end
|
#scope? ⇒ Boolean
148
149
150
|
# File 'app/serializers/api/project_serializer.rb', line 148
def scope?
defined?(current_user).nil?
end
|
#show_objects? ⇒ Boolean
72
73
74
|
# File 'app/serializers/api/project_serializer.rb', line 72
def show_objects?
@instance_options[:show_objects]
end
|
#space ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/serializers/api/project_serializer.rb', line 136
def space
::Affiliation.where(affiliate_type: 'Project', parent_type: 'Space', affiliate_id: object.id).map do |affiliation_space|
Space.where(id: affiliation_space.parent_id).map do |space|
{
id: space.id,
title: space.title,
short_title: space.short_title
}
end
end
end
|