Skip to content

Commit

Permalink
fix: corrige registro de refeições
Browse files Browse the repository at this point in the history
  • Loading branch information
larissaperinoto committed Jul 9, 2024
1 parent 1af5d49 commit ce5c0d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/app/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class WebsocketService {

getOrder() {
return new Observable((observer) => {
this.socket.on('meals', (message) => {
this.socket.on('meal', (message) => {
observer.next(message);
});
});
Expand Down
21 changes: 10 additions & 11 deletions server/src/services/Meal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ export class Meal {
for (const scale of this.buffet.scaleList) {
const currentWeight = scale.getCurrentWeight();
let previousWeight = scale.getPreviousWeight();
let measureSeconds = scale.getMeasureSeconds();
let measuredSeconds = scale.getMeasuredSeconds();

if (previousWeight === currentWeight && currentWeight > 0) {
measureSeconds = measureSeconds += time;
if (previousWeight === currentWeight) {
measuredSeconds = measuredSeconds += time;
} else {
measureSeconds = 0;
measuredSeconds = 0;
}

scale.setMeasuredSeconds(measuredSeconds);

const buffetType = this.generateBuffetType(currentWeight);
const total = this.generateTotal(currentWeight);

Expand All @@ -30,22 +32,19 @@ export class Meal {

const datetime = new Date().toLocaleString("pt-BR");

if (measureSeconds >= orderSeconds) {
if (measuredSeconds >= orderSeconds) {
this.socket.emit(
"order",
"meal",
JSON.stringify({
weight: currentWeight,
buffetType,
total,
datetime,
})
);
previousWeight = 0;
measureSeconds = 0;
scale.setPreviosWeight(0);
scale.setMeasuredSeconds(0);
}

scale.setMeasureseconds(measureSeconds);
scale.setPreviosWeight(previousWeight);
}
}, time);
}
Expand Down
10 changes: 5 additions & 5 deletions server/src/services/Scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Scale {
private serialPort: SerialPort;
private unitOfMeasurement = "";
private currentWeight = 0;
private measureSeconds = 0;
private measuredSeconds = 0;
private previosWeight = 0;

constructor(
Expand Down Expand Up @@ -54,11 +54,11 @@ export class Scale {
this.previosWeight = weight;
}

public getMeasureSeconds(): number {
return this.measureSeconds;
public getMeasuredSeconds(): number {
return this.measuredSeconds;
}

public setMeasureseconds(seconds: number): void {
this.measureSeconds = seconds;
public setMeasuredSeconds(seconds: number): void {
this.measuredSeconds = seconds;
}
}

0 comments on commit ce5c0d5

Please sign in to comment.