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",
|
"direction": "in",
|
||||||
"name": "req",
|
"name": "req",
|
||||||
"methods": [
|
"methods": [
|
||||||
"get",
|
|
||||||
"post"
|
"post"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user