From 87d2c5b900505e4103e6721aff2a4963c7bedac7 Mon Sep 17 00:00:00 2001 From: Faith Morante Date: Thu, 3 Mar 2022 20:55:34 +0800 Subject: [PATCH 1/2] filter by status --- src/graphql.ts | 1 + src/incidents/incidents.graphql | 1 + src/incidents/incidents.resolver.ts | 6 ++++++ src/incidents/incidents.service.ts | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/src/graphql.ts b/src/graphql.ts index 4d67eb9..83a369d 100644 --- a/src/graphql.ts +++ b/src/graphql.ts @@ -168,6 +168,7 @@ export interface IQuery { incidents(): Nullable[] | Promise[]>; incident(id: string): Nullable | Promise>; incidentsByServiceId(serviceId: string): Nullable[] | Promise[]>; + incidentsByStatus(status: string): Nullable[] | Promise[]>; incidentRoomURL(id: string): Nullable | Promise>; assignedIncidents(): Nullable[] | Promise[]>; openIncidents(): Nullable[] | Promise[]>; diff --git a/src/incidents/incidents.graphql b/src/incidents/incidents.graphql index 150af5f..3dcd08c 100644 --- a/src/incidents/incidents.graphql +++ b/src/incidents/incidents.graphql @@ -55,6 +55,7 @@ type Query { incidents: [Incident]! incident(id: ID!): Incident incidentsByServiceId(serviceId: ID!): [Incident]! + incidentsByStatus(status: String!): [Incident]! incidentRoomURL(id: ID!): String assignedIncidents: [Incident]! openIncidents: [Incident]! diff --git a/src/incidents/incidents.resolver.ts b/src/incidents/incidents.resolver.ts index 11bdff4..7f6deb7 100644 --- a/src/incidents/incidents.resolver.ts +++ b/src/incidents/incidents.resolver.ts @@ -1,3 +1,4 @@ +import { IncidentStatus } from './../graphql'; import { Resolver, Query, Mutation, Args } from '@nestjs/graphql'; import { IncidentsService } from './incidents.service'; @@ -37,6 +38,11 @@ export class IncidentsResolver { return this.incidentsService.findAllByServiceId(serviceId); } + @Query('incidentsByStatus') + incidentsByStatus(@Args('status') status: IncidentStatus) { + return this.incidentsService.findAllByStatus(status); + } + @Query('assignedIncidents') assignedIncidents(@CurrentUser() user: User) { return this.incidentsService.findAllByAssignedIncidents(user); diff --git a/src/incidents/incidents.service.ts b/src/incidents/incidents.service.ts index 206fb88..c15e0e9 100644 --- a/src/incidents/incidents.service.ts +++ b/src/incidents/incidents.service.ts @@ -147,6 +147,12 @@ export class IncidentsService { }); } + async findAllByStatus(status: IncidentStatus): Promise { + return await this.db.incident.findMany({ + where: { status }, + }); + } + async findAllByAssignedIncidents(user: User): Promise { return await this.db.incident.findMany({ where: { assigneeId: user.id }, From 4742a75878ea35608ab94e422507fa86c620344e Mon Sep 17 00:00:00 2001 From: Faith Morante Date: Thu, 10 Mar 2022 15:46:57 +0800 Subject: [PATCH 2/2] filter by status and org --- src/graphql.ts | 2 +- src/incidents/incidents.graphql | 2 +- src/incidents/incidents.resolver.ts | 14 +++++++++++--- src/incidents/incidents.service.ts | 8 ++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/graphql.ts b/src/graphql.ts index d521c9b..016028d 100644 --- a/src/graphql.ts +++ b/src/graphql.ts @@ -171,7 +171,7 @@ export interface IQuery { incidents(): Nullable[] | Promise[]>; incident(id: string): Nullable | Promise>; incidentsByServiceId(serviceId: string): Nullable[] | Promise[]>; - incidentsByStatus(status: string): Nullable[] | Promise[]>; + filteredIncidents(status?: Nullable, assigneeId?: Nullable, organizationId?: Nullable): Nullable[] | Promise[]>; incidentRoomURL(id: string): Nullable | Promise>; assignedIncidents(): Nullable[] | Promise[]>; openIncidents(): Nullable[] | Promise[]>; diff --git a/src/incidents/incidents.graphql b/src/incidents/incidents.graphql index 3dcd08c..c0a34fe 100644 --- a/src/incidents/incidents.graphql +++ b/src/incidents/incidents.graphql @@ -55,7 +55,7 @@ type Query { incidents: [Incident]! incident(id: ID!): Incident incidentsByServiceId(serviceId: ID!): [Incident]! - incidentsByStatus(status: String!): [Incident]! + filteredIncidents(status: String, assigneeId: String, organizationId: String): [Incident]! incidentRoomURL(id: ID!): String assignedIncidents: [Incident]! openIncidents: [Incident]! diff --git a/src/incidents/incidents.resolver.ts b/src/incidents/incidents.resolver.ts index 7f6deb7..0d5489f 100644 --- a/src/incidents/incidents.resolver.ts +++ b/src/incidents/incidents.resolver.ts @@ -38,9 +38,17 @@ export class IncidentsResolver { return this.incidentsService.findAllByServiceId(serviceId); } - @Query('incidentsByStatus') - incidentsByStatus(@Args('status') status: IncidentStatus) { - return this.incidentsService.findAllByStatus(status); + @Query('filteredIncidents') + filteredIncidents( + @Args('status') status: IncidentStatus, + @Args('assigneeId') assigneeId: string, + @Args('organizationId') organizationId: string, + ) { + return this.incidentsService.filterIncidents( + status, + assigneeId, + organizationId, + ); } @Query('assignedIncidents') diff --git a/src/incidents/incidents.service.ts b/src/incidents/incidents.service.ts index c5e7892..e5c43fd 100644 --- a/src/incidents/incidents.service.ts +++ b/src/incidents/incidents.service.ts @@ -151,9 +151,13 @@ export class IncidentsService { }); } - async findAllByStatus(status: IncidentStatus): Promise { + async filterIncidents( + status: IncidentStatus, + assigneeId: string, + organizationId: string, + ): Promise { return await this.db.incident.findMany({ - where: { status }, + where: { status, assigneeId, organizationId }, }); }