Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit 67aea0c

Browse files
author
Lian Nivin
committed
Add close controller and services
1 parent fe8e0ce commit 67aea0c

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

rails-time-track/app/controllers/api/projects_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ def update
6868
end
6969
end
7070

71-
# accion q haga close del project
72-
71+
def close
72+
if @project.update({closed: true})
73+
render json: @project, status: :ok
74+
else
75+
render json: {errors: @project.errors}
76+
end
77+
end
7378

7479
private
7580
def set_project

rails-time-track/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
resources :projects, :only => [:index, :show, :create] do
1111
get 'my-projects', action: 'my_projects', on: :collection
12+
put "/close", to: "projects#close"
1213
end
1314

1415
resources :weekly_project_reports, :only => [:show]

react-time-track/src/services/project.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,23 @@ async function closedProjects() {
5858
return response.json();
5959
}
6060

61-
// method: "PUT/POST"
62-
// async function getProjectDetail(projectId) {
63-
// const response = await fetch(`${API_ALL_PROJECTS}/close`, {
64-
// method: "..",
65-
// credentials: "include",
66-
// headers: {
67-
// "Content-Type": "application/json"
68-
// }
69-
// });
70-
71-
// if (!response.ok) {
72-
// const { errors } = await response.json();
73-
// console.log(errors);
74-
// throw new Error(errors);
75-
// }
76-
77-
// return response.json();
78-
// }
61+
async function closeProject(projectId) {
62+
const response = await fetch(`${API_ALL_PROJECTS}/${projectId}/close`, {
63+
method: "PUT",
64+
credentials: "include",
65+
headers: {
66+
"Content-Type": "application/json"
67+
}
68+
});
69+
70+
if (!response.ok) {
71+
const { errors } = await response.json();
72+
console.log(errors);
73+
throw new Error(errors);
74+
}
75+
76+
return response.json();
77+
}
7978

8079

8180
async function getProjectDetail(projectId) {
@@ -119,5 +118,6 @@ export {
119118
closedProjects,
120119
getProjectDetail,
121120
createProject,
122-
listUserProjects
121+
listUserProjects,
122+
closeProject
123123
};

react-time-track/src/views/project.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Link } from "@reach/router";
55
import Chart from "chart.js";
66

77
import { Card, Circle, Subtitle, Button } from "../components/ui";
8-
import { getProjectDetail } from "../services/project";
8+
import { getProjectDetail, closeProject } from "../services/project";
99
import { getWeeklyReport } from "../services/weekly_report";
1010

1111
import Modal from "../components/modal";
@@ -48,7 +48,7 @@ function Project({ project_id }, props) {
4848
}
4949

5050
function onCloseProject(project_id){
51-
console.log('Aca se cierra el proyecto')
51+
closeProject(project_id).then((response) => {console.log(response)})
5252
// ejecutar el service
5353
// then
5454
toggleModal();

0 commit comments

Comments
 (0)