Skip to content

Instantly share code, notes, and snippets.

@laugri
laugri / ddd-example-usecase-test.js
Last active December 3, 2018 17:55
DDD Example - use case test
import { articleTestFactory } from '~/domain/article';
import { shoppingCartTestFactory, itemTestFactory } from '~/domain/shoppingCart';
import { InMemoryShoppingCartRepository } from '~/infrastructure/InMemoryShoppingCartRepository';
import { InMemoryArticleRepository } from '~/infrastructure/InMemoryArticleRepository';
describe('addArticleToCart', () => {
it('should update, persist and return the cart with a new article', async () => {
// Arrange
const shoppingCartRepository = new InMemoryShoppingCartRepository();
const shoppingCart = shoppingCartTestFactory({items: []})
@laugri
laugri / ddd-example-repository-implementation.js
Created December 2, 2018 17:16
DDD example - Repository implementation
// Repository implementation example
class InMemoryShoppingCartRepository implements ShoppingCartRepository {
findById(shoppingCartId: ShoppingCartId) {
// implementation
}
store(ShoppingCart: ShoppingCart): Promise<void> {
// implementation
@laugri
laugri / ddd-example-repository-interface.js
Created December 2, 2018 17:16
DDD example - Repository Interface
// Repository interface example
interface ShoppingCartRepository {
findById(shoppingCartId: ShoppingCartId): Promise<ShoppingCart>;
store(shoppingCart: ShoppingCart): Promise<void>;
}
@laugri
laugri / ddd-example-aggregate.js
Created December 2, 2018 17:14
DDD Example - Aggregate.js
// Our ShoppingCart example of an Entity is actually also an aggregate.
class ShoppingCart {
id: ShoppingCartId;
items: Array<ShoppingCartItem>
addItem(item: ShoppingCartItem) {
// implementation
}
@laugri
laugri / ddd-example-domain-service.js
Created December 2, 2018 17:11
DDD example - domain service
// For e-commerce, an example of a domain service would be the checkout step
function checkout(shoppingCart: ShoppingCart, ...) {
// do service stuff
}
@laugri
laugri / ddd-example-entity.js
Created December 2, 2018 17:08
DDD example - Entity
// An example of an Entity
class ShoppingCart {
id: ShoppingCartId;
items: Array<ShoppingCartItem>
addItem(item: ShoppingCartItem) {
// implementation
}
@laugri
laugri / ddd-example-value-object.js
Last active December 5, 2018 16:59
DDD example - Value Object
// An example of a Value Object
class Price {
amountInEuroCents: number
inEuros(): number {
// implementation
}
{
"scripts": {
"heroku-postbuild": "./scripts/heroku.build",
}
}
#!/bin/sh -e
usage() {
echo "OVERVIEW: Build apps according to BUILD_ENV value. Meant to be used for Heroku deployment"
exit
}
if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
usage
fi
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const PORT = process.env.PORT || 3000;
const app = express();
const logger = morgan(
process.env.NODE_ENV !== 'production' ? 'dev' : 'combined',