-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description * GraphQL updates for basic CRUD on * Service * Category * Bundle * Service list validation before update ## Checklist - [x] This PR can be reviewed in under 30 minutes - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] I have assigned reviewers to this PR.
- Loading branch information
Showing
17 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable, NotFoundException, PipeTransform } from '@nestjs/common'; | ||
import { Bundle } from './bundles.model'; | ||
import { BundlesService } from './bundles.service'; | ||
|
||
@Injectable() | ||
export class BundlesPipe implements PipeTransform<string, Promise<Bundle>> { | ||
constructor(private readonly bundleService: BundlesService) {} | ||
|
||
async transform(value: string): Promise<Bundle> { | ||
const bundle = await this.bundleService.find(value); | ||
|
||
if (!bundle) { | ||
throw new NotFoundException(`Bundle with id ${value} not found`); | ||
} | ||
return bundle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Bundle } from '../bundles.model'; | ||
import { ID, InputType, OmitType, PartialType, Field } from '@nestjs/graphql'; | ||
|
||
@InputType() | ||
export class BundleChange extends PartialType(OmitType(Bundle, ['id', 'services'] as const), InputType) { | ||
@Field(() => [ID], { nullable: true }) | ||
services: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable, PipeTransform } from '@nestjs/common'; | ||
import { DampLabServicePipe } from '../services/damplab-services.pipe'; | ||
import { BundleChange } from './dtos/update.dto'; | ||
|
||
@Injectable() | ||
export class BundleUpdatePipe implements PipeTransform<BundleChange, Promise<BundleChange>> { | ||
constructor(private readonly damplabServicePipe: DampLabServicePipe) {} | ||
|
||
async transform(value: BundleChange): Promise<BundleChange> { | ||
// If services is includes, make sure they are all valid | ||
if (value.services) { | ||
await Promise.all(value.services.map((service) => this.damplabServicePipe.transform(service))); | ||
} | ||
|
||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NotFoundException, Injectable, PipeTransform } from '@nestjs/common'; | ||
import { Category } from './category.model'; | ||
import { CategoryService } from './categories.service'; | ||
|
||
@Injectable() | ||
export class CategoryPipe implements PipeTransform<string, Promise<Category>> { | ||
constructor(private readonly categoryService: CategoryService) {} | ||
|
||
async transform(value: string): Promise<Category> { | ||
try { | ||
const category = await this.categoryService.find(value); | ||
if (category) { | ||
return category; | ||
} | ||
} catch (e) {} | ||
|
||
throw new NotFoundException(`Category with id ${value} not found`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Category } from '../category.model'; | ||
import { ID, OmitType, PartialType, Field, InputType } from '@nestjs/graphql'; | ||
|
||
@InputType() | ||
export class CategoryChange extends PartialType(OmitType(Category, ['_id', 'services'] as const), InputType) { | ||
@Field(() => [ID], { nullable: true }) | ||
services: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable, PipeTransform } from '@nestjs/common'; | ||
import { DampLabServicePipe } from '../services/damplab-services.pipe'; | ||
import { CategoryChange } from './dtos/update.dto'; | ||
|
||
@Injectable() | ||
export class CategoryUpdatePipe implements PipeTransform<CategoryChange, Promise<CategoryChange>> { | ||
constructor(private readonly damplabServicePipe: DampLabServicePipe) {} | ||
|
||
async transform(value: CategoryChange): Promise<CategoryChange> { | ||
// If services is includes, make sure they are all valid | ||
if (value.services) { | ||
await Promise.all(value.services.map((service) => this.damplabServicePipe.transform(service))); | ||
} | ||
|
||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DampLabService } from '../models/damplab-service.model'; | ||
import { ID, InputType, OmitType, PartialType, Field } from '@nestjs/graphql'; | ||
|
||
@InputType() | ||
export class ServiceChange extends PartialType(OmitType(DampLabService, ['_id', 'allowedConnections'] as const), InputType) { | ||
@Field(() => [ID], { nullable: true }) | ||
allowedConnections: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable, PipeTransform } from '@nestjs/common'; | ||
import { DampLabServicePipe } from '../services/damplab-services.pipe'; | ||
import { ServiceChange } from './dtos/update.dto'; | ||
|
||
@Injectable() | ||
export class ServiceUpdatePipe implements PipeTransform<ServiceChange, Promise<ServiceChange>> { | ||
constructor(private readonly damplabServicePipe: DampLabServicePipe) {} | ||
|
||
async transform(value: ServiceChange): Promise<ServiceChange> { | ||
// If services is includes, make sure they are all valid | ||
if (value.allowedConnections) { | ||
await Promise.all(value.allowedConnections.map((service) => this.damplabServicePipe.transform(service))); | ||
} | ||
|
||
return value; | ||
} | ||
} |