Skip to content

Commit 63d8d3d

Browse files
jisazacMarco AguirreMarco AguirrerodolfoIOETjisazac
authored
Tta 94 refactor endpoints to make it work on tt stage and tt prod (#903)
* Innecesary env files deleted * New changes to env files * Add 1 git-crypt collaborator New collaborators: F295BDD1 Marco Aguirre <[email protected]> * Add 1 git-crypt collaborator New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> * Add 2 git-crypt collaborators New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> F295BDD1 Marco Aguirre <[email protected]> * New keys and env variables added * env files added & modified * Make run now uses .dev.env * Pipeline modified * is the .env needed? * using encrypted .stage.env * load secrets * adding env variables * scopes cannot be empty * use env * using env var * using env file * adding mask * using docker buildkit * only on tags * using buildkit directly * using dash source * docker buildkit * missing folders added * nginx fix * fixing secrets * problem with double qoutes * fixing quotes in .stage.env * fixing secrets * loading to env * quotes fixed * replacing \r * fixing trailing \n * one line expose * fixing endpoint url * removing unnecessary jobs * update creds * adding with space at the end of the file * primer commit * cambios en users list components * Se ajusta la variable isDevelopmentOrProd * revision tests * reportsUrl como variable global Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]>
1 parent d07db70 commit 63d8d3d

File tree

8 files changed

+23
-29
lines changed

8 files changed

+23
-29
lines changed

