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
112 changes: 112 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions apis/maintenanceCommand/Domain/Entities/incident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 3 additions & 0 deletions apis/maintenanceCommand/Domain/Entities/maintenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@ export class Maintenance implements MaintenanceInterface {
scooterId: string,
technicianId: string,
type: MaintenanceType,
warranty: boolean,
date: Date,
details: string,
cost: number,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum MaintenanceType {
PREVENT = 'préventive',
CORRECTIF = 'corrective'
CORRECTIF = 'corrective',
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MaintenanceType } from "../../../domain/enums";
import { MaintenanceType } from '../../../domain/enums';

export interface CreateMaintenanceDTO {
scooterId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Incident } from '../../domain/entities';

export interface IncidentRepositoryInterface {
searchByScooterId(scooterId: string): Promise<Incident[]>;
findByTestRideId(testRideId: string): Promise<Incident[]>;
save(incident: Incident): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ export interface MaintenanceRepositoryInterface {
findByScooterId(scooterId: string): Promise<Maintenance[]>;
findById(id: string): Promise<Maintenance>;
save(maintenance: Maintenance): Promise<void>;
searchByScooterId(scooterId: string): Promise<Maintenance[]>;
searchById(id: string): Promise<Maintenance | null>;
searchAll(): Promise<Maintenance[]>;
update(maintenance: Maintenance): Promise<void>;
delete(id: string): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Scooter } from '../../domain/entities';

export interface ScooterRepositoryInterface {
findById(id: string): Promise<Scooter | null>;
findAll(): Promise<Scooter[]>;
save(scooter: Scooter): Promise<void>;
update(scooter: Scooter): Promise<void>;
delete(id: string): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { StockPiece } from '../../domain/entities';

export interface StockRepositoryInterface {
findAll(): Promise<StockPiece[]>;
findById(id: string): Promise<StockPiece | null>;
findByName(name: string): Promise<StockPiece | null>;
save(stockPiece: StockPiece): Promise<void>;
update(stockPiece: StockPiece): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void | Error> {
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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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);
}
}
Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
@@ -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<Maintenance | Error> {
if (!dto || !dto.id) {
throw new BadRequestError();
}

const maintenance: Maintenance | null = await this.maintenanceRepository.searchById(dto.id);
if (!maintenance) {
throw new NotFoundError();
}
return maintenance;
}
}
File renamed without changes.
Loading