Skip to content
Merged
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
18 changes: 0 additions & 18 deletions backend/knexfile.js

This file was deleted.

20 changes: 0 additions & 20 deletions backend/migrations/20241222141816_create_dealers_table.js

This file was deleted.

18 changes: 0 additions & 18 deletions backend/migrations/20241222141909_create_spare_parts_table.js

This file was deleted.

22 changes: 0 additions & 22 deletions backend/migrations/20241222141910_create_order_table.js

This file was deleted.

23 changes: 0 additions & 23 deletions backend/migrations/20241222142304_create_order_lines_table.js

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Dealer } from "@domain/inventoryManagement/entities/Dealer";
import { DealerAddress } from "@domain/inventoryManagement/value-object/DealerAddress";
import { RegisterDealerEvent } from "@domain/inventoryManagement/events/RegisterDealerEvent";
import { Address } from "@domain/shared/value-object/Address";
import { Siret } from '@domain/shared/value-object/Siret';
import { IInputUseCase, IUseCase } from "@shared/IUseCase";
import { Result } from "@shared/Result";
import { DealerRepository } from "../../repositories/DealerRepository";
import {EventRepository} from "../../../shared/repositories/EventRepository";
import {RegisterDealerEvent} from "@domain/inventoryManagement/events/RegisterDealerEvent";
import { EventRepository } from "../../../shared/repositories/EventRepository";

