Skip to content

Commit

Permalink
#48 save name of serie
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jun 23, 2024
1 parent 918823f commit 93602af
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
7 changes: 5 additions & 2 deletions components/ManageSerie.async.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ async function sendFile() {
rDaughterLoading.value = false;
}

async function submit (event) {
async function submit (event) {

// check if we have daughter solution
if (rDaughterTable.value.length === 0) {
// TODO: show error message
Expand All @@ -109,10 +110,11 @@ async function submit (event) {
return acc;
}, {});

// send serie name and all associated daughter solution
$fetch('/api/AddSerie', {
method: 'POST',
body: JSON.stringify({
nameSerie: nameSerie.value,
nameSerie: event.target.elements.nameSerie.value,
daughterGroup,
}),
});
Expand Down Expand Up @@ -142,6 +144,7 @@ async function submit (event) {
<v-card-text>
<v-text-field
v-model="nameSerie"
name="nameSerie"
:counter="10"
:rules="nameRules"
:label="t('label.nameSerie')"
Expand Down
11 changes: 2 additions & 9 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,12 @@ CREATE TABLE daughter
(
id_series SERIAL REFERENCES series (id) ON DELETE CASCADE,
id_file SERIAL REFERENCES file (id) ON DELETE CASCADE,
PRIMARY KEY (id_series, id_file)
);

CREATE TABLE dau_metabo
(
id_daughter SERIAL REFERENCES file (id) ON DELETE CASCADE,
id_metabo VARCHAR(52) UNIQUE,
id_mol VARCHAR(52),
area FLOAT NOT NULL,
expected FLOAT NOT NULL,
PRIMARY KEY (id_daughter, id_metabo)
PRIMARY KEY (id_series, id_file, id_mol)
);


CREATE TABLE ratio
(
id_mol VARCHAR(52) UNIQUE,
Expand Down
40 changes: 16 additions & 24 deletions server/api/AddSerie.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,35 @@ import pg from "pg";

export default defineEventHandler(async (event) => {
const body = await readBody(event);
console.log("body", body);

const client = new pg.Client();
return client.connect()
.then(() => {
return client.query(`
INSERT INTO series(name, date_create, id_machine)
VALUES ('${body.name}', NOW(), -1)
VALUES ('${body.nameSerie}', NOW(), -1)
RETURNING id`); // -1 is the default value for id_machine
})
.then((respQuery) => {
if (respQuery.rows.length === 0) {
throw new Error("Serie not create");
}
respQuery.rows[0].id;
// save each metabolite by daughter solution
return Promise.all(Object.keys(body.daughterGroup).map(
(idFile: string) => {
return client.query(`
INSERT INTO daughter(id_series, id_file)
VALUES (
'${respQuery.rows[0].id}',
'${idFile}')`
)
.then(() => {
return Promise.all(body.daughterGroup[idFile].map(
(metabo) =>
client.query(`
INSERT INTO dau_metabo(
id_daughter, id_metabo, area, expected)
VALUES (
'${idFile}',
'${metabo.nameMeta}',
'${metabo.area}',
'${metabo.expectedArea}')`
)
));
});
(idFile: string) => {
//
for(const metabo of body.daughterGroup[idFile]){
client.query(`
INSERT INTO daughter(
id_series, id_file, id_mol, area, expected)
VALUES (
'${respQuery.rows[0].id}',
'${idFile}',
'${metabo.nameMeta}',
'${metabo.area}',
'${metabo.expectedArea}')`
);
}
}
));
})
Expand Down

0 comments on commit 93602af

Please sign in to comment.