-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ Corrige algumas atualizações do projeto.
- Loading branch information
1 parent
513333a
commit 9924a4a
Showing
13 changed files
with
490 additions
and
259 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,65 @@ | ||
import ValueObject from "../../../@shared/domain/value-object/value-object.interface" | ||
|
||
export default class Address implements ValueObject { | ||
_street: string = "" | ||
_number: string = "" | ||
_complement: string = "" | ||
_city: string = "" | ||
_state: string = "" | ||
_zipCode: string = "" | ||
|
||
constructor(street: string, number: string, complement: string, city: string, state: string, zipCode: string) { | ||
this._street = street | ||
this._number = number | ||
this._complement = complement | ||
this._city = city | ||
this._state = state | ||
this._zipCode = zipCode | ||
|
||
} | ||
|
||
get street(): string { | ||
return this._street | ||
} | ||
|
||
get number(): string { | ||
return this._number | ||
} | ||
|
||
get complement(): string { | ||
return this._complement | ||
} | ||
|
||
get city(): string { | ||
return this._city | ||
} | ||
|
||
get state(): string { | ||
return this._state | ||
} | ||
|
||
get zipCode(): string { | ||
return this._zipCode | ||
} | ||
|
||
validate() { | ||
if (this._street.length === 0) { | ||
throw new Error("Street is required") | ||
} | ||
if (this._number.length === 0) { | ||
throw new Error("Number is required") | ||
} | ||
if (this._complement.length === 0) { | ||
throw new Error("Complement is required") | ||
} | ||
if (this._city.length === 0) { | ||
throw new Error("City is required") | ||
} | ||
if (this._state.length === 0) { | ||
throw new Error("State is required") | ||
} | ||
if (this._zipCode.length === 0) { | ||
throw new Error("Zip code is required") | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,37 +1,47 @@ | ||
import AggregateRoot from "../../@shared/domain/entity/aggregate-root.interface"; | ||
import BaseEntity from "../../@shared/domain/entity/base.entity"; | ||
import Id from "../../@shared/domain/value-object/id.value-object"; | ||
import AggregateRoot from "../../@shared/domain/entity/aggregate-root.interface" | ||
import BaseEntity from "../../@shared/domain/entity/base.entity" | ||
import Address from "../../@shared/domain/value-object/address" | ||
import Id from "../../@shared/domain/value-object/id.value-object" | ||
|
||
type ClientProps = { | ||
id?: Id; | ||
name: string; | ||
email: string; | ||
address: string; | ||
createdAt?: Date; | ||
updatedAt?: Date; | ||
}; | ||
id?: Id | ||
name: string | ||
email: string | ||
document: string | ||
address: Address | ||
createdAt?: Date | ||
updatedAt?: Date | ||
} | ||
|
||
export default class Client extends BaseEntity implements AggregateRoot { | ||
private _name: string; | ||
private _email: string; | ||
private _address: string; | ||
|
||
private _name: string | ||
private _email: string | ||
private _document: string | ||
private _address: Address | ||
|
||
constructor(props: ClientProps) { | ||
super(props.id, props.createdAt, props.updatedAt); | ||
this._name = props.name; | ||
this._email = props.email; | ||
this._address = props.address; | ||
super(props.id, props.createdAt, props.updatedAt) | ||
this._name = props.name | ||
this._email = props.email | ||
this._document = props.document | ||
this._address = props.address | ||
} | ||
|
||
get name(): string { | ||
return this._name; | ||
return this._name | ||
} | ||
|
||
get email(): string { | ||
return this._email; | ||
return this._email | ||
} | ||
|
||
get address(): string { | ||
return this._address; | ||
get document(): string { | ||
return this._document | ||
} | ||
} | ||
|
||
get address(): Address { | ||
return this._address | ||
} | ||
|
||
} |
26 changes: 15 additions & 11 deletions
26
src/modules/client-adm/facade/client-adm.facade.interface.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
138 changes: 83 additions & 55 deletions
138
src/modules/client-adm/facade/client-adm.facade.spec.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 |
---|---|---|
@@ -1,81 +1,109 @@ | ||
import { Sequelize } from "sequelize-typescript"; | ||
import ClientAdmFacadeFactory from "../factory/client-adm.facade.factory"; | ||
import { ClientModel } from "../repository/client.model"; | ||
import ClientRepository from "../repository/client.repository"; | ||
import AddClientUseCase from "../usecase/add-client/add-client.usecase"; | ||
import FindClientUseCase from "../usecase/find-client/find-client.usecase"; | ||
import ClientAdmFacade from "./client-adm.facade"; | ||
import { Sequelize } from "sequelize-typescript" | ||
import { ClientModel } from "../repository/client.model" | ||
import ClientRepository from "../repository/client.repository" | ||
import AddClientUseCase from "../usecase/add-client/add-client.usecase" | ||
import ClientAdmFacade from "./client-adm.facade" | ||
import ClientAdmFacadeFactory from "../factory/client-adm.facade.factory" | ||
import Address from "../../@shared/domain/value-object/address" | ||
|
||
describe("ClientAdmFacade test", () => { | ||
let sequelize: Sequelize; | ||
|
||
describe("Client Adm Facade test", () => { | ||
|
||
let sequelize: Sequelize | ||
|
||
beforeEach(async () => { | ||
sequelize = new Sequelize({ | ||
dialect: "sqlite", | ||
storage: ":memory:", | ||
dialect: 'sqlite', | ||
storage: ':memory:', | ||
logging: false, | ||
sync: { force: true }, | ||
}); | ||
sync: { force: true } | ||
}) | ||
|
||
await sequelize.addModels([ClientModel]); | ||
await sequelize.sync(); | ||
}); | ||
sequelize.addModels([ClientModel]) | ||
await sequelize.sync() | ||
}) | ||
|
||
afterEach(async () => { | ||
await sequelize.close(); | ||
}); | ||
await sequelize.close() | ||
}) | ||
|
||
it("should create a client", async () => { | ||
const repository = new ClientRepository(); | ||
const addUsecase = new AddClientUseCase(repository); | ||
|
||
const repository = new ClientRepository() | ||
const addUsecase = new AddClientUseCase(repository) | ||
const facade = new ClientAdmFacade({ | ||
addUsecase: addUsecase, | ||
findUsecase: undefined, | ||
}); | ||
}) | ||
|
||
const input = { | ||
id: "1", | ||
name: "Client 1", | ||
email: "[email protected]", | ||
address: "Address 1", | ||
}; | ||
name: "Lucian", | ||
email: "[email protected]", | ||
document: "1234-5678", | ||
address: new Address( | ||
"Rua 123", | ||
"99", | ||
"Casa Verde", | ||
"Criciúma", | ||
"SC", | ||
"88888-888", | ||
) | ||
} | ||
|
||
await facade.add(input); | ||
await facade.add(input) | ||
|
||
const client = await ClientModel.findOne({ where: { id: "1" } }); | ||
const client = await ClientModel.findOne({ where: { id: "1" } }) | ||
|
||
expect(client).toBeDefined(); | ||
expect(client.name).toBe(input.name); | ||
expect(client.email).toBe(input.email); | ||
expect(client.address).toBe(input.address); | ||
}); | ||
expect(client).toBeDefined() | ||
expect(client.id).toBe(input.id) | ||
expect(client.name).toBe(input.name) | ||
expect(client.email).toBe(input.email) | ||
expect(client.document).toBe(input.document) | ||
expect(client.street).toBe(input.address.street) | ||
}) | ||
|
||
it("should find a client", async () => { | ||
// const repository = new ClientRepository(); | ||
// const findUsecase = new FindClientUseCase(repository); | ||
// const addUsecase = new AddClientUseCase(repository); | ||
|
||
// const repository = new ClientRepository() | ||
// const addUsecase = new AddClientUseCase(repository) | ||
// const findUseCase = new FindClientUseCase(repository) | ||
// const facade = new ClientAdmFacade({ | ||
// addUsecase: addUsecase, | ||
// findUsecase: findUsecase, | ||
// }); | ||
// addUseCase: addUsecase, | ||
// findUseCase: findUseCase | ||
// }) | ||
|
||
const facade = ClientAdmFacadeFactory.create(); | ||
const facade = ClientAdmFacadeFactory.create() | ||
|
||
const input = { | ||
id: "1", | ||
name: "Client 1", | ||
email: "[email protected]", | ||
address: "Address 1", | ||
}; | ||
|
||
await facade.add(input); | ||
|
||
const client = await facade.find({ id: "1" }); | ||
|
||
expect(client).toBeDefined(); | ||
expect(client.id).toBe(input.id); | ||
expect(client.name).toBe(input.name); | ||
expect(client.email).toBe(input.email); | ||
expect(client.address).toBe(input.address); | ||
}); | ||
}); | ||
name: "Lucian", | ||
email: "[email protected]", | ||
document: "1234-5678", | ||
address: new Address( | ||
"Rua 123", | ||
"99", | ||
"Casa Verde", | ||
"Criciúma", | ||
"SC", | ||
"88888-888" | ||
) | ||
} | ||
|
||
await facade.add(input) | ||
|
||
const client = await facade.find({ id: "1" }) | ||
|
||
expect(client).toBeDefined() | ||
expect(client.id).toBe(input.id) | ||
expect(client.name).toBe(input.name) | ||
expect(client.email).toBe(input.email) | ||
expect(client.document).toBe(input.document) | ||
expect(client.address.street).toBe(input.address.street) | ||
expect(client.address.number).toBe(input.address.number) | ||
expect(client.address.complement).toBe(input.address.complement) | ||
expect(client.address.city).toBe(input.address.city) | ||
expect(client.address.state).toBe(input.address.state) | ||
expect(client.address.zipCode).toBe(input.address.zipCode) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,26 +1,44 @@ | ||
import { Column, Model, PrimaryKey, Table } from "sequelize-typescript"; | ||
|
||
@Table({ | ||
tableName: "clients", | ||
timestamps: false, | ||
tableName: 'client', | ||
timestamps: false | ||
}) | ||
export class ClientModel extends Model { | ||
@PrimaryKey | ||
@Column({ allowNull: false }) | ||
id: string; | ||
id: string | ||
|
||
@Column({ allowNull: false }) | ||
name: string; | ||
name: string | ||
|
||
@Column({ allowNull: false }) | ||
email: string; | ||
email: string | ||
|
||
@Column({ allowNull: false }) | ||
address: string; | ||
document: string | ||
|
||
@Column({ allowNull: false }) | ||
createdAt: Date; | ||
street: string | ||
|
||
@Column({ allowNull: false }) | ||
updatedAt: Date; | ||
} | ||
number: string | ||
|
||
@Column({ allowNull: true }) | ||
complement: string | ||
|
||
@Column({ allowNull: false }) | ||
city: string | ||
|
||
@Column({ allowNull: false }) | ||
state: string | ||
|
||
@Column({ allowNull: false }) | ||
zipcode: string | ||
|
||
@Column({ allowNull: false }) | ||
createdAt: Date | ||
|
||
@Column({ allowNull: false }) | ||
updatedAt: Date | ||
} |
Oops, something went wrong.