interface RegisterDealerInput extends IInputUseCase {
siret: Siret,
name: string,
address: DealerAddress,
address: Address,
phoneNumber: string
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { AbstractProjection } from "@application/shared/projections/AbstractProjection";
import { ProjectionJobScheduler } from "@application/shared/projections/ProjectionJobScheduler";
import { Customer } from "@domain/maintenance/entities/Customer";
import { RegisterCustomerEvent } from "@domain/maintenance/events/RegisterCustomerEvent";
import { UnregisterCustomerEvent } from "@domain/maintenance/events/UnregisterCustomerEvent";
import { UpdateCustomerEvent } from "@domain/maintenance/events/UpdateCustomerEvent";
import { Result, VoidResult } from "@shared/Result";
import { CustomerRepository } from "../repositories/CustomerRepository";

export class CustomerProjection extends AbstractProjection {
constructor(private _customerRepository: CustomerRepository) {
super();
}

init(projectionJobScheduler: ProjectionJobScheduler) {
projectionJobScheduler.schedule(RegisterCustomerEvent.type, this.constructor.name)
projectionJobScheduler.schedule(UpdateCustomerEvent.type, this.constructor.name)
projectionJobScheduler.schedule(UnregisterCustomerEvent.type, this.constructor.name)

}

bindEvents() {
return {
[RegisterCustomerEvent.type]: this.applyRegisterEvent,
[UpdateCustomerEvent.type]: this.applyUpdateEvent,
[UnregisterCustomerEvent.type]: this.applyUnregisteredEvent
}
}

async applyRegisterEvent(event: RegisterCustomerEvent): Promise<VoidResult> {
const customer = Customer.fromObject(event.payload)
if (customer instanceof Error) return Result.FailureStr("Cannot register customer");
return this._customerRepository.store(customer)
}

async applyUnregisteredEvent(event: UnregisterCustomerEvent): Promise<VoidResult> {
const response = await this._customerRepository.find(event.payload.customerId)
if (!response.success) return Result.FailureStr("Cannot delete customer")
return this._customerRepository.delete(event.payload.customerId)
}

async applyUpdateEvent(event: UpdateCustomerEvent): Promise<VoidResult> {
const customer = await this._customerRepository.find(event.payload.customerId)
if (!customer.success) return Result.FailureStr("Cannot update customer")

const updatedCustomer = Customer.fromObject({
...customer,
...event.payload
})
if (updatedCustomer instanceof Error) return Result.FailureStr("Cannot update customer")
return this._customerRepository.store(updatedCustomer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Customer } from "@domain/maintenance/entities/Customer";
import { IRepository } from "@shared/IRepository";
import { Result, VoidResult } from "@shared/Result";

export interface CustomerRepository extends IRepository {
find(customerId: string): Promise<Result<Customer>>;
store(customer: Customer): Promise<VoidResult>;
delete(customerId: string): Promise<VoidResult>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Garage } from '../../../domain/maintenance/entities/Garage';
import { Siret } from '../../../domain/shared/value-object/Siret';
import { IRepository } from '../../../shared/IRepository';
import { Result, VoidResult } from '../../../shared/Result';

export interface GarageRepository extends IRepository {
getBySiret(siret: Siret): Promise<Result<Garage>>
store(garage: Garage): Promise<VoidResult>;
delete(siret: Siret): Promise<VoidResult>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CustomerRepository } from "@application/maintenance/repositories/CustomerRepository";
import { EventRepository } from "@application/shared/repositories/EventRepository";
import { UnregisterCustomerEvent } from '@domain/maintenance/events/UnregisterCustomerEvent';
import { IInputUseCase, IUseCase } from "@shared/IUseCase";
import { Result } from "@shared/Result";

interface DeleteCustomerUseCaseInput extends IInputUseCase {
customerId: string
}

export type DeleteCustomerUseCase = IUseCase<DeleteCustomerUseCaseInput, Result>
export const createDeleteCustomerUseCase = (_eventRepository: EventRepository, _customerRepository: CustomerRepository): DeleteCustomerUseCase => {
return async (input: DeleteCustomerUseCaseInput) => {
const findResponse = await _customerRepository.find(input.customerId);
if (!findResponse.success) return Result.FailureStr("Customer not found")

const unregisterCustomerEvent = new UnregisterCustomerEvent({
customerId: input.customerId
})
const deleteResponse = await _eventRepository.storeEvent(unregisterCustomerEvent);
if (!deleteResponse.success) return Result.FailureStr("Cannot delete customer")
return Result.Success("Customer deleted")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { EventRepository } from "@application/shared/repositories/EventRepository";
import { RegisterCustomerEvent } from "@domain/maintenance/events/RegisterCustomerEvent";
import { randomUUID } from "crypto";
import { CustomerAddress } from "@domain/maintenance/value-object/CustomerAddress";
import { IInputUseCase, IUseCase } from "@shared/IUseCase";
import { Result } from "@shared/Result";

interface RegisterCustomerInput extends IInputUseCase {
name: string,
phoneNumber: string,
email: string
address: CustomerAddress
}

export type RegisterCustomerUseCase = IUseCase<RegisterCustomerInput, Result>
export const createRegisterCustomerUseCase = (_eventRepository: EventRepository): RegisterCustomerUseCase => {
return async (input: RegisterCustomerInput) => {
const registerCustomerEvent = new RegisterCustomerEvent({
customerId: randomUUID(),
name: input.name,
phoneNumber: input.phoneNumber,
email: input.email,
address: input.address
})
const storeResponse = await _eventRepository.storeEvent(registerCustomerEvent);
if (!storeResponse.success) return Result.FailureStr("Cannot register customer")
return Result.Success("Customer registered")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Customer } from '@domain/maintenance/entities/Customer';
import { IInputUseCase, IUseCase } from "@shared/IUseCase";
import { Result } from '@shared/Result';
import { CustomerRepository } from '../../repositories/CustomerRepository';

interface ShowCustomerInput extends IInputUseCase {
customerId: string,
}

type ShowCustomerResult = Result<Customer>
export type ShowCustomerUseCase = IUseCase<ShowCustomerInput, ShowCustomerResult>
export const createShowCustomerUseCase = (_customerRepository: CustomerRepository): ShowCustomerUseCase => {
return async (input: ShowCustomerInput) => {
const findResponse = await _customerRepository.find(input.customerId);
if (!findResponse.success) return Result.FailureStr("Customer not found")
return findResponse
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Siret } from "../../../../domain/shared/value-object/Siret";
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from "../../../../shared/Result";
import { GarageRepository } from "../../repositories/GarageRepository";

interface DeleteGarageInput extends IInputUseCase {
siret: Siret,
}

export type DeleteGarageUseCase = IUseCase<DeleteGarageInput, Result>
export const deleteGarageUseCase = (_garageRepository: GarageRepository): DeleteGarageUseCase => {

// @TODO : Add logic to delete the link with a Dealer if exist

return async (input: DeleteGarageInput) => {
const deleteResponse = await _garageRepository.delete(input.siret)
if (!deleteResponse.success) return Result.FailureStr("Cannot delete garage")
return Result.Success("Garage deleted")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { GarageRepository } from '@application/maintenance/repositories/GarageRepository';
import { Siret } from '@domain/shared/value-object/Siret';
import { IInputUseCase, IUseCase } from '@shared/IUseCase';
import { Result } from '@shared/Result';

interface RegisterGarageInput extends IInputUseCase {
siret: Siret,
name: string,
phoneNumber: string,
}

export type RegisterGarageUseCase = IUseCase<RegisterGarageInput, Result>
export const registerGarageUseCAse = (_garageRepository: GarageRepository): RegisterGarageUseCase => {
return async (input: RegisterGarageInput) => {
// const garage = new Garage(
// input.siret,
// input.name,
// input.phoneNumber,
// );
// const storeResponse = await _garageRepository.store(garage);
// if (!storeResponse.success) return Result.FailureStr("Cannot register garage");
return Result.Success("Garage Registered");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { GarageRepository } from "@application/maintenance/repositories/GarageRepository";
import { Garage } from "@domain/maintenance/entities/Garage";
import { Siret } from '@domain/shared/value-object/Siret';
import { IInputUseCase, IUseCase } from "@shared/IUseCase";
import { Result } from "@shared/Result";

interface ShowGarageInput extends IInputUseCase {
siret: Siret
}

type ShowGarageResult = Result<Garage>
export type ShowGarageUseCase = IUseCase<ShowGarageInput, ShowGarageResult>
export const showGarageUseCase = (_garageRepository: GarageRepository): ShowGarageUseCase => {
return async (input: ShowGarageInput) => {
const findResponse = await _garageRepository.getBySiret(input.siret);
if (!findResponse.success) return Result.FailureStr("Garage not found")
return findResponse
}
}
Loading
Loading