diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..4dcdacf --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,112 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI + +on: [push] + +jobs: + build: + name: node_build_job + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - name: Checkout repository + uses: actions/checkout@v4 # Récupère le code de votre repo + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Move & Install API dependencies + run: cd apis/authCommand && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/authCommand && npm run build --if-present + + - name: Run tests + run: cd apis/authCommand && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/authQuery && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/authQuery && npm run build --if-present + + - name: Run tests + run: cd apis/authQuery && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/gateway && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/gateway && npm run build --if-present + + - name: Run tests + run: cd apis/gateway && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/maintenanceCommand && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/maintenanceCommand && npm run build --if-present + + - name: Run tests + run: cd apis/maintenanceCommand && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/maintenanceQuery && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/maintenanceQuery && npm run build --if-present + + - name: Run tests + run: cd apis/maintenanceQuery && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/reservationCommand && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/reservationCommand && npm run build --if-present + + - name: Run tests + run: cd apis/reservationCommand && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/reservationQuery && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/reservationQuery && npm run build --if-present + + - name: Run tests + run: cd apis/reservationQuery && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/stockCommand && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/stockCommand && npm run build --if-present + + - name: Run tests + run: cd apis/stockCommand && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install API dependencies + run: cd apis/stockQuery && npm ci # Installe les dépendances du projet + + - name: Build + run: cd apis/stockQuery && npm run build --if-present + + - name: Run tests + run: cd apis/stockQuery && npm run test --if-present # Commande pour lancer vos tests Vitest, modifiez selon votre script de test + + - name: Move & Install Client dependencies + run: cd client && npm ci # Installe les dépendances du projet + + - name: Build + run: cd client && npm run build --if-present \ No newline at end of file diff --git a/apis/maintenanceCommand/Domain/Entities/incident.ts b/apis/maintenanceCommand/Domain/Entities/incident.ts index c4674ee..6e902d7 100644 --- a/apis/maintenanceCommand/Domain/Entities/incident.ts +++ b/apis/maintenanceCommand/Domain/Entities/incident.ts @@ -38,4 +38,11 @@ export class Incident implements IncidentInterface { this.reportedAt = reportedAt; this.resolvedAt = resolvedAt; } + + public timeToResolve(): number { + if (this.resolvedAt) { + return this.resolvedAt.getTime() - this.reportedAt.getTime(); + } + return new Date().getTime() - this.reportedAt.getTime(); + } } diff --git a/apis/maintenanceCommand/Domain/Entities/maintenance.ts b/apis/maintenanceCommand/Domain/Entities/maintenance.ts index 3391a37..0df4877 100644 --- a/apis/maintenanceCommand/Domain/Entities/maintenance.ts +++ b/apis/maintenanceCommand/Domain/Entities/maintenance.ts @@ -7,6 +7,7 @@ export class Maintenance implements MaintenanceInterface { public scooterId: string; public technicianId: string; public type: MaintenanceType; + public warranty: boolean; public date: Date; public details: string; public cost: number; @@ -15,6 +16,7 @@ export class Maintenance implements MaintenanceInterface { scooterId: string, technicianId: string, type: MaintenanceType, + warranty: boolean, date: Date, details: string, cost: number, @@ -24,6 +26,7 @@ export class Maintenance implements MaintenanceInterface { this.scooterId = scooterId; this.technicianId = technicianId; this.type = type; + this.warranty = warranty; this.date = date; this.details = details; this.cost = cost; diff --git a/apis/maintenanceCommand/Domain/enums/maintenance.type.enum.ts b/apis/maintenanceCommand/Domain/enums/maintenance.type.enum.ts index 6811e02..575d23e 100644 --- a/apis/maintenanceCommand/Domain/enums/maintenance.type.enum.ts +++ b/apis/maintenanceCommand/Domain/enums/maintenance.type.enum.ts @@ -1,4 +1,4 @@ export enum MaintenanceType { PREVENT = 'préventive', - CORRECTIF = 'corrective' + CORRECTIF = 'corrective', } \ No newline at end of file diff --git a/apis/maintenanceCommand/application/dtos/maintenance/create.maintenance.dto.ts b/apis/maintenanceCommand/application/dtos/maintenance/create.maintenance.dto.ts index 9ec6c52..84c62d0 100644 --- a/apis/maintenanceCommand/application/dtos/maintenance/create.maintenance.dto.ts +++ b/apis/maintenanceCommand/application/dtos/maintenance/create.maintenance.dto.ts @@ -1,4 +1,4 @@ -import { MaintenanceType } from "../../../domain/enums"; +import { MaintenanceType } from '../../../domain/enums'; export interface CreateMaintenanceDTO { scooterId: string; diff --git a/apis/maintenanceCommand/application/ports/incident.repository.interface.ts b/apis/maintenanceCommand/application/ports/incident.repository.interface.ts new file mode 100644 index 0000000..b1335a0 --- /dev/null +++ b/apis/maintenanceCommand/application/ports/incident.repository.interface.ts @@ -0,0 +1,7 @@ +import { Incident } from '../../domain/entities'; + +export interface IncidentRepositoryInterface { + searchByScooterId(scooterId: string): Promise; + findByTestRideId(testRideId: string): Promise; + save(incident: Incident): Promise; +} \ No newline at end of file diff --git a/apis/maintenanceCommand/application/ports/maintenance.repository.interface.ts b/apis/maintenanceCommand/application/ports/maintenance.repository.interface.ts index 8190491..bfa2eaf 100644 --- a/apis/maintenanceCommand/application/ports/maintenance.repository.interface.ts +++ b/apis/maintenanceCommand/application/ports/maintenance.repository.interface.ts @@ -4,4 +4,9 @@ export interface MaintenanceRepositoryInterface { findByScooterId(scooterId: string): Promise; findById(id: string): Promise; save(maintenance: Maintenance): Promise; + searchByScooterId(scooterId: string): Promise; + searchById(id: string): Promise; + searchAll(): Promise; + update(maintenance: Maintenance): Promise; + delete(id: string): Promise; } diff --git a/apis/maintenanceCommand/application/ports/scooter.repository.interface.ts b/apis/maintenanceCommand/application/ports/scooter.repository.interface.ts new file mode 100644 index 0000000..7c29df1 --- /dev/null +++ b/apis/maintenanceCommand/application/ports/scooter.repository.interface.ts @@ -0,0 +1,9 @@ +import { Scooter } from '../../domain/entities'; + +export interface ScooterRepositoryInterface { + findById(id: string): Promise; + findAll(): Promise; + save(scooter: Scooter): Promise; + update(scooter: Scooter): Promise; + delete(id: string): Promise; +} diff --git a/apis/maintenanceCommand/application/ports/stock.repository.interface.ts b/apis/maintenanceCommand/application/ports/stock.repository.interface.ts new file mode 100644 index 0000000..0170f20 --- /dev/null +++ b/apis/maintenanceCommand/application/ports/stock.repository.interface.ts @@ -0,0 +1,9 @@ +import { StockPiece } from '../../domain/entities'; + +export interface StockRepositoryInterface { + findAll(): Promise; + findById(id: string): Promise; + findByName(name: string): Promise; + save(stockPiece: StockPiece): Promise; + update(stockPiece: StockPiece): Promise; +} diff --git a/apis/maintenanceCommand/application/usecase/maintenance/Plan.maintenance.usecase.ts b/apis/maintenanceCommand/application/usecase/maintenance/Plan.maintenance.usecase.ts index 23dd5b5..4b4e87e 100644 --- a/apis/maintenanceCommand/application/usecase/maintenance/Plan.maintenance.usecase.ts +++ b/apis/maintenanceCommand/application/usecase/maintenance/Plan.maintenance.usecase.ts @@ -1,15 +1,25 @@ -import { MaintenanceRepository } from '../../ports'; -import { Maintenance } from '../../../domain/entities'; -import { ScooterRepository } from '../../ports'; -import { Scooter } from '../../../domain/entities'; +import { Maintenance, Scooter, Warranty } from '../../../domain/entities'; import { MaintenanceType } from '../../../domain/enums'; +import { BadRequestError } from '../../../../authCommand/application/errors'; +import { MaintenanceRepositoryInterface, ScooterRepositoryInterface } from '../../ports'; +import { CreateMaintenanceDTO } from '../../dtos/maintenance'; export class PlanifierMaintenanceUseCase { - constructor(private scooterRepo: ScooterRepository, private maintenanceRepo: MaintenanceRepository) {} - async execute(scooterId: string): Promise { - const scooter = await this.scooterRepo.findById(scooterId); - if (!scooter) throw new Error("Scooter introuvable"); + private scooterRepo: ScooterRepositoryInterface; + private maintenanceRepo: MaintenanceRepositoryInterface; + + constructor(scooterRepo: ScooterRepositoryInterface, maintenanceRepo: MaintenanceRepositoryInterface) { + this.scooterRepo = scooterRepo; + this.maintenanceRepo = maintenanceRepo; + } + + async execute(dto: CreateMaintenanceDTO): Promise { + if (!dto || !dto.scooterId || !dto.technicianId) { + throw new BadRequestError(); + } + const scooter = await this.scooterRepo.findById(dto.scooterId); + if (!scooter) throw new BadRequestError(); let needsMaintenance = false; let maintenanceType = MaintenanceType.PREVENT; @@ -28,10 +38,12 @@ export class PlanifierMaintenanceUseCase { if (needsMaintenance) { const maintenance = new Maintenance( scooter.id, + dto.technicianId, maintenanceType, + true, new Date(), details, - 0 // Coût inconnu pour l’instant + 0, ); await this.maintenanceRepo.save(maintenance); } diff --git a/apis/maintenanceCommand/application/usecase/maintenance/delete.maintenance.usecase.ts b/apis/maintenanceCommand/application/usecase/maintenance/delete.maintenance.usecase.ts index e69de29..ff5a0fa 100644 --- a/apis/maintenanceCommand/application/usecase/maintenance/delete.maintenance.usecase.ts +++ b/apis/maintenanceCommand/application/usecase/maintenance/delete.maintenance.usecase.ts @@ -0,0 +1,24 @@ +import { BadRequestError, NotFoundError } from "../../../../authCommand/application/errors"; +import { MaintenanceRepositoryInterface } from "../../ports"; +import { DeleteMaintenanceDTO } from "../../dtos/maintenance"; + + +export class DeleteMaintenanceUseCase { + + private maintenanceRepo: MaintenanceRepositoryInterface; + + constructor(maintenanceRepo: MaintenanceRepositoryInterface) { + this.maintenanceRepo = maintenanceRepo; + } + + async execute(dto: DeleteMaintenanceDTO): Promise { + if (!dto.id) { + throw new BadRequestError(); + } + const maintenance = await this.maintenanceRepo.searchById(dto.id); + if (!maintenance) { + throw new NotFoundError(); + } + await this.maintenanceRepo.delete(maintenance.id); + } +} \ No newline at end of file diff --git a/apis/maintenanceCommand/application/usecase/maintenance/index.ts b/apis/maintenanceCommand/application/usecase/maintenance/index.ts new file mode 100644 index 0000000..b8305cf --- /dev/null +++ b/apis/maintenanceCommand/application/usecase/maintenance/index.ts @@ -0,0 +1,8 @@ +export * from "./Plan.maintenance.usecase"; +export * from "./Alert.maintenance.usecase"; +export * from "./delete.maintenance.usecase"; +export * from "./search.maintenance.usecase"; +export * from "./searchHistory.maintenance.usecase"; +export * from "./troubleshooting.maintenance.usecase"; +export * from "./update.maintenance.usecase"; +export * from "./warranty.maintenance.usecase"; \ No newline at end of file diff --git a/apis/maintenanceCommand/application/usecase/maintenance/search.maintenance.usecase.ts b/apis/maintenanceCommand/application/usecase/maintenance/search.maintenance.usecase.ts index e69de29..9cd900f 100644 --- a/apis/maintenanceCommand/application/usecase/maintenance/search.maintenance.usecase.ts +++ b/apis/maintenanceCommand/application/usecase/maintenance/search.maintenance.usecase.ts @@ -0,0 +1,26 @@ +import { MaintenanceRepositoryInterface } from "../../ports"; +import { Maintenance } from "../../../domain/entities"; +import { ReadMaintenanceDTO } from "../../dtos/maintenance"; +import { BadRequestError, NotFoundError } from "../../../../authCommand/application/errors"; + + +export class SearchMaintenanceUseCase { + + private maintenanceRepository: MaintenanceRepositoryInterface; + + constructor(maintenanceRepository: MaintenanceRepositoryInterface) { + this.maintenanceRepository = maintenanceRepository; + } + + async execute(dto: ReadMaintenanceDTO): Promise { + if (!dto || !dto.id) { + throw new BadRequestError(); + } + + const maintenance: Maintenance | null = await this.maintenanceRepository.searchById(dto.id); + if (!maintenance) { + throw new NotFoundError(); + } + return maintenance; + } +} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/apis/stockCommand/application/usecases/scooter/getall.scooter.usecase.ts similarity index 100% rename from .github/workflows/ci.yml rename to apis/stockCommand/application/usecases/scooter/getall.scooter.usecase.ts