src/app/modules/customer-management/components/projects/components/services/project.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('ProjectService', () => {
104104
it('update project using PUT from url locally', () => {
105105
const project: Project = { id: '1', name: 'new name', description: 'description', project_type_id: '123', status: 'active'};
106106
service.url = 'projects';
107-
service.isDevelopment = true;
107+
service.isDevelopmentOrProd = true;
108108
service.updateProject(project).subscribe((response) => {
109109
expect(response.name).toBe('new name');
110110
});
@@ -115,7 +115,7 @@ describe('ProjectService', () => {
115115

116116
it('delete project using DELETE from baseUrl', () => {
117117
const url = `${service.url}/1`;
118-
service.isDevelopment = false;
118+
service.isDevelopmentOrProd = false;
119119
service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => {
120120
expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2);
121121
});
@@ -126,7 +126,7 @@ describe('ProjectService', () => {
126126

127127
it('update status project using PUT from baseUrl locally', () => {
128128
const url = `${service.url}/1`;
129-
service.isDevelopment = true;
129+
service.isDevelopmentOrProd = true;
130130
service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => {
131131
expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2);
132132
});

src/app/modules/customer-management/components/projects/components/services/project.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Project } from '../../../../../shared/models';
1111
export class ProjectService {
1212
projects: Project[] = [];
1313
url = `${environment.timeTrackerApiUrl}/projects`;
14-
isDevelopment = environment.production === EnvironmentType.TT_DEV;
14+
isDevelopmentOrProd = environment.production === EnvironmentType.TT_DEV || environment.production === EnvironmentType.TT_PROD;
1515

1616
constructor(private http: HttpClient) {}
1717

@@ -34,7 +34,7 @@ export class ProjectService {
3434

3535
updateProject(projectData): Observable<any> {
3636
const { id } = projectData;
37-
if (this.isDevelopment) {
37+
if (this.isDevelopmentOrProd) {
3838
if (projectData.status === 'active') {
3939
projectData.status = 1;
4040
}
@@ -43,7 +43,7 @@ export class ProjectService {
4343
}
4444

4545
deleteProject(projectId: string): Observable<any> {
46-
return this.isDevelopment
46+
return this.isDevelopmentOrProd
4747
? this.http.put(`${this.url}/${projectId}`, { status: 0 })
4848
: this.http.delete(`${this.url}/${projectId}`);
4949
}

src/app/modules/time-clock/services/entry.service.spec.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as moment from 'moment';
1010
describe('EntryService', () => {
1111
let service: EntryService;
1212
let httpMock: HttpTestingController;
13+
var reportsUrl = service.urlInProductionLegacy ? service.baseUrl : service.baseUrl + '/report';
1314

1415
beforeEach(() => {
1516
TestBed.configureTestingModule({imports: [HttpClientTestingModule], providers: [DatePipe]});
@@ -84,15 +85,15 @@ describe('EntryService', () => {
8485
});
8586

8687
it('stops an entry using POST', () => {
87-
service.urlInProduction = true;
88+
service.urlInProductionLegacy = true;
8889
service.stopEntryRunning('id').subscribe();
8990

9091
const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/id/stop`);
9192
expect(updateEntryRequest.request.method).toBe('POST');
9293
});
9394

9495
it('stops an entry using PUT', () => {
95-
service.urlInProduction = false;
96+
service.urlInProductionLegacy = false;
9697
service.stopEntryRunning('id').subscribe();
9798

9899
const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/stop`);
@@ -105,7 +106,6 @@ describe('EntryService', () => {
105106
const pipe: DatePipe = new DatePipe('en');
106107
const timeRange: TimeEntriesTimeRange = {start_date: yesterday, end_date: today};
107108
const userId = '123';
108-
const reportsUrl = service.urlInProduction ? service.baseUrl : service.baseUrl + '/report';
109109
service.loadEntriesByTimeRange(timeRange, userId).subscribe();
110110

111111
const loadEntryRequest = httpMock.expectOne(req => req.method === 'GET' && req.url === reportsUrl);
@@ -120,9 +120,7 @@ describe('EntryService', () => {
120120
const today = moment(new Date());
121121
const timeRange: TimeEntriesTimeRange = { start_date: yesterday, end_date: today };
122122
const userId = '123';
123-
const reportsUrl = service.urlInProduction ? service.baseUrl : service.baseUrl + '/report';
124123
service.loadEntriesByTimeRange(timeRange, userId).subscribe();
125-
126124
const loadEntryRequest = httpMock.expectOne(req => req.method === 'GET' && req.url === reportsUrl);
127125
expect(loadEntryRequest.request.params.get('limit')).toEqual('9999');
128126
});
@@ -132,12 +130,8 @@ describe('EntryService', () => {
132130
const today = moment(new Date());
133131
const timeRange: TimeEntriesTimeRange = { start_date: yesterday, end_date: today };
134132
const userId = '123';
135-
const reportsUrl = service.urlInProduction ? service.baseUrl : service.baseUrl + '/report';
136-
137133
service.loadEntriesByTimeRange(timeRange, userId).subscribe();
138-
139134
const loadEntryRequest = httpMock.expectOne(req => req.method === 'GET' && req.url === reportsUrl);
140-
141135
const timezoneOffset = new Date().getTimezoneOffset().toString();
142136
expect(loadEntryRequest.request.params.get('timezone_offset')).toEqual(timezoneOffset);
143137
});

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class EntryService {
2020

2121
static TIME_ENTRIES_DATE_TIME_FORMAT = 'yyyy-MM-ddTHH:mm:ssZZZZZ';
2222
baseUrl = `${environment.timeTrackerApiUrl}/time-entries`;
23-
urlInProduction = environment.production === EnvironmentType.TT_PROD || environment.production === EnvironmentType.TT_PROD_LEGACY;
23+
urlInProductionLegacy = environment.production === EnvironmentType.TT_PROD_LEGACY;
2424

2525
loadActiveEntry(): Observable<any> {
2626
return this.http.get(`${this.baseUrl}/running`);
@@ -46,7 +46,7 @@ export class EntryService {
4646
}
4747

4848
stopEntryRunning(idEntry: string): Observable<any> {
49-
return (this.urlInProduction ? this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) );
49+
return (this.urlInProductionLegacy ? this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) );
5050
}
5151

5252
restartEntry(idEntry: string): Observable<Entry> {
@@ -69,7 +69,7 @@ export class EntryService {
6969

7070
loadEntriesByTimeRange(range: TimeEntriesTimeRange, userId: string): Observable<any> {
7171
const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999;
72-
const loadEntriesByTimeRangeURL = this.urlInProduction ? this.baseUrl : this.baseUrl + '/report';
72+
const loadEntriesByTimeRangeURL = this.urlInProductionLegacy ? this.baseUrl : this.baseUrl + '/report';
7373
return this.http.get(loadEntriesByTimeRangeURL,
7474
{
7575
params: {

src/app/modules/users/components/users-list/users-list.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
<td class="col-3 text-center">
2121
<ui-switch
2222
size="small"
23-
(change)="!isDevelopment?switchGroup('time-tracker-admin', user):null; updateRole(ROLES.admin, user, $event);"
23+
(change)="!isDevelopmentOrProd?switchGroup('time-tracker-admin', user):null; updateRole(ROLES.admin, user, $event);"
2424
[checked]="user.groups.includes('time-tracker-admin')"></ui-switch>
2525
admin
26-
<span *ngIf="!isDevelopment">
26+
<span *ngIf="!isDevelopmentOrProd">
2727
<ui-switch
2828
size="small"
2929
(change)="switchGroup('time-tracker-tester', user)"

src/app/modules/users/components/users-list/users-list.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
2727
columnDefs: [{ orderable: false, targets: [2]}]
2828
};
2929
switchGroupsSubscription: Subscription;
30-
isDevelopment = true;
30+
isDevelopmentOrProd = true;
3131

3232
public get ROLES() {
3333
return ROLES;
@@ -38,7 +38,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
3838
}
3939

4040
ngOnInit(): void {
41-
this.isDevelopment = environment.production === EnvironmentType.TT_DEV;
41+
this.isDevelopmentOrProd = environment.production === EnvironmentType.TT_DEV || environment.production === EnvironmentType.TT_PROD;
4242
this.store.dispatch(new LoadUsers());
4343
this.loadUsersSubscription = this.actionsSubject$
4444
.pipe(filter((action: any) => action.type === UserActionTypes.LOAD_USERS_SUCCESS))

src/app/modules/users/services/users.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('UsersService', () => {
3535
it('grant role to a User', () => {
3636
const userId = 'userId';
3737
const roleId = 'admin';
38-
service.isProduction = true;
38+
service.isProductionLegacy = true;
3939

4040
service.grantRole(userId, roleId).subscribe();
4141

@@ -46,7 +46,7 @@ describe('UsersService', () => {
4646
it('grant role to a User locally', () => {
4747
const userId = 'userId';
4848
const roleId = 'admin';
49-
service.isProduction = false;
49+
service.isProductionLegacy = false;
5050

5151
service.grantRole(userId, roleId).subscribe();
5252

@@ -57,7 +57,7 @@ describe('UsersService', () => {
5757
it('revoke role to a User', () => {
5858
const userId = 'userId';
5959
const roleId = 'admin';
60-
service.isProduction = true;
60+
service.isProductionLegacy = true;
6161

6262
service.revokeRole(userId, roleId).subscribe();
6363

@@ -68,7 +68,7 @@ describe('UsersService', () => {
6868
it('revoke role to a User locally', () => {
6969
const userId = 'userId';
7070
const roleId = 'admin';
71-
service.isProduction = false;
71+
service.isProductionLegacy = false;
7272

7373
service.revokeRole(userId, roleId).subscribe();
7474

src/app/modules/users/services/users.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { EnvironmentType } from './../../../../environments/enum';
99
providedIn: 'root',
1010
})
1111
export class UsersService {
12-
isProduction = environment.production === EnvironmentType.TT_PROD || environment.production === EnvironmentType.TT_PROD_LEGACY;
12+
isProductionLegacy = environment.production === EnvironmentType.TT_PROD_LEGACY;
1313
constructor(private http: HttpClient) {}
1414

1515
baseUrl = `${environment.timeTrackerApiUrl}/users`;
@@ -19,13 +19,13 @@ export class UsersService {
1919
}
2020

2121
grantRole(userId: string, roleId: string): Observable<any> {
22-
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/grant`
22+
const url = this.isProductionLegacy ? `${this.baseUrl}/${userId}/roles/${roleId}/grant`
2323
: `${this.baseUrl}/${userId}/${roleId}/grant`;
2424
return this.http.post(url, null);
2525
}
2626

2727
revokeRole(userId: string, roleId: string): Observable<any> {
28-
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/revoke`
28+
const url = this.isProductionLegacy ? `${this.baseUrl}/${userId}/roles/${roleId}/revoke`
2929
: `${this.baseUrl}/${userId}/${roleId}/revoke`;
3030
return this.http.post(url, null);
3131
}

0 commit comments

Comments
 (0)