Skip to content

Commit e2ce6e7

Browse files
feat: TT-481 change customers project visibility (#785)
1 parent 6d7c26d commit e2ce6e7

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/app/modules/customer-management/components/projects/components/project-list/project-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<tr class="d-flex" *ngFor="let project of projects">
1414
<td class="col-sm-4">{{ project.id }}</td>
1515
<td class="col-sm-3">{{ project.name }}</td>
16-
<td class="col-sm-2">{{ project.project_type.name }}</td>
16+
<td class="col-sm-2">{{ project.project_type?.name }}</td>
1717
<td class="col-sm-1 text-center">
1818
<button type="button" class="btn btn-sm btn-primary" (click)="updateProject(project)">
1919
<i class="fa fa-pencil fa-xs"></i>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,38 @@ describe('ProjectService', () => {
9191
updateProjectRequest.flush(project);
9292
});
9393

94+
it('update project using PUT from url locally', () => {
95+
const project: Project = { id: '1', name: 'new name', description: 'description', project_type_id: '123', status: 'active'};
96+
service.url = 'projects';
97+
service.isDevelopment = true;
98+
service.updateProject(project).subscribe((response) => {
99+
expect(response.name).toBe('new name');
100+
});
101+
const updateProjectRequest = httpMock.expectOne(`${service.url}/${project.id}`);
102+
expect(updateProjectRequest.request.method).toBe('PUT');
103+
updateProjectRequest.flush(project);
104+
});
105+
94106
it('delete project using DELETE from baseUrl', () => {
95107
const url = `${service.url}/1`;
108+
service.isDevelopment = false;
96109
service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => {
97110
expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2);
98111
});
99112
const deleteActivitiesRequest = httpMock.expectOne(url);
100113
expect(deleteActivitiesRequest.request.method).toBe('DELETE');
101114
deleteActivitiesRequest.flush(projectsList);
102115
});
116+
117+
it('update status project using PUT from baseUrl locally', () => {
118+
const url = `${service.url}/1`;
119+
service.isDevelopment = true;
120+
service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => {
121+
expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2);
122+
});
123+
const deleteActivitiesRequest = httpMock.expectOne(url);
124+
expect(deleteActivitiesRequest.request.method).toBe('PUT');
125+
deleteActivitiesRequest.flush(projectsList);
126+
});
127+
103128
});

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Project } from '../../../../../shared/models';
1010
export class ProjectService {
1111
projects: Project[] = [];
1212
url = `${environment.timeTrackerApiUrl}/projects`;
13+
isDevelopment = !environment.production;
1314

1415
constructor(private http: HttpClient) {}
1516

@@ -32,10 +33,17 @@ export class ProjectService {
3233

3334
updateProject(projectData): Observable<any> {
3435
const { id } = projectData;
36+
if (this.isDevelopment) {
37+
if (projectData.status === 'active') {
38+
projectData.status = 1;
39+
}
40+
}
3541
return this.http.put(`${this.url}/${id}`, projectData);
3642
}
3743

3844
deleteProject(projectId: string): Observable<any> {
39-
return this.http.delete(`${this.url}/${projectId}`);
45+
return this.isDevelopment
46+
? this.http.put(`${this.url}/${projectId}`, { status: 0 })
47+
: this.http.delete(`${this.url}/${projectId}`);
4048
}
4149
}

0 commit comments

Comments
 (0)