Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Product } from '.';
- import { validate } from './validator';
- export class Category {
- private readonly minNameLength: number = 2;
- private readonly maxNameLength: number = 15;
- private readonly _name: string;
- private _products: Product[];
- public constructor(name: string) {
- if (name.length < this.minNameLength || name.length > this.maxNameLength){
- throw new Error(`Product name length must be between ${this.minNameLength} and ${this.maxNameLength}`);
- }
- this._name = name;
- this._products = [];
- }
- public get products(): Product[] {
- return this._products;
- }
- public addProduct(product: Product): void {
- if (product === null) {
- throw new Error('Product to add cannot be null!');
- }
- this.products.push(product);
- }
- public removeProduct(product: Product): void {
- if (product === null || product === undefined){
- throw new Error(`Error`);
- }
- const productFound: Product | undefined = this.products.find((x: Product) => x.name === product.name);
- }
- public print(): string {
- throw new Error('Not implemented!');
- }
- // Do not remove this. It is used for the tests.
- protected set mockProductsData(value: Product[]) {
- this._products = value;
- }
- }
Add Comment
Please, Sign In to add comment