Skip to content

Commit

Permalink
status: Add resetStatusStreak and decrementStatusStreak API's
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Mar 17, 2020
1 parent 19fd085 commit bac2624
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion status/StatusUpdateReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def getInvalidUpdatesReport(self, invalidUpdates):
i = 0
for member in invalidUpdates.all():
i = i + 1
profile = UserProfile.objects.get(user=member.user)
profile = UserProfile.objects.get(user=member)
lastSend = profile.didNotSendStreak
profile.didNotSendStreak = self.getLastSend(int(lastSend))
message += str(i) + '. ' + self.getName(member) + '\n'
Expand Down
37 changes: 36 additions & 1 deletion status/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
from django.db.models import Count
import graphene
from graphql_jwt.decorators import login_required
from framework.api.APIException import APIException
from .models import *
from django.contrib.auth.models import User
from framework.api.user import UserBasicObj
from members.models import Group
from members.models import Group, Profile


class statusResponseObj(graphene.ObjectType):
status = graphene.String()


class MessageObj(graphene.ObjectType):
message = graphene.String()
Expand Down Expand Up @@ -116,6 +122,8 @@ class Query(graphene.ObjectType):
startDate=graphene.types.datetime.Date(required=True),
endDate=graphene.types.datetime.Date()
)
resetStatusStreak = graphene.Field(statusResponseObj)
decrementStatusStreak = graphene.Field(statusResponseObj)

@login_required
def resolve_getStatusUpdates(self, info, **kwargs):
Expand Down Expand Up @@ -150,3 +158,30 @@ def resolve_clubStatusUpdate(self, info, **kwargs):
'end': end
}
return data

@login_required
def resolve_resetStatusStreak(self, info):
if info.context.user.is_superuser:
profiles = Profile.objects.all()
for profile in profiles:
profile.didNotSendStreak = None
profile.save()

return statusResponseObj(status="Done")

else:
raise APIException('You don\'t have permission required to reset status streak', code='ACCESS_DENIED')

@login_required
def resolve_decrementStatusStreak(self, info):
if info.context.user.is_superuser:
profiles = Profile.objects.all()
for profile in profiles:
if profile.didNotSendStreak and int(profile.didNotSendStreak) > 0:
profile.didNotSendStreak = int(profile.didNotSendStreak) - 1
profile.save()

return statusResponseObj(status="Done")

else:
raise APIException('You don\'t have permission required to decrease status streak', code='ACCESS_DENIED')

0 comments on commit bac2624

Please sign in to comment.