Skip to content

Commit dc2e2de

Browse files
committed
Add migration to update Yemot texts and refactor messages in YemotHandlerService
1 parent 38e4fb0 commit dc2e2de

2 files changed

Lines changed: 44 additions & 23 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class UpdateYemotTexts1780395303129 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`DELETE FROM \`texts\` WHERE 1 = 1`);
6+
7+
const texts = [
8+
{ name: 'GENERAL.YES', text: 'הקישי 1 - כן' },
9+
{ name: 'GENERAL.NO', text: 'הקישי 2 - לא' },
10+
{ name: 'GENERAL.INVALID_INPUT', text: 'הקשה לא תקינה, נסי שוב' },
11+
{ name: 'SYSTEM.CLOSED', text: 'המערכת סגורה. לא ניתן לדווח אחרי השעה תשע וחצי בבוקר. המשך יום טוב.' },
12+
{ name: 'SYSTEM.REPORT_SUCCESS', text: 'דווח בהצלחה' },
13+
{ name: 'SYSTEM.LATE_DEPARTURE', text: 'יצאת מאוחר מידי. המשך יום טוב.' },
14+
{ name: 'STUDENT.TZ_PROMPT', text: 'הקישי מספר תעודת זהות' },
15+
{ name: 'STUDENT.INVALID_TZ', text: 'מספר תעודת הזהות לא תקין, נסי שוב' },
16+
{ name: 'STUDENT.ALREADY_REPORTED', text: 'כבר דיווחת היום, לא ניתן לדווח פעמיים.' },
17+
{ name: 'STUDENT.NO_CLASS', text: 'התלמידה אינה משויכת לכיתה.' },
18+
{ name: 'TRANSPORT.NUM_PROMPT', text: 'הקישי מספר הסעה' },
19+
{ name: 'TRANSPORT.INVALID_NUM', text: 'מספר הסעה לא תקין, נסי שוב' },
20+
{ name: 'TRANSPORT.DEPARTURE_CONFIRM', text: 'האם יצאת לדרך לפני השעה {departureTime}? {yes} {no}' },
21+
];
22+
23+
for (const text of texts) {
24+
await queryRunner.query(
25+
'INSERT INTO `texts` (`user_id`, `name`, `description`, `value`) VALUES (?, ?, ?, ?)',
26+
[0, text.name, text.text, text.text],
27+
);
28+
}
29+
}
30+
31+
public async down(queryRunner: QueryRunner): Promise<void> {
32+
}
33+
}

‎server/src/yemot-handler.service.ts‎

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ export class YemotHandlerService extends BaseYemotHandlerService {
1616
await this.getUserByDidPhone();
1717
this.logger.log(`Processing call with ID: ${this.call.callId} from phone: ${this.call.phone}`);
1818
if (await this.isPastReportingDeadline()) {
19-
await this.hangupWithMessage('המערכת סגורה. לא ניתן לדווח אחרי השעה תשע וחצי בבוקר. המשך יום טוב.');
19+
await this.hangupWithMessageByKey('SYSTEM.CLOSED');
2020
return;
2121
}
2222
const student = await this.getStudentByInput();
2323
if (!student) return;
2424
const alreadyReported = await this.hasReportedToday(student.id);
2525
if (alreadyReported) {
26-
await this.hangupWithMessage('כבר דיווחת היום, לא ניתן לדווח פעמיים.');
26+
await this.hangupWithMessageByKey('STUDENT.ALREADY_REPORTED');
2727
return;
2828
}
2929
const transportation = await this.getTransportByInput();
3030
if (!transportation) return;
3131
const isValid = await this.isDepartureTimeValid(transportation);
3232
if (isValid) {
3333
await this.createAbsenceRecord(student, transportation);
34-
await this.hangupWithMessage('דווח בהצלחה');
34+
await this.hangupWithMessageByKey('SYSTEM.REPORT_SUCCESS');
3535
} else {
36-
await this.hangupWithMessage('יצאת מאוחר מידי המשך יום טוב');
36+
await this.hangupWithMessageByKey('SYSTEM.LATE_DEPARTURE');
3737
}
3838
}
3939
private isPastReportingDeadline(): boolean {
@@ -51,13 +51,13 @@ export class YemotHandlerService extends BaseYemotHandlerService {
5151
student = await this.getStudentByTz();
5252

5353
if (!student) {
54-
await this.sendMessage('מספר תעודת הזהות לא תקין נסי שוב');
54+
await this.sendMessageByKey('STUDENT.INVALID_TZ');
5555
}
5656
}
5757
return student;
5858
}
5959
private async getStudentByTz(): Promise<Student> {
60-
const tz = await this.askForInput('הקישי מספר תעודת זהות');
60+
const tz = await this.askForInputByKey('STUDENT.TZ_PROMPT');
6161
const student = await this.dataSource.getRepository(Student).findOneBy({
6262
userId: this.user.id,
6363
tz: tz,
@@ -91,36 +91,24 @@ export class YemotHandlerService extends BaseYemotHandlerService {
9191
transportation = await this.getTransportByNum();
9292

9393
if (!transportation) {
94-
await this.sendMessage(' מספר הסעה לא תקין, נסי שוב');
94+
await this.sendMessageByKey('TRANSPORT.INVALID_NUM');
9595
}
9696
}
9797

9898
return transportation;
9999
}
100100

101101
private async getTransportByNum(): Promise<Transportation> {
102-
const num = await this.askForInput('הקישי מספר הסעה');
102+
const num = await this.askForInputByKey('TRANSPORT.NUM_PROMPT');
103103
const transportation = await this.dataSource.getRepository(Transportation).findOneBy({
104104
userId: this.user.id,
105105
key: Number(num),
106106
});
107107
return transportation;
108108
}
109109

110-
private async isDepartureTimeValid(transportation): Promise<boolean> {
111-
let valid: boolean | null = null;
112-
while (valid === null) {
113-
const message = `האם יצאת לדרך לפני השעה ${transportation.departureTime}? הקישי 1 - כן, 2 - לא`;
114-
const userInput = await this.askForInput(message);
115-
if (userInput === '1') {
116-
valid = true;
117-
} else if (userInput === '2') {
118-
valid = false;
119-
} else {
120-
await this.sendMessage('הקשה לא תקינה, נא הקישי 1 או 2');
121-
}
122-
}
123-
return valid;
110+
private async isDepartureTimeValid(transportation: Transportation): Promise<boolean> {
111+
return this.askConfirmation('TRANSPORT.DEPARTURE_CONFIRM', { departureTime: transportation.departureTime });
124112
}
125113

126114
private async createAbsenceRecord(student: Student, transportation: Transportation) {
@@ -130,7 +118,7 @@ export class YemotHandlerService extends BaseYemotHandlerService {
130118
studentReferenceId: student.id,
131119
});
132120
if (!studentKlass) {
133-
await this.hangupWithMessage(' התלמידה אינה משויכת לכיתה.');
121+
await this.hangupWithMessageByKey('STUDENT.NO_CLASS');
134122
return;
135123
}
136124
const newAbsence = absenceRepo.create({

0 commit comments

Comments
 (0)