Skip to content

Commit 239ba5b

Browse files
committed
refactor: project request destroy
1 parent 9fda53e commit 239ba5b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/app/project/page.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default function Project() {
9292
const handleDelete = async () => {
9393
toast.success("Destroy sent successfully");
9494
try {
95+
// Update Project request status
9596
const requestTypeData = {
9697
projectid: projectId,
9798
status: "destroy",
@@ -112,6 +113,42 @@ export default function Project() {
112113
);
113114
}
114115

116+
const projectData = {
117+
projectid: projectId,
118+
statuspm: "Pending",
119+
statusops: "Pending",
120+
};
121+
122+
const resProject = await fetch("/api/project", {
123+
method: "PUT",
124+
headers: {
125+
"Content-Type": "application/json",
126+
},
127+
body: JSON.stringify(projectData),
128+
});
129+
130+
if (!resProject.ok) {
131+
const errorMessage = await resRequesttype.text();
132+
throw new Error(
133+
`Project API failed: ${resRequesttype.status} - ${errorMessage}`
134+
);
135+
}
136+
137+
const resRequest = await fetch("/api/request", {
138+
method: "PUT",
139+
headers: {
140+
"Content-Type": "application/json",
141+
},
142+
body: JSON.stringify(projectData),
143+
});
144+
145+
if (!resRequest.ok) {
146+
const errorMessage = await resRequesttype.text();
147+
throw new Error(
148+
`Project API failed: ${resRequesttype.status} - ${errorMessage}`
149+
);
150+
}
151+
115152
router.push("/projectlist");
116153
} catch (error) {
117154
console.error("Error while deleting resource:", error);

src/app/projectops/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ export default function ProjectMG() {
193193
return;
194194
} else if (event === "Approved") {
195195
toast.success("Request approved");
196-
sendMessageToQueue(projectId, "create-vm");
197196

198197
try {
199198
const res = await fetch(`/api/request/?projectId=${projectId}`, {
@@ -209,6 +208,7 @@ export default function ProjectMG() {
209208

210209
const data = await res.json();
211210
if (data[0].statuspm === event) {
211+
sendMessageToQueue(projectId, "create-vm");
212212
try {
213213
const res = await fetch(
214214
`/api/triggerdag/?dagId=idp&projectId=${projectId}`,

0 commit comments

Comments
 (0)