Skip to content

Commit

Permalink
Fix robot creation is duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
gdepuille committed Apr 27, 2024
1 parent 47da95a commit e227cfa
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/services/RobotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { Cacheable } from 'typescript-cacheable';
import { Inject, Singleton } from 'typescript-ioc';
import { Robot } from '../models/Robot';
import { Config } from './Config';
import { Logger } from './Logger';

@Singleton
export class RobotService {

@Inject
private config: Config;

@Inject
private log: Logger;

buildDir(robot: Robot): string {
if (robot.simulateur) {
return `${this.config.logsOutput}-simulateur/${robot.name.toLowerCase()}`;
Expand All @@ -34,16 +38,27 @@ export class RobotService {
init() {
Robot.findAll()
.then((robots) => {
const hasNerell = robots.find(r => r.name === 'Nerell' && !r.simulateur);
const hasNerellSimu = robots.find(r => r.name === 'Nerell' && r.simulateur);
//const hasOdin = robots.find(r => r.name === 'Odin' && !r.simulateur);
//const hasOdinSimu = robots.find(r => r.name === 'Odin' && r.simulateur);
const hasPamiTriangle = robots.find(r => r.name === 'Pami Triangle' && !r.simulateur);
const hasPamiTriangleSimu = robots.find(r => r.name === 'Pami Triangle' && r.simulateur);
const hasPamiCarre = robots.find(r => r.name === 'Pami Carre' && !r.simulateur);
const hasPamiCarreSimu = robots.find(r => r.name === 'Pami Carre' && r.simulateur);
const hasPamiRond = robots.find(r => r.name === 'Pami Rond' && !r.simulateur);
const hasPamiRondSimu = robots.find(r => r.name === 'Pami Rond' && r.simulateur);
const hasNerell = robots.find(r => r.name === 'Nerell' && !r.simulateur) !== undefined;
const hasNerellSimu = robots.find(r => r.name === 'Nerell' && r.simulateur) !== undefined;
const hasOdin = robots.find(r => r.name === 'Odin' && !r.simulateur) !== undefined;
const hasOdinSimu = robots.find(r => r.name === 'Odin' && r.simulateur) !== undefined;
const hasPamiTriangle = robots.find(r => r.name === 'Pami △' && !r.simulateur) !== undefined;
const hasPamiTriangleSimu = robots.find(r => r.name === 'Pami △' && r.simulateur) !== undefined;
const hasPamiCarre = robots.find(r => r.name === 'Pami ▢' && !r.simulateur) !== undefined;
const hasPamiCarreSimu = robots.find(r => r.name === 'Pami ▢' && r.simulateur) !== undefined;
const hasPamiRond = robots.find(r => r.name === 'Pami ○' && !r.simulateur) !== undefined;
const hasPamiRondSimu = robots.find(r => r.name === 'Pami ○' && r.simulateur) !== undefined;

this.log.info(`Nerell found : ${hasNerell}`)
this.log.info(`Nerell simu found : ${hasNerellSimu}`)
this.log.info(`Odin found : ${hasOdin}`)
this.log.info(`Odin simu found : ${hasOdinSimu}`)
this.log.info(`Pami Triangle found : ${hasPamiTriangle}`)
this.log.info(`Pami Triangle simu found : ${hasPamiTriangleSimu}`)
this.log.info(`Pami Carre found : ${hasPamiCarre}`)
this.log.info(`Pami Carre simu found : ${hasPamiCarreSimu}`)
this.log.info(`Pami Rond found : ${hasPamiRond}`)
this.log.info(`Pami Rond simu found : ${hasPamiRondSimu}`)

if (!hasNerell) {
new Robot({
Expand Down

0 comments on commit e227cfa

Please sign in to comment.