Skip to content

Commit

Permalink
#48 update series associated to project
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jun 24, 2024
1 parent cb40c35 commit 8f16eb1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
27 changes: 27 additions & 0 deletions components/ExtractInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,33 @@ async function updateProject(){
}
}));
}
// update series
if(currentProject.series != oldProject.series){
// delete series
const lDelSeries = oldProject.series.filter(x => !currentProject.series.includes(x));
// verify we have series to disassociate
if(lDelSeries.length > 0){
holdOn.push($fetch("/api/DisassociateSeries",{
method:"POST",
body: {
id_project: currentProject.id,
series: lDelSeries
}
}));
}
// add series
const lAddSeries = currentProject.series.filter(x => !oldProject.series.includes(x));
// verify we have series to associate
if(lAddSeries.length > 0){
holdOn.push($fetch("/api/AssociateSeries",{
method:"POST",
body: {
id_project: currentProject.id,
series: lAddSeries
}
}));
}
}

Promise.all(holdOn)
.then(() => processOk(currentProject.name + " " +
Expand Down
20 changes: 20 additions & 0 deletions server/api/DisassociateSeries.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
//
// SPDX-License-Identifier: MIT

import pg from "pg";

export default defineEventHandler((event) => {
return readBody(event)
.then((body) => {

const client = new pg.Client();
return client.connect()

.then(() => client.query(`DELETE FROM proj_series
WHERE id_series IN
(${body.series.join(",")})
AND id_project = ${body.id_project}`))
.finally(() => client.end());
});
});
4 changes: 4 additions & 0 deletions server/api/createProject.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default defineEventHandler((event) => {

})
.then(() => {
// verify we have series to associate
if (project.series.length == 0) {
return;
}
return $fetch("/api/AssociateSeries",{
method:"POST",
body: {
Expand Down

0 comments on commit 8f16eb1

Please sign in to comment.