Skip to content

Commit

Permalink
#48 update calibratrion curve
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jul 19, 2024
1 parent 111be49 commit ee655d8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
22 changes: 21 additions & 1 deletion components/ManageCalibCurve.async.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,27 @@ function modify(item: {id: string, name: string}) {
function updateCalibCurve(){
// Group value by file (daughter solution)
const daughterGroup = createDaughterGroup();
dialog.value = false;
// send calibration curve id and all associated daughter solution to update
// TODO: update only changed part
$fetch('/api/UpdateCalibCurve',{
method: 'POST',
body: {
idCalibCurve: idCalibCurve.value,
nameCalibCurve: nameCalibCurve.value,
daughters: daughterGroup,
},
})
.then(() => {
// We update the daughter table
rUpload.value = !rUpload.value;
// show message whose say the update of calibration curve is a success
success(t("message.success.updateCalibCurve"));
dialog.value = false;
})
.catch(() => {
// show message whose say the update of calibration curve is a failure
error(t("message.error.updateCalibCurve"));
});
}

</script>
Expand Down
43 changes: 43 additions & 0 deletions server/api/UpdateCalibCurve.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
//
// SPDX-License-Identifier: MIT
// this file is used to update the expected concentration of the daughters
// of a calibration curve

import pg from "pg";

export default defineEventHandler(async (event) => {
const body = await readBody(event);
const client = new pg.Client();
return client.connect()
.then(() => {
const lQueryPromises = [];
// for each daughter solution
for(const idFile in body.daughters){
// for each metabolite of the daughter solution
for(const daughter of body.daughters[idFile]){
// update expected concentration
lQueryPromises.push(client.query(`
UPDATE daughter
SET expected = ${daughter.expectedArea}
WHERE id_file = ${idFile}
AND id_mol = '${daughter.nameMeta}'
AND id_calib_curves = ${body.idCalibCurve}`
));
}
}
return Promise.all(lQueryPromises);
})
.then(() => {
// update the calibration curve name
return client.query(`
UPDATE calib_curves
SET name = '${body.nameCalibCurve}'
WHERE id = ${body.idCalibCurve}`
);
})
.catch((err: Error) => {
throw err;
})
.finally(() => client.end());
});

0 comments on commit ee655d8

Please sign in to comment.