-
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.
- Loading branch information
Showing
28 changed files
with
290 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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,17 @@ | ||
import { Injectable, PipeTransform } from '@nestjs/common'; | ||
import { DampLabServicePipe } from '../services/damplab-services.pipe'; | ||
import { CreateCategory } from './dtos/create.dto'; | ||
|
||
@Injectable() | ||
export class CreateCategoryPipe implements PipeTransform<CreateCategory, Promise<CreateCategory>> { | ||
constructor(private readonly damplabServicePipe: DampLabServicePipe) {} | ||
|
||
async transform(value: CreateCategory): Promise<CreateCategory> { | ||
// Ensure the services are valid | ||
for (const service of value.services) { | ||
await 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ID, InputType, OmitType, Field } from '@nestjs/graphql'; | ||
import { Category } from '../category.model'; | ||
|
||
@InputType() | ||
export class CreateCategory extends OmitType(Category, ['_id', 'services'] as const, InputType) { | ||
@Field(() => [ID]) | ||
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,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
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 { CreateService } from './dtos/create.dto'; | ||
|
||
@Injectable() | ||
export class CreateServicePipe implements PipeTransform<CreateService, Promise<CreateService>> { | ||
constructor(private readonly damplabServicePipe: DampLabServicePipe) {} | ||
|
||
async transform(value: CreateService): Promise<CreateService> { | ||
// Ensure the services are valid | ||
for (const service of value.allowedConnections) { | ||
await 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { CreateServicePipe } from './create.pipe'; | ||
import { DampLabServicePipe } from './damplab-services.pipe'; | ||
import { DampLabServicesResolver } from './damplab-services.resolver'; | ||
import { DampLabServices } from './damplab-services.services'; | ||
import { DampLabService, DampLabServiceSchema } from './models/damplab-service.model'; | ||
import { ServiceUpdatePipe } from './update.pipe'; | ||
|
||
@Module({ | ||
imports: [MongooseModule.forFeature([{ name: DampLabService.name, schema: DampLabServiceSchema }])], | ||
providers: [DampLabServicesResolver, DampLabServices, DampLabServicePipe], | ||
providers: [DampLabServicesResolver, DampLabServices, DampLabServicePipe, ServiceUpdatePipe, CreateServicePipe], | ||
exports: [DampLabServices, DampLabServicePipe] | ||
}) | ||
export class DampLabServicesModule {} |
Oops, something went wrong.