default selection is now none
This commit is contained in:
@@ -21,7 +21,13 @@ export class Application implements IApplication {
|
||||
}
|
||||
this.flattened = flatten(categories);
|
||||
if (this.flattened.allCategories.length === 0) {
|
||||
throw new Error('An application must consist of at least one category');
|
||||
throw new Error('Application must consist of at least one category');
|
||||
}
|
||||
if (this.flattened.allScripts.length === 0) {
|
||||
throw new Error('Application must consist of at least one script');
|
||||
}
|
||||
if (this.flattened.allScripts.filter((script) => script.isRecommended).length === 0) {
|
||||
throw new Error('Application must consist of at least one recommended script');
|
||||
}
|
||||
ensureNoDuplicates(this.flattened.allCategories);
|
||||
ensureNoDuplicates(this.flattened.allScripts);
|
||||
@@ -31,6 +37,10 @@ export class Application implements IApplication {
|
||||
return this.flattened.allCategories.find((category) => category.id === categoryId);
|
||||
}
|
||||
|
||||
public getRecommendedScripts(): readonly IScript[] {
|
||||
return this.flattened.allScripts.filter((script) => script.isRecommended);
|
||||
}
|
||||
|
||||
public findScript(scriptId: string): IScript | undefined {
|
||||
return this.flattened.allScripts.find((script) => script.id === scriptId);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,13 @@ import { IScript } from '@/domain/IScript';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
|
||||
export interface IApplication {
|
||||
readonly name: string;
|
||||
readonly version: number;
|
||||
readonly categories: ReadonlyArray<ICategory>;
|
||||
readonly totalScripts: number;
|
||||
readonly totalCategories: number;
|
||||
|
||||
getRecommendedScripts(): ReadonlyArray<IScript>;
|
||||
findCategory(categoryId: number): ICategory | undefined;
|
||||
findScript(scriptId: string): IScript | undefined;
|
||||
getAllScripts(): ReadonlyArray<IScript>;
|
||||
|
||||
@@ -4,5 +4,6 @@ import { IDocumentable } from './IDocumentable';
|
||||
export interface IScript extends IEntity<string>, IDocumentable {
|
||||
readonly name: string;
|
||||
readonly code: string;
|
||||
readonly isRecommended: boolean;
|
||||
readonly documentationUrls: ReadonlyArray<string>;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,11 @@ export class Script extends BaseEntity<string> implements IScript {
|
||||
return true;
|
||||
}
|
||||
|
||||
constructor(public name: string, public code: string, public documentationUrls: ReadonlyArray<string>) {
|
||||
constructor(
|
||||
public name: string,
|
||||
public code: string,
|
||||
public documentationUrls: ReadonlyArray<string>,
|
||||
public isRecommended: boolean) {
|
||||
super(name);
|
||||
if (code == null || code.length === 0) {
|
||||
throw new Error('Code is empty or null');
|
||||
|
||||
Reference in New Issue
Block a user