build: add TypeScript configuration and generate declaration files
- 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
This commit is contained in:
100
dist/dashboard/dashboard.controller.js
vendored
Normal file
100
dist/dashboard/dashboard.controller.js
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
"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.DashboardController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const authenticated_guard_1 = require("../auth/guards/authenticated.guard");
|
||||
const utils_service_1 = require("../utils/utils.service");
|
||||
const user_goal_model_1 = require("../models/user-goal.model");
|
||||
const weight_log_model_1 = require("../models/weight-log.model");
|
||||
const sequelize_1 = require("@nestjs/sequelize");
|
||||
let DashboardController = class DashboardController {
|
||||
constructor(utilsService, userGoalModel, weightLogModel) {
|
||||
this.utilsService = utilsService;
|
||||
this.userGoalModel = userGoalModel;
|
||||
this.weightLogModel = weightLogModel;
|
||||
}
|
||||
async getDashboard(req, res) {
|
||||
try {
|
||||
const today = new Date();
|
||||
const dateStr = today.toISOString().split('T')[0];
|
||||
const nutrition = await this.utilsService.calculateDailyTotals(req.user.id, dateStr);
|
||||
const water = await this.utilsService.calculateWaterTotal(req.user.id, dateStr);
|
||||
let goals = await this.userGoalModel.findOne({ where: { UserId: req.user.id } });
|
||||
if (!goals) {
|
||||
goals = await this.userGoalModel.create({
|
||||
UserId: req.user.id,
|
||||
target_protein_g: 150,
|
||||
target_carbs_g: 200,
|
||||
target_fat_g: 60,
|
||||
target_water_ml: 2000,
|
||||
});
|
||||
}
|
||||
const weightLogToday = await this.weightLogModel.findOne({
|
||||
where: { UserId: req.user.id, date: dateStr },
|
||||
});
|
||||
const yesterday = new Date(today);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
const yesterdayStr = yesterday.toISOString().split('T')[0];
|
||||
const weightLogYesterday = await this.weightLogModel.findOne({
|
||||
where: { UserId: req.user.id, date: yesterdayStr },
|
||||
});
|
||||
let weightChange = null;
|
||||
if (weightLogToday && weightLogYesterday) {
|
||||
weightChange = weightLogToday.weight_kg - weightLogYesterday.weight_kg;
|
||||
}
|
||||
const remaining = {
|
||||
calories: req.user.target_daily_calories - nutrition.calories,
|
||||
protein: goals.target_protein_g - nutrition.protein,
|
||||
carbs: goals.target_carbs_g - nutrition.carbs,
|
||||
fat: goals.target_fat_g - nutrition.fat,
|
||||
water: goals.target_water_ml - water.total_ml,
|
||||
};
|
||||
const macroPercentages = this.utilsService.getMacroPercentages(nutrition.protein, nutrition.carbs, nutrition.fat);
|
||||
return {
|
||||
user: req.user,
|
||||
nutrition,
|
||||
water,
|
||||
goals,
|
||||
weightLogToday,
|
||||
weightChange,
|
||||
remaining,
|
||||
macroPercentages,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
req.flash('error_msg', 'Error loading dashboard');
|
||||
return {};
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.DashboardController = DashboardController;
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
(0, common_1.Render)('dashboard'),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], DashboardController.prototype, "getDashboard", null);
|
||||
exports.DashboardController = DashboardController = __decorate([
|
||||
(0, common_1.Controller)('dashboard'),
|
||||
(0, common_1.UseGuards)(authenticated_guard_1.AuthenticatedGuard),
|
||||
__param(1, (0, sequelize_1.InjectModel)(user_goal_model_1.UserGoal)),
|
||||
__param(2, (0, sequelize_1.InjectModel)(weight_log_model_1.WeightLog)),
|
||||
__metadata("design:paramtypes", [utils_service_1.UtilsService, Object, Object])
|
||||
], DashboardController);
|
||||
//# sourceMappingURL=dashboard.controller.js.map
|
||||
Reference in New Issue
Block a user