Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"jsc" : {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
}
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
}
}
}
3 changes: 1 addition & 2 deletions src/domain/@shared/event/event-dispatcher.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EventHandlerInterface from "./event-handler.interface";
import EventInterface from "./event.interface";
import { EventHandlerInterface, EventInterface } from ".";

export default interface EventDispatcherInterface {
notify(event: EventInterface): void;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/@shared/event/event-dispatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SendEmailWhenProductIsCreatedHandler from "../../product/event/handler/send-email-when-product-is-created.handler";
import ProductCreatedEvent from "../../product/event/product-created.event";
import EventDispatcher from "./event-dispatcher";
import { EventDispatcher } from ".";

describe("Domain events tests", () => {
it("should register an event handler", () => {
Expand Down
10 changes: 6 additions & 4 deletions src/domain/@shared/event/event-dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import EventDispatcherInterface from "./event-dispatcher.interface";
import EventHandlerInterface from "./event-handler.interface";
import eventInterface from "./event.interface";
import {
EventDispatcherInterface,
EventHandlerInterface,
EventInterface,
} from ".";

export default class EventDispatcher implements EventDispatcherInterface {
private eventHandlers: { [eventName: string]: EventHandlerInterface[] } = {};
Expand Down Expand Up @@ -29,7 +31,7 @@ export default class EventDispatcher implements EventDispatcherInterface {
this.eventHandlers = {};
}

notify(event: eventInterface): void {
notify(event: EventInterface): void {
const eventName = event.constructor.name;
if (this.eventHandlers[eventName]) {
this.eventHandlers[eventName].forEach((eventHandler) => {
Expand Down
2 changes: 1 addition & 1 deletion src/domain/@shared/event/event-handler.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventInterface from './event.interface';
import { EventInterface } from ".";
export default interface EventHandlerInterface<T extends EventInterface=EventInterface> {
handle(event: T): void;
}
11 changes: 11 additions & 0 deletions src/domain/@shared/event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import EventDispatcher from "./event-dispatcher";
import EventDispatcherInterface from "./event-dispatcher.interface";
import EventHandlerInterface from "./event-handler.interface";
import EventInterface from "./event.interface";

export {
EventDispatcher,
EventHandlerInterface,
EventInterface,
EventDispatcherInterface
};
3 changes: 3 additions & 0 deletions src/domain/@shared/repository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import RepositoryInterface from "./repository-interface";

export { RepositoryInterface };
7 changes: 7 additions & 0 deletions src/domain/checkout/entity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Order from "./order";
import OrderItem from "./order_item";

export {
OrderItem,
Order
}
3 changes: 1 addition & 2 deletions src/domain/checkout/entity/order.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Order from "./order";
import OrderItem from "./order_item";
import { Order, OrderItem } from ".";

describe("Order unit tests", () => {
it("should throw error when id is empty", () => {
Expand Down
4 changes: 1 addition & 3 deletions src/domain/checkout/entity/order.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import OrderItem from "./order_item";
import { OrderItem } from ".";
export default class Order {
private _id: string;
private _customerId: string;
private _items: OrderItem[];
private _total: number;

constructor(id: string, customerId: string, items: OrderItem[]) {
this._id = id;
this._customerId = customerId;
this._items = items;
this._total = this.total();
this.validate();
}

Expand Down
3 changes: 3 additions & 0 deletions src/domain/checkout/factory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import OrderFactory from "./order.factory";

export { OrderFactory };
2 changes: 1 addition & 1 deletion src/domain/checkout/factory/order.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { v4 as uuid } from "uuid";
import OrderFactory from "./order.factory";
import { OrderFactory } from ".";

describe("Order factory unit test", () => {
it("should create an order", () => {
Expand Down
6 changes: 2 additions & 4 deletions src/domain/checkout/factory/order.factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Order from "../entity/order";
import OrderItem from "../entity/order_item";
import { Order, OrderItem } from "@/domain/checkout/entity";

interface OrderFactoryProps {
id: string;
Expand All @@ -24,8 +23,7 @@ export default class OrderFactory {
item.quantity
);
});

return new Order(props.id, props.customerId, items);

return new Order(props.id, props.customerId, items);
}
}
3 changes: 3 additions & 0 deletions src/domain/checkout/repository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import OrderRepositoryInterface from "./order-repository.interface";

export { OrderRepositoryInterface };
7 changes: 4 additions & 3 deletions src/domain/checkout/repository/order-repository.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import RepositoryInterface from "../../@shared/repository/repository-interface";
import Order from "../entity/order";
import { RepositoryInterface } from "@/domain/@shared/repository";
import { Order } from "@/domain/checkout/entity";

export default interface OrderRepositoryInterface extends RepositoryInterface<Order> {}
export default interface OrderRepositoryInterface
extends RepositoryInterface<Order> {}
5 changes: 5 additions & 0 deletions src/domain/checkout/service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import OrderService from "./order.service";

export {
OrderService
}
7 changes: 3 additions & 4 deletions src/domain/checkout/service/order.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Customer from "../../customer/entity/customer";
import Order from "../entity/order";
import OrderItem from "../entity/order_item";
import OrderService from "./order.service";
import { Customer } from "@/domain/customer/entity";
import { Order, OrderItem } from "@/domain/checkout/entity";
import { OrderService } from ".";
describe("Order service unit tets", () => {
it("should place an order", () => {
const customer = new Customer("c1", "Customer 1");
Expand Down
5 changes: 2 additions & 3 deletions src/domain/checkout/service/order.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Order from "../entity/order";
import OrderItem from "../entity/order_item";
import { v4 as uuid } from "uuid";
import Customer from "../../customer/entity/customer";
import { Order, OrderItem } from "../entity";
import { Customer } from "@/domain/customer/entity";

export default class OrderService {
static placeOrder(customer: Customer, items: OrderItem[]): Order {
Expand Down
4 changes: 2 additions & 2 deletions src/domain/customer/entity/customer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Address from "../value-object/address";
import Customer from "./customer";
import { Address } from "@/domain/customer/value-object";
import { Customer } from ".";

describe("Customer unit tests", () => {
it("should throw error when id is empty", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/domain/customer/entity/customer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Address from "../value-object/address";
import { Address } from "@/domain/customer/value-object";

export default class Customer {
private _id: string;
Expand Down Expand Up @@ -42,7 +42,7 @@ export default class Customer {
get Address(): Address {
return this._address;
}

changeAddress(address: Address) {
this._address = address;
}
Expand Down
3 changes: 3 additions & 0 deletions src/domain/customer/entity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Customer from "./customer";

export { Customer };
4 changes: 2 additions & 2 deletions src/domain/customer/factory/customer.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CustomerFactory from "./customer.factory";
import Address from "../value-object/address";
import { Address } from "@/domain/customer/value-object";
import { CustomerFactory } from ".";

describe("Customer factory unit test", () => {
it("should create a customer", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/domain/customer/factory/customer.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Customer from "../entity/customer";
import { v4 as uuid } from "uuid";
import Address from "../value-object/address";
import { Address } from "@/domain/customer/value-object";
import { Customer } from "@/domain/customer/entity";

export default class CustomerFactory {
public static create(name: string): Customer {
Expand Down
3 changes: 3 additions & 0 deletions src/domain/customer/factory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CustomerFactory from "./customer.factory";

export { CustomerFactory };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RepositoryInterface from "../../@shared/repository/repository-interface";
import Customer from "../entity/customer";
import { RepositoryInterface } from "@/domain/@shared/repository";
import { Customer } from "@/domain/customer/entity";

export default interface CustomerRepositoryInterface
extends RepositoryInterface<Customer> {}
3 changes: 3 additions & 0 deletions src/domain/customer/repository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CustomerRepositoryInterface from "./customer-repository.interface";

export { CustomerRepositoryInterface };
2 changes: 1 addition & 1 deletion src/domain/customer/value-object/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Address {
get city(): string {
return this._city;
}

validate() {
if (this._street.length === 0) {
throw new Error("Street is required");
Expand Down
3 changes: 3 additions & 0 deletions src/domain/customer/value-object/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Address from "./address";

export { Address };
5 changes: 5 additions & 0 deletions src/domain/product/entity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Product from "./product";
import ProductB from "./product-b";
import ProductInterface from "./product.interface";

export { ProductB, ProductInterface, Product };
2 changes: 1 addition & 1 deletion src/domain/product/entity/product-b.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ProductInterface from "./product.interface";
import { ProductInterface } from ".";

export default class ProductB implements ProductInterface {
private _id: string;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/product/entity/product.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Product from "./product";
import { Product } from ".";

describe("Product unit tests", () => {
it("should throw error when id is empty", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/domain/product/entity/product.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ProductInterface from "./product.interface";
import { ProductInterface } from ".";

export default class Product implements ProductInterface {
private _id: string;
Expand All @@ -15,7 +15,7 @@ export default class Product implements ProductInterface {
get id(): string {
return this._id;
}

get name(): string {
return this._name;
}
Expand Down
5 changes: 5 additions & 0 deletions src/domain/product/event/handler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import SendEmailWhenProductIsCreatedHandler from "./send-email-when-product-is-created.handler";

export {
SendEmailWhenProductIsCreatedHandler
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import EventHandlerInterface from "../../../@shared/event/event-handler.interface";
import ProductCreatedEvent from "../product-created.event";
import EventHandlerInterface from "@/domain/@shared/event/event-handler.interface";
import { ProductCreatedEvent } from "@/domain/product/event";

export default class SendEmailWhenProductIsCreatedHandler
implements EventHandlerInterface<ProductCreatedEvent>
{
handle(event: ProductCreatedEvent): void {
console.log(`Sending email to .....`);
console.log(`Sending email to .....`);
}
}
3 changes: 3 additions & 0 deletions src/domain/product/event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ProductCreatedEvent from "./product-created.event";

export { ProductCreatedEvent };
2 changes: 1 addition & 1 deletion src/domain/product/event/product-created.event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventInterface from "../../@shared/event/event.interface";
import { EventInterface } from "@/domain/@shared/event";

export default class ProductCreatedEvent implements EventInterface {
dataTimeOccurred: Date;
Expand Down
3 changes: 3 additions & 0 deletions src/domain/product/factory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ProductFactory from "./product.factory";

export { ProductFactory };
2 changes: 1 addition & 1 deletion src/domain/product/factory/product.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ProductFactory from "./product.factory";
import { ProductFactory } from ".";

describe("Product factory unit test", () => {
it("should create a proct type a", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/domain/product/factory/product.factory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Product from "../entity/product";
import ProductInterface from "../entity/product.interface";
import { v4 as uuid } from "uuid";
import ProductB from "../entity/product-b";
import { Product } from "@/domain/product/entity";
import { ProductInterface } from "@/domain/product/entity";
import { ProductB } from "@/domain/product/entity";

export default class ProductFactory {
public static create(
type: string,
type: "a" | "b" | "c",
name: string,
price: number
): ProductInterface {
Expand Down
3 changes: 3 additions & 0 deletions src/domain/product/repository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ProductRepositoryInterface from "./product-repository.interface";

export { ProductRepositoryInterface };
4 changes: 2 additions & 2 deletions src/domain/product/repository/product-repository.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RepositoryInterface from "../../@shared/repository/repository-interface";
import Product from "../entity/product";
import { RepositoryInterface } from "../../@shared/repository";
import { Product } from "../entity";

export default interface ProductRepositoryInterface
extends RepositoryInterface<Product> {}
3 changes: 3 additions & 0 deletions src/domain/product/service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ProductService from "./product.service";

export { ProductService };
4 changes: 2 additions & 2 deletions src/domain/product/service/product.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Product from "../entity/product";
import ProductService from "./product.service";
import { Product } from "@/domain/product/entity";
import { ProductService } from ".";

describe("Product service unit tests", () => {
it("should change the prices of all products", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/domain/product/service/product.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Product from "../entity/product";
import { Product } from "@/domain/product/entity";

export default class ProductService {
static increasePrice(products: Product[], percentage: number): Product[] {
Expand Down
Loading