Skip to content

Commit

Permalink
#48 associate Series to project
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jun 24, 2024
1 parent fcc06e5 commit ba21455
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
5 changes: 5 additions & 0 deletions components/ExtractInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function emptyProject(project: tProject) {
project.createDate = "";
project.nbFile = 0;
project.files = [] as tFile[];
project.series = [];
}

// The project consulted
Expand Down Expand Up @@ -366,11 +367,13 @@ function openProject(id: string) {
currentProject.createDate = tempProject[0].createDate;
currentProject.nbFile = tempProject[0].nbFile;
Object.assign(currentProject.files, tempProject[0].files);
Object.assign(currentProject.series, tempProject[0].series);
oldProject.id = id;
oldProject.name = tempProject[0].name;
oldProject.createDate = tempProject[0].createDate;
oldProject.nbFile = tempProject[0].nbFile;
Object.assign(oldProject.files, tempProject[0].files);
Object.assign(oldProject.series, tempProject[0].series);
}
isOpen.value = true;
}
Expand Down Expand Up @@ -402,6 +405,7 @@ function processFail(msg: string) {
}
function createProject() {
const body = new FormData();

body.append("folder", currentFolder);
body.append("project", JSON.stringify(currentProject));
// todo get team name
Expand Down Expand Up @@ -726,6 +730,7 @@ async function deleteProject(id:string, name:string){
item-title="name"
item-value="id"
label="t('label.selectSerie')"
multiple
/>
</div>
</template>
Expand Down
7 changes: 7 additions & 0 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ FROM series, ratio
WHERE series.id = ratio.id_series
GROUP BY series.id;

CREATE TABLE proj_series
(
id_project SERIAL REFERENCES project (id) ON DELETE CASCADE,
id_series SERIAL REFERENCES series (id) ON DELETE CASCADE,
PRIMARY KEY (id_project, id_series)
);

INSERT INTO users (name, email, hash, team)
VALUES
('root_ep2m2', '[email protected]',
Expand Down
30 changes: 30 additions & 0 deletions server/api/AssociateSeries.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
//
// SPDX-License-Identifier: MIT

import pg from "pg";

export default defineEventHandler(async (event) => {
const body = await readBody(event);
const client = new pg.Client();
return client.connect()
.then(() => {
console.log(body);

const lPromises = [];
for(const idSerie of body.series){
lPromises.push(
client.query(`
INSERT INTO proj_series(id_project, id_series)
VALUES ('${body.id_project}', '${idSerie}')`
)
);
}
return Promise.allSettled(lPromises);
})
.catch((err: Error) => {
throw err;
})
.finally(() => client.end());

});
24 changes: 15 additions & 9 deletions server/api/createProject.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,40 @@ export default defineEventHandler((event) => {
project (name, date_create, team)
VALUES ('${project.name}',
NOW(),
'${team}')`;

'${team}')
RETURNING id`;

let idProject: string;
const client = new pg.Client();
return client.connect()
.then(() => {
return client.query(addProjectSql);
})
.then(() => {
return client.query(`SELECT id
FROM project
WHERE name = '${project.name}'`);
})
.then((respQuery:{rows:{id:string}[]}) => {

if (respQuery.rows.length === 0) {
throw new Error("project not create");
}

idProject = respQuery.rows[0].id;
return $fetch("/api/addFile",{
method:"POST",
body: {
files: project.files,
folder: folder,
id_project: respQuery.rows[0].id
id_project: idProject
}
});

})
.then(() => {
return $fetch("/api/AssociateSeries",{
method:"POST",
body: {
series: project.series,
id_project: idProject
}
});
})
.then(() => rm(join("/shareFile", folder),
{ recursive: true, force: true }))
.catch((err: Error) => {
Expand Down

0 comments on commit ba21455

Please sign in to comment.