-
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
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
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,14 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class Product1609755423492 implements MigrationInterface { | ||
name = 'Product1609755423492' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "product" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying NOT NULL, "description" character varying, "unitPrice" integer NOT NULL DEFAULT 0, CONSTRAINT "PK_bebc9158e480b949565b4dc7a82" PRIMARY KEY ("id"))`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "product"`); | ||
} | ||
|
||
} |
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,15 @@ | ||
import { Product } from './Product.entity'; | ||
|
||
describe('Product', () => { | ||
it('testGetters', () => { | ||
const product = new Product( | ||
'Mug', | ||
'Mug avec le portrait de l\'enfant', | ||
999 | ||
); | ||
expect(product.getId()).toBeUndefined(); | ||
expect(product.getTitle()).toBe('Mug'); | ||
expect(product.getDescription()).toBe('Mug avec le portrait de l\'enfant'); | ||
expect(product.getUnitPrice()).toBe(999); | ||
}); | ||
}); |
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,38 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
@Entity() | ||
export class Product { | ||
@PrimaryGeneratedColumn('uuid') | ||
private id: string; | ||
|
||
@Column({ type: 'varchar', nullable: false }) | ||
private title: string; | ||
|
||
@Column({ type: 'varchar', nullable: true }) | ||
private description: string; | ||
|
||
@Column({ type: 'integer', nullable: false, default: 0 }) | ||
private unitPrice: number; | ||
|
||
constructor(title: string, description: string, unitPrice: number) { | ||
this.title = title; | ||
this.description = description; | ||
this.unitPrice = unitPrice; | ||
} | ||
|
||
public getId(): string { | ||
return this.id; | ||
} | ||
|
||
public getTitle(): string { | ||
return this.title; | ||
} | ||
|
||
public getDescription(): string { | ||
return this.description; | ||
} | ||
|
||
public getUnitPrice(): number { | ||
return this.unitPrice; | ||
} | ||
} |
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,5 @@ | ||
import { Product } from '../Product.entity'; | ||
|
||
export interface IProductRepository { | ||
save(task: Product): Promise<Product>; | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/Infrastructure/Product/Repository/ProductRepository.ts
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 } from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Product } from 'src/Domain/Product/Product.entity'; | ||
import { IProductRepository } from 'src/Domain/Product/Repository/IProductRepository'; | ||
|
||
@Injectable() | ||
export class ProductRepository implements IProductRepository { | ||
constructor( | ||
@InjectRepository(Product) | ||
private readonly repository: Repository<Product> | ||
) {} | ||
|
||
public save(product: Product): Promise<Product> { | ||
return this.repository.save(product); | ||
} | ||
} |
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,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { BusModule } from '../bus.module'; | ||
import { Product } from 'src/Domain/Product/Product.entity'; | ||
import { ProductRepository } from './Repository/ProductRepository'; | ||
|
||
@Module({ | ||
imports: [BusModule, TypeOrmModule.forFeature([Product])], | ||
controllers: [], | ||
providers: [ | ||
{ provide: 'IProductRepository', useClass: ProductRepository } | ||
] | ||
}) | ||
export class ProductModule {} |