mirror of
https://github.com/jlengrand/simple-food-diary.git
synced 2026-03-10 08:41:19 +00:00
New test
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
"direction": "in",
|
||||
"name": "req",
|
||||
"methods": [
|
||||
"get",
|
||||
"post"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user