How do I refer to an enum in my application? I nee...
# prisma-whats-new
z
How do I refer to an enum in my application? I need to check if
assignment.status
(which is an enum) has a value of
NORMAL
(one of the possible values). My code right now is
Copy code
if (assignment.status === 'NORMAL') {...}
, but it doesn't work.
e
What does a console log look like? I know when you pass an enum to a query, it's just a string format of it
Some good ol debugging here should shed some light.
z
logging
assignment.status
gives
NORMAL
(as a string)
e
Well that's quite odd indeed
Does it behave any differently with == rather than === (not advised for real implementation obviously, just trying to wrap my head around your situation. )
Also check what type of returns for assignment.status
Are you 100% sure you're not getting into that block? Or just that what's supposed to happen in the block doesn't happen
z
If I remove the conditional it works fine
if I do
console.log(typeof assignment.status)
I get
string
==
vs
===
doesn't make a difference
Here is a snippet of the code:
Copy code
<List id="assignment-list">
              {this.props.assignments.map(
                assignment =>
                  ((!assignment.recurring) && (assignment.status === "NORMAL"))
                    ? <AssignmentListItem
                        isTeacher={this.props.isTeacher}
                        key={assignment.id}
                        assignment={assignment}
                        updateAssignmentStatus={this.updateAssignmentStatus}
                      />
                    : ''
              )}
            </List>
e
Well react isn't my specialty by any means, but out of curiosity, do you get any components rendered when you remove the other conditional?
z
...interestingly enough, yes
e
Well I think you've got some further inspection to do
z
but if I leave the other conditional and remove the
status
one it works too
e
I understand that
Are you positive there are actually records which meet both conditionals?
z
absolutely
e
Remove the status conditional, and then log the status of each successfully rendered component
Also, this is a style thing for sure, but might you consider extracting this logic to a function? I should think it would improve the readability of your code
I'm also on mobile so maybe that's not needed lol
z
ill look into it
ok so
there are no `NORMAL`s logged
e
I think you're getting close to your solution
z
If I go into graph.cool's data tab, I can see a bunch that meet both conditions, though
e
Definitely weird. You'll probably want to review your query
Check it out in the playground til you have what you need
Maybe you've got a filter that's behaving unexpectedly or something of that sort
z
I removed all the filters from it, and it still doesn't work in the playground. It pulls everything except the combination where recurring is false and status is normal
e
Definitely weird. @agartha anything to add here?
z
I will just refactor
recurring
to be a value in the
status
enum. Thanks for the help!
e
No worries, that's what this slack is for