Skip to content

Commit

Permalink
#58 enable equivalent tab about there are molecule in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Nov 6, 2024
1 parent eac33a3 commit dd46593
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
22 changes: 18 additions & 4 deletions components/FormMolecule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ SPDX-License-Identifier: MIT
The file profile form molecule composant
-->
<script setup lang="ts">
import { textChangeRangeIsUnchanged } from 'typescript';


const { t } = useI18n();

const props = defineProps({
Expand Down Expand Up @@ -163,6 +160,22 @@ function titleDialogBox(): string {
}
}

// Enable equivalent if there are molecule in database
const disabledEquivalents = ref<boolean>(true);
/**
* Check if database contain molecule
*/
function checkMolecule(){
$fetch('/api/molecule/check', {
method: 'GET'
})
.then((response) => {
console.log(response);

disabledEquivalents.value = !response;
});
}
checkMolecule();
/**
* Add molecule
*/
Expand All @@ -177,6 +190,7 @@ function update() {
// TODO
event('close');
}

</script>

<template>
Expand Down Expand Up @@ -291,7 +305,7 @@ function update() {
<!-- Tab where define equivalent molecul -->
<v-expansion-panel
:title="t('title.equivalent')"
disabled
:disabled="disabledEquivalents"
>
<v-expansion-panel-text>
<!-- field to indicate searched molecule -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@
import * as mol from "./functions"

export default defineEventHandler(async (event: any) => {
// get what to you want to do
const what = getRouterParam(event, "what");
const method = getRouterParam(event, "method");

// get the method
const method = event.method.toLowerCase();

// map the method to the function
const funcMap: { [key: string]: Function } = {
"get-check": mol.getCheck,
"get-search": mol.getSearch,
"get-equivalent": mol.getEquivalent,
"get-synonym": mol.getSynonym,
"post-molecule": mol.addMolecule,
"put-molecule": mol.updateMolecule,
};

if (!funcMap[`${what}-${method}`]) {
// check if the method is valid
if (!funcMap[`${method}-${what}`]) {
throw new Error(`Invalid method ${method} for ${what}`);
}

// In case of a get request, we need to get the query parameters
if (method === "get") {
return await funcMap[`${method}-${what}`](getQuery(event).param);
}
// In case of a post or put request, we need to get the body
const body = await readBody(event)
return await funcMap[`${what}-${method}`](body.json());
return await funcMap[`${method}-${what}`](body.json());

});

0 comments on commit dd46593

Please sign in to comment.