test
This commit is contained in:
@@ -1,19 +1,77 @@
|
|||||||
|
require('reflect-metadata');
|
||||||
const { Sequelize } = require('sequelize-typescript');
|
const { Sequelize } = require('sequelize-typescript');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
// Try to find the model file
|
|
||||||
let FoodItem;
|
let FoodItem;
|
||||||
const distModelPath = path.join(__dirname, '../dist/models/food-item.model.js');
|
let MealFood;
|
||||||
|
let PlannedFood;
|
||||||
if (fs.existsSync(distModelPath)) {
|
let Meal;
|
||||||
const modelModule = require(distModelPath);
|
let User;
|
||||||
FoodItem = modelModule.FoodItem;
|
let WaterLog;
|
||||||
|
let WeightLog;
|
||||||
|
let MealPlan;
|
||||||
|
let UserGoal;
|
||||||
|
let DailySummary;
|
||||||
|
let APICache;
|
||||||
|
const foodItemPath = path.join(__dirname, '../dist/models/food-item.model.js');
|
||||||
|
const mealFoodPath = path.join(__dirname, '../dist/models/meal-food.model.js');
|
||||||
|
const plannedFoodPath = path.join(__dirname, '../dist/models/planned-food.model.js');
|
||||||
|
const mealPath = path.join(__dirname, '../dist/models/meal.model.js');
|
||||||
|
const userPath = path.join(__dirname, '../dist/models/user.model.js');
|
||||||
|
const waterLogPath = path.join(__dirname, '../dist/models/water-log.model.js');
|
||||||
|
const weightLogPath = path.join(__dirname, '../dist/models/weight-log.model.js');
|
||||||
|
const mealPlanPath = path.join(__dirname, '../dist/models/meal-plan.model.js');
|
||||||
|
const userGoalPath = path.join(__dirname, '../dist/models/user-goal.model.js');
|
||||||
|
const dailySummaryPath = path.join(__dirname, '../dist/models/daily-summary.model.js');
|
||||||
|
const apiCachePath = path.join(__dirname, '../dist/models/api-cache.model.js');
|
||||||
|
if (fs.existsSync(foodItemPath)) {
|
||||||
|
const mod = require(foodItemPath);
|
||||||
|
FoodItem = mod.FoodItem;
|
||||||
} else {
|
} else {
|
||||||
console.error('Could not find compiled FoodItem model at ' + distModelPath);
|
console.error('Missing model: ' + foodItemPath);
|
||||||
console.error('Please run "npm run build" first.');
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
if (fs.existsSync(mealFoodPath)) {
|
||||||
|
const mod = require(mealFoodPath);
|
||||||
|
MealFood = mod.MealFood;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(plannedFoodPath)) {
|
||||||
|
const mod = require(plannedFoodPath);
|
||||||
|
PlannedFood = mod.PlannedFood;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(mealPath)) {
|
||||||
|
const mod = require(mealPath);
|
||||||
|
Meal = mod.Meal;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(userPath)) {
|
||||||
|
const mod = require(userPath);
|
||||||
|
User = mod.User;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(waterLogPath)) {
|
||||||
|
const mod = require(waterLogPath);
|
||||||
|
WaterLog = mod.WaterLog;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(weightLogPath)) {
|
||||||
|
const mod = require(weightLogPath);
|
||||||
|
WeightLog = mod.WeightLog;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(mealPlanPath)) {
|
||||||
|
const mod = require(mealPlanPath);
|
||||||
|
MealPlan = mod.MealPlan;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(userGoalPath)) {
|
||||||
|
const mod = require(userGoalPath);
|
||||||
|
UserGoal = mod.UserGoal;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(dailySummaryPath)) {
|
||||||
|
const mod = require(dailySummaryPath);
|
||||||
|
DailySummary = mod.DailySummary;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(apiCachePath)) {
|
||||||
|
const mod = require(apiCachePath);
|
||||||
|
APICache = mod.APICache;
|
||||||
|
}
|
||||||
|
|
||||||
// Database connection
|
// Database connection
|
||||||
const dbPath = process.env.DATABASE_URL
|
const dbPath = process.env.DATABASE_URL
|
||||||
@@ -31,9 +89,10 @@ if (!process.env.DATABASE_URL) {
|
|||||||
const sequelize = new Sequelize({
|
const sequelize = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
storage: dbPath,
|
storage: dbPath,
|
||||||
models: [FoodItem],
|
|
||||||
logging: false
|
logging: false
|
||||||
});
|
});
|
||||||
|
const models = [FoodItem].concat([MealFood, PlannedFood, Meal, User, WaterLog, WeightLog, MealPlan, UserGoal, DailySummary, APICache].filter(Boolean));
|
||||||
|
sequelize.addModels(models);
|
||||||
|
|
||||||
const filipinoFoods = [
|
const filipinoFoods = [
|
||||||
// Rice (Kanin)
|
// Rice (Kanin)
|
||||||
|
|||||||
Reference in New Issue
Block a user