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", "direction": "in",
"name": "req", "name": "req",
"methods": [ "methods": [
"get",
"post" "post"
] ]
}, },

View File

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

View File

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

View File

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