- Add tsconfig.json for TypeScript compilation with declaration and source map generation - Generate .d.ts declaration files for all modules, services, controllers, and models - Update package.json with NestJS dependencies and TypeScript development tools - Include database files in the distribution output for persistence
125 lines
5.1 KiB
JavaScript
125 lines
5.1 KiB
JavaScript
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.MealPlannerController = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const authenticated_guard_1 = require("../auth/guards/authenticated.guard");
|
|
const meal_planner_service_1 = require("./meal-planner.service");
|
|
let MealPlannerController = class MealPlannerController {
|
|
constructor(mealPlannerService) {
|
|
this.mealPlannerService = mealPlannerService;
|
|
}
|
|
async getMealPlanner(req) {
|
|
try {
|
|
const data = await this.mealPlannerService.getWeeklyMealPlans(req.user.id);
|
|
return {
|
|
user: req.user,
|
|
dates: data.dates,
|
|
meal_plans: data.mealPlans,
|
|
today: data.today,
|
|
};
|
|
}
|
|
catch (err) {
|
|
console.error(err);
|
|
req.flash('error_msg', 'Error loading meal planner');
|
|
return {
|
|
user: req.user,
|
|
dates: [],
|
|
meal_plans: {},
|
|
today: new Date().toISOString().split('T')[0],
|
|
};
|
|
}
|
|
}
|
|
async autoGenerate(req, body, res) {
|
|
try {
|
|
const { date } = body;
|
|
if (!date) {
|
|
req.flash('error_msg', 'Please select a date');
|
|
return res.redirect('/meal-planner');
|
|
}
|
|
await this.mealPlannerService.autoGenerate(req.user.id, date);
|
|
req.flash('success_msg', 'Meal plan generated successfully!');
|
|
res.redirect('/meal-planner');
|
|
}
|
|
catch (err) {
|
|
console.error(err);
|
|
req.flash('error_msg', 'Error generating meal plan');
|
|
res.redirect('/meal-planner');
|
|
}
|
|
}
|
|
async addMealPlan(req, body, res) {
|
|
try {
|
|
await this.mealPlannerService.addMealPlan(req.user.id, body);
|
|
req.flash('success_msg', 'Meal plan updated!');
|
|
res.redirect('/meal-planner');
|
|
}
|
|
catch (err) {
|
|
console.error(err);
|
|
req.flash('error_msg', 'Error adding meal plan');
|
|
res.redirect('/meal-planner');
|
|
}
|
|
}
|
|
async toggleComplete(req, id, res) {
|
|
try {
|
|
await this.mealPlannerService.toggleComplete(req.user.id, id);
|
|
res.json({ success: true });
|
|
}
|
|
catch (err) {
|
|
console.error(err);
|
|
res.status(500).json({ success: false });
|
|
}
|
|
}
|
|
};
|
|
exports.MealPlannerController = MealPlannerController;
|
|
__decorate([
|
|
(0, common_1.Get)(),
|
|
(0, common_1.Render)('meal_planner'),
|
|
__param(0, (0, common_1.Req)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MealPlannerController.prototype, "getMealPlanner", null);
|
|
__decorate([
|
|
(0, common_1.Post)('auto-generate'),
|
|
__param(0, (0, common_1.Req)()),
|
|
__param(1, (0, common_1.Body)()),
|
|
__param(2, (0, common_1.Res)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MealPlannerController.prototype, "autoGenerate", null);
|
|
__decorate([
|
|
(0, common_1.Post)('add'),
|
|
__param(0, (0, common_1.Req)()),
|
|
__param(1, (0, common_1.Body)()),
|
|
__param(2, (0, common_1.Res)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MealPlannerController.prototype, "addMealPlan", null);
|
|
__decorate([
|
|
(0, common_1.Post)('complete/:id'),
|
|
__param(0, (0, common_1.Req)()),
|
|
__param(1, (0, common_1.Param)('id')),
|
|
__param(2, (0, common_1.Res)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Number, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MealPlannerController.prototype, "toggleComplete", null);
|
|
exports.MealPlannerController = MealPlannerController = __decorate([
|
|
(0, common_1.Controller)('meal-planner'),
|
|
(0, common_1.UseGuards)(authenticated_guard_1.AuthenticatedGuard),
|
|
__metadata("design:paramtypes", [meal_planner_service_1.MealPlannerService])
|
|
], MealPlannerController);
|
|
//# sourceMappingURL=meal-planner.controller.js.map
|