hivest-js
Version:
A simple, fast and minimalist framework for Node.js that allows you to create modular applications with dependency injection using decorators
78 lines • 3.39 kB
JavaScript
;
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.SettingsController = void 0;
const tsyringe_1 = require("tsyringe");
const decorators_1 = require("../../../lib/decorators");
const user_service_1 = require("./user.service");
let SettingsController = class SettingsController {
constructor(userService) {
this.userService = userService;
}
async getSettings({ req, res }) {
// Simulate getting user settings
const user = await this.userService.getUser('1'); // Mock user
return res.status(200).json({
message: 'Settings retrieved',
settings: {
theme: 'dark',
language: 'en',
notifications: true,
userId: user.id,
},
});
}
async updateTheme({ req, res }) {
// Simulate updating theme
const { theme } = req.body;
return res.status(200).json({
message: 'Theme updated successfully',
theme: theme || 'dark',
});
}
async updateNotifications({ req, res }) {
// Simulate updating notifications
const { enabled } = req.body;
return res.status(200).json({
message: 'Notifications updated successfully',
notifications: enabled !== false,
});
}
};
exports.SettingsController = SettingsController;
__decorate([
(0, decorators_1.HttpGet)('/'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SettingsController.prototype, "getSettings", null);
__decorate([
(0, decorators_1.HttpPut)('/theme'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SettingsController.prototype, "updateTheme", null);
__decorate([
(0, decorators_1.HttpPut)('/notifications'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SettingsController.prototype, "updateNotifications", null);
exports.SettingsController = SettingsController = __decorate([
(0, tsyringe_1.injectable)(),
(0, decorators_1.Controller)({ path: '/settings' }),
__param(0, (0, tsyringe_1.inject)('UserService')),
__metadata("design:paramtypes", [user_service_1.UserService])
], SettingsController);
//# sourceMappingURL=settings.controller.js.map