Skip to content

Commit 2eef09e

Browse files
author
Guido Quezada
committed
fix: #566 refactor variables name
1 parent add60cd commit 2eef09e

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
<label class="col-12 col-sm-2">Date in:</label>
7676
<div class="col-12 col-sm-4">
7777
<input
78-
formControlName="entry_date"
79-
id="entry_date"
78+
formControlName="start_date"
79+
id="start_date"
8080
type="date"
8181
class="form-control"
8282
aria-label="Small"
8383
aria-describedby="inputGroup-sizing-sm"
84-
[class.is-invalid]="entry_date.invalid && entry_date.touched"
84+
[class.is-invalid]="start_date.invalid && start_date.touched"
8585
required
8686
/>
8787
</div>
@@ -112,13 +112,13 @@
112112
<label class="col-12 col-sm-2">Date out:</label>
113113
<div class="col-12 col-sm-4">
114114
<input
115-
formControlName="departure_date"
116-
id="departure_date"
115+
formControlName="end_date"
116+
id="end_date"
117117
type="date"
118118
class="form-control"
119119
aria-label="Small"
120120
aria-describedby="inputGroup-sizing-sm"
121-
[class.is-invalid]="departure_date.invalid && departure_date.touched"
121+
[class.is-invalid]="end_date.invalid && end_date.touched"
122122
required
123123
/>
124124
</div>

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ describe('DetailsFieldsComponent', () => {
6666
project_name: '',
6767
activity_id: '',
6868
uri: '',
69-
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
70-
departure_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
69+
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
70+
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
7171
start_hour: '00:00:00',
7272
end_hour: '00:00:00',
7373
description: '',
@@ -109,8 +109,8 @@ describe('DetailsFieldsComponent', () => {
109109
project_name: 'name',
110110
activity_id: 'a1',
111111
uri: 'ticketUri',
112-
entry_date: '',
113-
departure_date: '',
112+
start_date: '',
113+
end_date: '',
114114
start_hour: '00:00:10',
115115
end_hour: '00:00:11',
116116
description: '',
@@ -178,8 +178,8 @@ describe('DetailsFieldsComponent', () => {
178178
project_name: '',
179179
activity_id: '',
180180
uri: '',
181-
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
182-
departure_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
181+
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
182+
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
183183
start_hour: '00:00:00',
184184
end_hour: '00:00:00',
185185
description: '',
@@ -215,8 +215,8 @@ describe('DetailsFieldsComponent', () => {
215215
project_name: 'p-name',
216216
activity_id: 'a1',
217217
uri: '',
218-
entry_date: '2020-02-05',
219-
departure_date: '2020-02-05',
218+
start_date: '2020-02-05',
219+
end_date: '2020-02-05',
220220
start_hour: '00:00:01',
221221
end_hour: '00:01:01',
222222
description: '',
@@ -291,7 +291,7 @@ describe('DetailsFieldsComponent', () => {
291291
component.goingToWorkOnThis = true;
292292
spyOn(component.saveEntry, 'emit');
293293

294-
component.entryForm.setValue({ ...formValues, entry_date: '2020-06-11', departure_date: '2020-06-11' });
294+
component.entryForm.setValue({ ...formValues, start_date: '2020-06-11', end_date: '2020-06-11' });
295295

296296
component.onSubmit();
297297

@@ -315,29 +315,29 @@ describe('DetailsFieldsComponent', () => {
315315
spyOn(toastrServiceStub, 'error');
316316

317317
const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
318-
component.entryForm.setValue({ ...formValues, entry_date: futureDate, departure_date: futureDate });
318+
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: futureDate });
319319
component.onSubmit();
320320

321321
expect(toastrServiceStub.error).toHaveBeenCalled();
322322
});
323323

324-
it('when entry_date is in the future and departure_date is OK then throws an error', () => {
324+
it('when start_date is in the future and end_date is OK then throws an error', () => {
325325
spyOn(toastrServiceStub, 'error');
326326

327327
const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
328328
const currentDate = moment().format('YYYY-MM-DD');
329-
component.entryForm.setValue({ ...formValues, entry_date: futureDate, departure_date: currentDate });
329+
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: currentDate });
330330
component.onSubmit();
331331

332332
expect(toastrServiceStub.error).toHaveBeenCalled();
333333
});
334334

335-
it('when entry_date is OK and departure_date is in the future then throws an error future', () => {
335+
it('when start_date is OK and end_date is in the future then throws an error future', () => {
336336
spyOn(toastrServiceStub, 'error');
337337

338338
const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
339339
const currentDate = moment().format('YYYY-MM-DD');
340-
component.entryForm.setValue({ ...formValues, entry_date: currentDate, departure_date: futureDate });
340+
component.entryForm.setValue({ ...formValues, start_date: currentDate, end_date: futureDate });
341341
component.onSubmit();
342342

343343
expect(toastrServiceStub.error).toHaveBeenCalled();

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4949
project_name: ['', Validators.required],
5050
activity_id: ['', Validators.required],
5151
description: '',
52-
entry_date: '',
53-
departure_date: '',
52+
start_date: '',
53+
end_date: '',
5454
start_hour: '',
5555
end_hour: '',
5656
uri: '',
@@ -131,8 +131,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
131131
project_id: this.entryToEdit.project_id,
132132
activity_id: this.entryToEdit.activity_id,
133133
description: this.entryToEdit.description,
134-
entry_date: formatDate(get(this.entryToEdit, 'start_date', '') , 'yyyy-MM-dd', 'en'),
135-
departure_date: formatDate(get(this.entryToEdit, 'end_date'), 'yyyy-MM-dd', 'en'),
134+
start_date: formatDate(get(this.entryToEdit, 'start_date', '') , 'yyyy-MM-dd', 'en'),
135+
end_date: formatDate(get(this.entryToEdit, 'end_date'), 'yyyy-MM-dd', 'en'),
136136
start_hour: formatDate(get(this.entryToEdit, 'start_date', '00:00:00'), 'HH:mm:ss', 'en'),
137137
end_hour: formatDate(get(this.entryToEdit, 'end_date', '00:00:00'), 'HH:mm:ss', 'en'),
138138
uri: this.entryToEdit.uri,
@@ -150,8 +150,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
150150
project_id: '',
151151
activity_id: '',
152152
description: '',
153-
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
154-
departure_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
153+
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
154+
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
155155
start_hour: '00:00:00',
156156
end_hour: '00:00:00',
157157
uri: '',
@@ -175,12 +175,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
175175
return this.entryForm.get('activity_id');
176176
}
177177

178-
get entry_date() {
179-
return this.entryForm.get('entry_date');
178+
get start_date() {
179+
return this.entryForm.get('start_date');
180180
}
181181

182-
get departure_date() {
183-
return this.entryForm.get('departure_date');
182+
get end_date() {
183+
return this.entryForm.get('end_date');
184184
}
185185

186186
get start_hour() {
@@ -201,24 +201,24 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
201201
this.toastrService.warning('Make sure to select a project and activity');
202202
return;
203203
}
204-
const entryDate = this.entryForm.value.entry_date;
205-
const departureDate = this.entryForm.value.departure_date;
204+
const startDate = this.entryForm.value.start_date;
205+
const endDate = this.entryForm.value.end_date;
206206
const entry = {
207207
project_id: this.entryForm.value.project_id,
208208
activity_id: this.entryForm.value.activity_id,
209-
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
209+
technologies: get(this, 'selectedTechnologies', []),
210210
description: this.entryForm.value.description,
211-
start_date: new Date(`${entryDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
212-
end_date: new Date(`${departureDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
211+
start_date: new Date(`${startDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
212+
end_date: new Date(`${endDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
213213
uri: this.entryForm.value.uri,
214214
timezone_offset: new Date().getTimezoneOffset(),
215215
};
216216
if (this.goingToWorkOnThis) {
217217
delete entry.end_date;
218218
}
219-
const isEntryDateInTheFuture = moment(entryDate).isAfter(moment());
220-
const isDepartureDateInTheFuture = moment(departureDate).isAfter(moment());
221-
if (isEntryDateInTheFuture || isDepartureDateInTheFuture) {
219+
const isStartDateInTheFuture = moment(startDate).isAfter(moment());
220+
const isEndDateInTheFuture = moment(endDate).isAfter(moment());
221+
if (isStartDateInTheFuture || isEndDateInTheFuture) {
222222
this.toastrService.error('You cannot start a time-entry in the future');
223223
return;
224224
}

0 commit comments

Comments
 (0)