Sign In Prompt
This commit is contained in:
@@ -72,7 +72,7 @@ export default class FDAI {
|
||||
}
|
||||
|
||||
const response = await ollama.generate({
|
||||
model: 'meta-llama-3-1-8b-1',
|
||||
model: 'llama3:latest',
|
||||
format: "json",
|
||||
prompt:
|
||||
`Give one food suggestion for these question answers and then generate a recipe.
|
||||
|
||||
@@ -28,9 +28,8 @@ export default class RecipeAPI extends APIRoute {
|
||||
|
||||
let aiResult = await ai.suggestFood(recipe.currentQuestion, recipe.answers, recipe.restrictions);
|
||||
|
||||
console.log(aiResult);
|
||||
|
||||
let suggestFood = JSON.parse(aiResult.response);
|
||||
suggestFood.userID = recipe.userID;
|
||||
|
||||
let result = await db.create(suggestFood);
|
||||
|
||||
@@ -38,6 +37,7 @@ export default class RecipeAPI extends APIRoute {
|
||||
}
|
||||
|
||||
async rate(req, res) {
|
||||
|
||||
let db = req.app.get('mongo').recipes;
|
||||
|
||||
let recipe = await db.get(req.params.id);
|
||||
@@ -54,9 +54,7 @@ export default class RecipeAPI extends APIRoute {
|
||||
return;
|
||||
}
|
||||
|
||||
recipe.rating = rating;
|
||||
|
||||
let result = await db.update(req.params.id, { rating: rating });
|
||||
let result = await db.update(req.params.id, { rating: recipe.rating + parseInt(rating), ratingCount: recipe.ratingCount + 1 });
|
||||
|
||||
res.send(result);
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import APIRoute from "../APIRoute.js";
|
||||
|
||||
export default class UsersAPI extends APIRoute {
|
||||
constructor() {
|
||||
super('/users');
|
||||
|
||||
this.addSubRoute('/create', 'post', this.createUser);
|
||||
}
|
||||
|
||||
async get(req, res) {
|
||||
res.send('GET request');
|
||||
}
|
||||
|
||||
async post(req, res) {
|
||||
res.send('POST request');
|
||||
}
|
||||
|
||||
async createUser(req, res) {
|
||||
let user = req.body;
|
||||
|
||||
let db = req.app.get('mongo').users;
|
||||
|
||||
let result = await db.create({
|
||||
recipes: [],
|
||||
dietaryRestrictions: [],
|
||||
firstName: "String",
|
||||
lastName: "OtherString",
|
||||
email: ""
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
import mongoose from "mongoose";
|
||||
import Users from "./collections/users.js";
|
||||
import Recipes from "./collections/recipes.js";
|
||||
|
||||
export default class Mongo {
|
||||
constructor(uri) {
|
||||
this.connect(uri);
|
||||
this.users = new Users();
|
||||
this.recipes = new Recipes();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ const recipesSchema = new mongoose.Schema({
|
||||
rating: Number,
|
||||
cuisine: String,
|
||||
expense: Number,
|
||||
mealType: Object
|
||||
mealType: Object,
|
||||
ratingCount: Number
|
||||
}, { timestamps: true });
|
||||
|
||||
export default class Recipes {
|
||||
@@ -43,7 +44,9 @@ export default class Recipes {
|
||||
cuisine: recipe.cuisine,
|
||||
expense: recipe.expense,
|
||||
mealType: recipe.mealType,
|
||||
instructions: recipe.instructions
|
||||
instructions: recipe.instructions,
|
||||
ratingCount: 0,
|
||||
rating: 0
|
||||
}, this.upsert);
|
||||
return await this.get(Id);
|
||||
}
|
||||
@@ -63,6 +66,13 @@ export default class Recipes {
|
||||
return await this.get(Id);
|
||||
}
|
||||
|
||||
async increment(Id, field, amount) {
|
||||
let result = await this.get(Id);
|
||||
if(!result) return null;
|
||||
|
||||
return await this.get(Id);
|
||||
}
|
||||
|
||||
async delete(Id) {
|
||||
let result = await this.get(Id);
|
||||
if(!result) return false;
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import mongoose from "mongoose";
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const reqString = {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
|
||||
const UserSchema = new mongoose.Schema({
|
||||
id: reqString,
|
||||
recipes: Array,
|
||||
dietaryRestrictions: Array,
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
email: String
|
||||
}, { timestamps: true });
|
||||
|
||||
export default class Users {
|
||||
constructor() {
|
||||
this.model = mongoose.model('users', UserSchema);
|
||||
this.upsert = { upsert: true };
|
||||
}
|
||||
|
||||
|
||||
async create(user) {
|
||||
if(await this.model.findOne({ username: user.username }) || await this.model.findOne({ email: user.email })) return null;
|
||||
|
||||
let Id = uuidv4();
|
||||
|
||||
|
||||
await this.model.findOneAndUpdate({ id: Id }, {
|
||||
id: Id,
|
||||
recipes: user.recipes,
|
||||
dietaryRestrictions: user.dietaryRestrictions,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
email: user.Email
|
||||
}, this.upsert);
|
||||
return await this.get(user.id);
|
||||
}
|
||||
|
||||
async get(Id) {
|
||||
let data = await this.model.findOne({ id: Id });
|
||||
if(data) data.password = undefined;
|
||||
return data;
|
||||
}
|
||||
|
||||
async getByUsername(username) {
|
||||
let data = await this.model.findOne({ username: username }) || await this.model.findOne({ email: username });
|
||||
if(data) data.password = undefined;
|
||||
return data;
|
||||
}
|
||||
|
||||
async getAll(query) {
|
||||
let data = await this.model.find(query);
|
||||
data.forEach(user => {
|
||||
user.password = undefined;
|
||||
});
|
||||
return data
|
||||
}
|
||||
|
||||
async update(Id, data) {
|
||||
if(!(await this.get(Id))) return null;
|
||||
await this.model.findOneAndUpdate({ id: Id }, data, this.upsert);
|
||||
return await this.get(Id);
|
||||
}
|
||||
|
||||
async delete(Id) {
|
||||
let result = await this.get(Id);
|
||||
if(!result) return false;
|
||||
await this.model.deleteOne({ id: Id })
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user