Skip to content

Commit

Permalink
Add Retrigger of load geo area
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Nov 19, 2024
1 parent a7bb213 commit 1387f5f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apps/geo/mutations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from geo.tasks import load_geo_areas
import graphene

from geo.models import Region, AdminLevel
Expand Down Expand Up @@ -134,10 +135,47 @@ def mutate(root, info, id):
return PublishRegion(result=instance, errors=None, ok=True)


class ReTriggeredFailedRegion(graphene.Mutation):
class Arguments:
region_id = graphene.ID(required=True)
model = Region
errors = graphene.List(graphene.NonNull(CustomErrorType))
ok = graphene.Boolean()
result = graphene.Field(RegionType)

@staticmethod
def mutate(root, info, region_id):
instance = Region.objects.filter(
id=region_id
).first()
error_data = []
if instance is None:
error_data.append('Region does\'t exist')
elif instance.status == Region.Status.COMPLETED:
error_data.append('Geo Area already generated')
elif instance.created_by != info.context.user:
error_data.append('Authorized User only update region')

if error_data:
return ReTriggeredFailedRegion(errors=[
dict(
field='nonFieldErrors',
messages=error_data
)
], ok=False)
load_geo_areas(region_id)
return ReTriggeredFailedRegion(
result=instance,
error=None,
ok=True
)


class Mutation():
create_region = CreateRegion.Field()
update_region = UpdateRegion.Field()
create_admin_level = CreateAdminLevel.Field()
publish_region = PublishRegion.Field()
update_admin_level = UpdateAdminLevel.Field()
delete_admin_level = DeleteAdminLevel.Field()
retrigger_region = ReTriggeredFailedRegion.Field()
1 change: 1 addition & 0 deletions apps/geo/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def load_geo_areas(region_id):
return False

try:
region_id.status = Region.Status.INITIATED
return_value = _load_geo_areas(region_id)
except Exception:
logger.error('Load Geo Areas', exc_info=True)
Expand Down
7 changes: 7 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5078,6 +5078,7 @@ type Mutation {
publishRegion(id: ID!): PublishRegion
updateAdminLevel(data: AdminLevelInputType!, id: ID!): UpdateAdminLevel
deleteAdminLevel(adminLevelId: ID!): DeleteAdminLevel
retriggerRegion(regionId: ID!): ReTriggeredFailedRegion
organizationCreate(data: OrganizationInputType!): OrganizationCreate
createAssessmentRegSummaryIssue(data: AssessmentRegistrySummaryIssueCreateInputType!): AssessmentRegistryCreateIssue
fileUpload(data: FileUploadInputType!): UploadFile
Expand Down Expand Up @@ -5920,6 +5921,12 @@ type QuestionType {
subSectorDisplay: EnumDescription
}

type ReTriggeredFailedRegion {
errors: [GenericScalar!]
ok: Boolean
result: RegionType
}

type RecentActivityType {
id: ID!
createdAt: DateTime
Expand Down

0 comments on commit 1387f5f

Please sign in to comment.