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:
Jp
2026-01-31 09:00:26 +08:00
parent 0fa0343798
commit f521970a65
174 changed files with 7205 additions and 1633 deletions

94
dist/goals/goals.service.js vendored Normal file
View File

@@ -0,0 +1,94 @@
"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.GoalsService = void 0;
const common_1 = require("@nestjs/common");
const sequelize_1 = require("@nestjs/sequelize");
const user_model_1 = require("../models/user.model");
const user_goal_model_1 = require("../models/user-goal.model");
const utils_service_1 = require("../utils/utils.service");
let GoalsService = class GoalsService {
constructor(userModel, userGoalModel, utilsService) {
this.userModel = userModel;
this.userGoalModel = userGoalModel;
this.utilsService = utilsService;
}
async getGoals(userId) {
const user = await this.userModel.findByPk(userId);
const userGoals = await this.userGoalModel.findOne({ where: { UserId: userId } });
let bmr = null;
let tdee = null;
if (user && user.weight_kg && user.height_cm && user.age) {
bmr = this.utilsService.calculateBMR(user.weight_kg, user.height_cm, user.age, user.gender || 'male');
tdee = this.utilsService.calculateTDEE(bmr, user.activity_level || 'moderate');
}
return {
goals: userGoals,
bmr,
tdee,
user,
};
}
async updateGoals(userId, data) {
const user = await this.userModel.findByPk(userId);
if (!user) {
throw new Error('User not found');
}
user.age = parseInt(data.age) || 25;
user.gender = data.gender || 'male';
user.height_cm = parseFloat(data.height_cm) || 170;
user.weight_kg = parseFloat(data.weight_kg) || 70;
user.activity_level = data.activity_level || 'moderate';
const bmr = this.utilsService.calculateBMR(user.weight_kg, user.height_cm, user.age, user.gender);
const tdee = this.utilsService.calculateTDEE(bmr, user.activity_level);
const goalType = data.goal_type || 'recomp';
let targetCalories;
if (goalType === 'weight_loss') {
targetCalories = tdee - 500;
}
else if (goalType === 'muscle_gain') {
targetCalories = tdee + 300;
}
else {
targetCalories = tdee;
}
user.target_daily_calories = Math.round(targetCalories);
await user.save();
let userGoals = await this.userGoalModel.findOne({ where: { UserId: userId } });
if (!userGoals) {
userGoals = await this.userGoalModel.create({ UserId: userId });
}
userGoals.goal_type = goalType;
userGoals.target_weight_kg = parseFloat(data.target_weight_kg) || 70;
const macros = this.utilsService.calculateMacroTargets(user.weight_kg, goalType);
userGoals.target_protein_g = macros.protein_g;
userGoals.target_carbs_g = macros.carbs_g;
userGoals.target_fat_g = macros.fat_g;
userGoals.target_water_ml = parseInt(data.target_water_ml) || 2000;
await userGoals.save();
return {
success: true,
user,
goals: userGoals,
};
}
};
exports.GoalsService = GoalsService;
exports.GoalsService = GoalsService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, sequelize_1.InjectModel)(user_model_1.User)),
__param(1, (0, sequelize_1.InjectModel)(user_goal_model_1.UserGoal)),
__metadata("design:paramtypes", [Object, Object, utils_service_1.UtilsService])
], GoalsService);
//# sourceMappingURL=goals.service.js.map