@@ -1,79 +1,26 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
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 __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
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.CreateUserHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const bcrypt = __importStar(require("bcrypt"));
|
||||
const user_entity_1 = require("../../domain/entities/user.entity");
|
||||
const user_repository_interface_1 = require("../../domain/repositories/user.repository.interface");
|
||||
let CreateUserHandler = class CreateUserHandler {
|
||||
userRepository;
|
||||
constructor(userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
constructor() { }
|
||||
async execute(dto) {
|
||||
const exists = await this.userRepository.existsByEmail(dto.email);
|
||||
if (exists) {
|
||||
throw new common_1.ConflictException('Email already exists.');
|
||||
}
|
||||
const saltRounds = parseInt(process.env.BCRYPT_SALT_ROUNDS ?? '10', 10);
|
||||
const hashedPassword = await bcrypt.hash(dto.password, saltRounds);
|
||||
const user = user_entity_1.User.create({
|
||||
name: dto.name,
|
||||
email: dto.email,
|
||||
password: hashedPassword,
|
||||
metadata: dto.metadata,
|
||||
});
|
||||
await this.userRepository.create(user);
|
||||
// TODO:
|
||||
// this.eventDispatcher.publish(new UserCreatedEvent(user));
|
||||
return user;
|
||||
// Legacy handler - creation via this path is deprecated. Use the new handlers under application/handlers/user.
|
||||
throw new common_1.BadRequestException('Deprecated handler. User creation via this endpoint is not supported.');
|
||||
}
|
||||
};
|
||||
exports.CreateUserHandler = CreateUserHandler;
|
||||
exports.CreateUserHandler = CreateUserHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [user_repository_interface_1.UserRepository])
|
||||
__metadata("design:paramtypes", [])
|
||||
], CreateUserHandler);
|
||||
//# sourceMappingURL=create-user.handler.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"create-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/create-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAGwB;AAExB,+CAAiC;AAEjC,mEAAyD;AACzD,mGAAqF;AAG9E,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAET;IADnB,YACmB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,GAAkB;QAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAElE,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,0BAAiB,CAAC,uBAAuB,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QACxE,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEnE,MAAM,IAAI,GAAG,kBAAI,CAAC,MAAM,CAAC;YACvB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,QAAQ,EAAE,cAAc;YACxB,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvC,QAAQ;QACR,4DAA4D;QAE5D,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA7BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGwB,0CAAc;GAFtC,iBAAiB,CA6B7B"}
|
||||
{"version":3,"file":"create-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/create-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiE;AAI1D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,gBAAe,CAAC;IAEhB,KAAK,CAAC,OAAO,CAAC,GAAkB;QAC9B,+GAA+G;QAC/G,MAAM,IAAI,4BAAmB,CAAC,uEAAuE,CAAC,CAAC;IACzG,CAAC;CACF,CAAA;AAPY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;;GACA,iBAAiB,CAO7B"}
|
||||
@@ -1,84 +1,26 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
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 __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
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.UpdateUserHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const bcrypt = __importStar(require("bcrypt"));
|
||||
const user_repository_interface_1 = require("../../domain/repositories/user.repository.interface");
|
||||
let UpdateUserHandler = class UpdateUserHandler {
|
||||
userRepository;
|
||||
constructor(userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
constructor() { }
|
||||
async execute(id, dto) {
|
||||
const user = await this.userRepository.findById(id);
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException('User not found.');
|
||||
}
|
||||
if (dto.email &&
|
||||
dto.email !== user.email) {
|
||||
const exists = await this.userRepository.existsByEmail(dto.email);
|
||||
if (exists) {
|
||||
throw new common_1.ConflictException('Email already exists.');
|
||||
}
|
||||
user.changeEmail(dto.email);
|
||||
}
|
||||
if (dto.name) {
|
||||
user.changeName(dto.name);
|
||||
}
|
||||
if (dto.password) {
|
||||
const saltRounds = parseInt(process.env.BCRYPT_SALT_ROUNDS ?? '10', 10);
|
||||
const hashedPassword = await bcrypt.hash(dto.password, saltRounds);
|
||||
user.changePassword(hashedPassword);
|
||||
}
|
||||
await this.userRepository.update(user);
|
||||
return user;
|
||||
// Legacy handler - deprecated. Use new handlers under application/handlers/user.
|
||||
throw new common_1.BadRequestException('Deprecated handler.');
|
||||
}
|
||||
};
|
||||
exports.UpdateUserHandler = UpdateUserHandler;
|
||||
exports.UpdateUserHandler = UpdateUserHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [user_repository_interface_1.UserRepository])
|
||||
__metadata("design:paramtypes", [])
|
||||
], UpdateUserHandler);
|
||||
//# sourceMappingURL=update-user.handler.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"update-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/update-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAIwB;AAExB,+CAAiC;AAEjC,mGAAqF;AAI9E,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAET;IADnB,YACmB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ,KAAK,CAAC,OAAO,CACX,EAAU,EACV,GAAkB;QAElB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,IACE,GAAG,CAAC,KAAK;YACT,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,EACxB,CAAC;YACD,MAAM,MAAM,GACV,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAErD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,IAAI,0BAAiB,CACzB,uBAAuB,CACxB,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;YACxE,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACnE,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACtC,CAAC;QAED,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA7CY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGwB,0CAAc;GAFtC,iBAAiB,CA6C7B"}
|
||||
{"version":3,"file":"update-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/update-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiE;AAI1D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,gBAAe,CAAC;IAEhB,KAAK,CAAC,OAAO,CAAC,EAAU,EAAE,GAAkB;QAC1C,iFAAiF;QACjF,MAAM,IAAI,4BAAmB,CAAC,qBAAqB,CAAC,CAAC;IACvD,CAAC;CACF,CAAA;AAPY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;;GACA,iBAAiB,CAO7B"}
|
||||
Reference in New Issue
Block a user