test
This commit is contained in:
@@ -1,18 +1,76 @@
|
||||
require('reflect-metadata');
|
||||
const { Sequelize } = require('sequelize-typescript');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Try to find the model file
|
||||
let FoodItem;
|
||||
const distModelPath = path.join(__dirname, '../dist/models/food-item.model.js');
|
||||
|
||||
if (fs.existsSync(distModelPath)) {
|
||||
const modelModule = require(distModelPath);
|
||||
FoodItem = modelModule.FoodItem;
|
||||
let MealFood;
|
||||
let PlannedFood;
|
||||
let Meal;
|
||||
let User;
|
||||
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 {
|
||||
console.error('Could not find compiled FoodItem model at ' + distModelPath);
|
||||
console.error('Please run "npm run build" first.');
|
||||
process.exit(1);
|
||||
console.error('Missing model: ' + foodItemPath);
|
||||
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
|
||||
@@ -29,11 +87,12 @@ if (!process.env.DATABASE_URL) {
|
||||
}
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: dbPath,
|
||||
models: [FoodItem],
|
||||
logging: false
|
||||
dialect: 'sqlite',
|
||||
storage: dbPath,
|
||||
logging: false
|
||||
});
|
||||
const models = [FoodItem].concat([MealFood, PlannedFood, Meal, User, WaterLog, WeightLog, MealPlan, UserGoal, DailySummary, APICache].filter(Boolean));
|
||||
sequelize.addModels(models);
|
||||
|
||||
const filipinoFoods = [
|
||||
// Rice (Kanin)
|
||||
@@ -510,4 +569,4 @@ async function seed() {
|
||||
}
|
||||
}
|
||||
|
||||
seed();
|
||||
seed();
|
||||
|
||||
Reference in New Issue
Block a user