This commit is contained in:
Julien Lengrand-Lambert
2021-08-11 16:45:35 +02:00
parent 8f812dc4d6
commit adc6de4862
4 changed files with 12 additions and 9 deletions

View File

@@ -6,7 +6,6 @@
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},

View File

@@ -6,11 +6,11 @@ console.log('running!');
mongoose.connect(process.env.CONNECTION_STRING);
const taskSchema = new mongoose.Schema({
const entrySchema = new mongoose.Schema({
portionSize: String,
mealtypes: [String],
mealTypes: [String],
});
const EntryModel = mongoose.model('entry', taskSchema);
const EntryModel = mongoose.model('entry', entrySchema);
// eslint-disable-next-line func-names
const httpTrigger: AzureFunction = async function (
@@ -20,6 +20,11 @@ const httpTrigger: AzureFunction = async function (
const { body } = context.req;
const task = await EntryModel.create(body);
context.res = {
header: {
'Content-Type': 'application/json',
},
};
context.res.status = 201;
context.res.body = task;
};

View File

@@ -11,8 +11,7 @@
},
"devDependencies": {
"@azure/functions": "^1.2.3",
"typescript": "^4.0.0",
"mongoose": "^5.13.6"
"typescript": "^4.0.0"
},
"dependencies": {
"mongoose": "^5.13.6"

View File

@@ -38,18 +38,18 @@ class FoodLogForm extends LitElement {
const portionSize = this.shadowRoot!.querySelector<HTMLInputElement>(
'input[type=radio]:checked'
)?.value;
const mealtypes = Array.from<HTMLInputElement>(
const mealTypes = Array.from<HTMLInputElement>(
this.shadowRoot!.querySelectorAll('input[type=checkbox]:checked')
).map(e => e.value);
// TODO : add timestamp
const meal = {
portionSize,
mealtypes,
mealTypes,
};
// eslint-disable-next-line no-console
console.log(meal);
console.log(JSON.stringify(meal));
fetch(
'/api/addDiaryEntry', // API location