mirror of
https://github.com/jlengrand/simple-food-diary.git
synced 2026-03-10 08:41:19 +00:00
33 lines
741 B
TypeScript
33 lines
741 B
TypeScript
import { AzureFunction, Context } from '@azure/functions';
|
|
|
|
const mongoose = require('mongoose');
|
|
|
|
console.log('running!');
|
|
|
|
mongoose.connect(process.env.CONNECTION_STRING);
|
|
|
|
const entrySchema = new mongoose.Schema({
|
|
portionSize: String,
|
|
mealTypes: [String],
|
|
});
|
|
const EntryModel = mongoose.model('entry', entrySchema);
|
|
|
|
// eslint-disable-next-line func-names
|
|
const httpTrigger: AzureFunction = async function (
|
|
context: Context
|
|
): Promise<void> {
|
|
console.log('running as well!');
|
|
|
|
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;
|
|
};
|
|
|
|
export default httpTrigger;
|