artmapper
Version:
Spring Boot clone for Node.js with TypeScript/JavaScript - JPA-like ORM, Lombok decorators, dependency injection, and MySQL support
69 lines • 2.76 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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserService = void 0;
const index_1 = require("../../index");
const UserRepository_1 = require("../repository/UserRepository");
const User_1 = require("../entity/User");
let UserService = class UserService {
async createUser(userData) {
const user = new User_1.User();
user.username = userData.username;
user.email = userData.email;
user.password = userData.password;
user.createdAt = new Date();
user.updatedAt = new Date();
return this.userRepository.save(user);
}
async getUserById(id) {
return this.userRepository.findById(id);
}
async getAllUsers() {
return this.userRepository.findAll();
}
async getUserByUsername(username) {
return this.userRepository.findByUsername(username);
}
async getUserByEmail(email) {
return this.userRepository.findByEmail(email);
}
async updateUser(id, userData) {
const user = await this.userRepository.findById(id);
if (!user) {
return null;
}
if (userData.username)
user.username = userData.username;
if (userData.email)
user.email = userData.email;
if (userData.password)
user.password = userData.password;
user.updatedAt = new Date();
return this.userRepository.save(user);
}
async deleteUser(id) {
const user = await this.userRepository.findById(id);
if (!user) {
return false;
}
await this.userRepository.delete(user);
return true;
}
};
exports.UserService = UserService;
__decorate([
(0, index_1.Autowired)(),
__metadata("design:type", UserRepository_1.UserRepository)
], UserService.prototype, "userRepository", void 0);
exports.UserService = UserService = __decorate([
(0, index_1.Service)('UserService')
], UserService);
//# sourceMappingURL=UserService.js.map