2023-06-19 20:38:45 +02:00
|
|
|
import type { RequestHandler } from '@sveltejs/kit';
|
|
|
|
import { Recipe } from '../../../models/Recipe';
|
|
|
|
import { dbConnect, dbDisconnect } from '../../../utils/db';
|
|
|
|
import type {RecipeModelType} from '../../../types/types';
|
|
|
|
import { BEARER_TOKEN } from '$env/static/private'
|
|
|
|
// header: use for bearer token for now
|
|
|
|
// recipe json in body
|
|
|
|
export const POST: RequestHandler = async ({request}) => {
|
|
|
|
let message = await request.json()
|
|
|
|
const recipe_json = message.recipe
|
|
|
|
const bearer_token = message.headers.bearer
|
|
|
|
console.log("RECIPE:", recipe_json)
|
|
|
|
console.log("BEARER:", bearer_token)
|
|
|
|
if(bearer_token === BEARER_TOKEN){
|
2023-06-23 17:23:14 +02:00
|
|
|
console.log("PASSWORD CORRECT")
|
2023-06-19 20:38:45 +02:00
|
|
|
await dbConnect();
|
|
|
|
await Recipe.create(recipe_json);
|
|
|
|
await dbDisconnect();
|
2023-06-23 17:23:14 +02:00
|
|
|
return {status: 400} //TODO: cleanup error throwing
|
2023-06-19 20:38:45 +02:00
|
|
|
}
|
|
|
|
else{
|
2023-06-23 17:23:14 +02:00
|
|
|
console.log("PASSWORD INCORRECT")
|
2023-06-19 20:38:45 +02:00
|
|
|
return {status: 403}
|
|
|
|
}
|
|
|
|
};
|