feat(SPG-324) REST API CUD Users
parent
9431e27013
commit
cfb896921b
|
@ -1,5 +1,6 @@
|
|||
export enum MODULE_NAME {
|
||||
TENANT = 'tenants',
|
||||
USER = 'users',
|
||||
USER_PRIVILEGE = 'user-privileges',
|
||||
USER_PRIVILEGE_CONFIGURATION = 'user-privilege-configurations',
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@ import { AuthController } from './infrastructure/auth.controller';
|
|||
import { LoginManager } from './domain/managers/login.manager';
|
||||
import { LogoutManager } from './domain/managers/logout.manager';
|
||||
import { AuthOrchestrator } from './domain/auth.orchestrator';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services.ts/user-data.service';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services.ts/user-data.service';
|
||||
import { LoginManager } from './managers/login.manager';
|
||||
import { LogoutManager } from './managers/logout.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthOrchestrator {
|
||||
|
|
|
@ -14,8 +14,8 @@ import { BatchActiveTenantManager } from './managers/batch-active-tenant.manager
|
|||
import { BatchDeleteTenantManager } from './managers/batch-delete-tenant.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services.ts/user-data.service';
|
||||
import { UpdatePasswordTenantManager } from './managers/update-password-tenant.manager';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class TenantDataOrchestrator extends BaseDataTransactionOrchestrator<UserEntity> {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrat
|
|||
import { DetailTenantManager } from './managers/detail-tenant.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
import { UserReadService } from 'src/modules/user-related/user/data/services.ts/user-read.service';
|
||||
import { UserReadService } from 'src/modules/user-related/user/data/services/user-read.service';
|
||||
|
||||
@Injectable()
|
||||
export class TenantReadOrchestrator extends BaseReadOrchestrator<UserEntity> {
|
||||
|
|
|
@ -20,9 +20,9 @@ import { BatchActiveTenantManager } from './domain/usecases/managers/batch-activ
|
|||
import { BatchConfirmTenantManager } from './domain/usecases/managers/batch-confirm-tenant.manager';
|
||||
import { BatchInactiveTenantManager } from './domain/usecases/managers/batch-inactive-tenant.manager';
|
||||
import { UserModel } from '../user/data/models/user.model';
|
||||
import { UserDataService } from '../user/data/services.ts/user-data.service';
|
||||
import { UserReadService } from '../user/data/services.ts/user-read.service';
|
||||
import { UpdatePasswordTenantManager } from './domain/usecases/managers/update-password-tenant.manager';
|
||||
import { UserDataService } from '../user/data/services/user-data.service';
|
||||
import { UserReadService } from '../user/data/services/user-read.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||
import { UserEntity } from '../../domain/entities/user.entity';
|
||||
import { UserRole } from '../../constants';
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||
import { UserPrivilegeModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege.model';
|
||||
import { UserRole } from '../../constants';
|
||||
|
||||
@Entity(TABLE_NAME.USER)
|
||||
export class UserModel
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||
import { UserEntity } from '../../domain/entities/user.entity';
|
||||
import { UserModel } from '../models/user.model';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserModel } from '../models/user.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class UserDataService extends BaseDataService<UserEntity> {
|
|
@ -1,10 +1,10 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
import { UserEntity } from '../../domain/entities/user.entity';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { UserModel } from '../models/user.model';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { UserModel } from '../models/user.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
|
||||
@Injectable()
|
||||
export class UserReadService extends BaseReadService<UserEntity> {
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class UserChangeStatusEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class UserCreatedEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class UserDeletedEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class UserUpdatedEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserChangeStatusEvent } from '../../entities/event/user-change-status.event';
|
||||
|
||||
@Injectable()
|
||||
export class ActiveUserManager extends BaseUpdateStatusManager<UserEntity> {
|
||||
getResult(): string {
|
||||
return `Success active data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserChangeStatusEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserChangeStatusEvent } from '../../entities/event/user-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchActiveUserManager extends BaseBatchUpdateStatusManager<UserEntity> {
|
||||
validateData(data: UserEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserChangeStatusEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserChangeStatusEvent } from '../../entities/event/user-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchConfirmUserManager extends BaseBatchUpdateStatusManager<UserEntity> {
|
||||
validateData(data: UserEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserChangeStatusEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserDeletedEvent } from '../../entities/event/user-deleted.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchDeleteUserManager extends BaseBatchDeleteManager<UserEntity> {
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async validateData(data: UserEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserDeletedEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserChangeStatusEvent } from '../../entities/event/user-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchInactiveUserManager extends BaseBatchUpdateStatusManager<UserEntity> {
|
||||
validateData(data: UserEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserChangeStatusEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserChangeStatusEvent } from '../../entities/event/user-change-status.event';
|
||||
|
||||
@Injectable()
|
||||
export class ConfirmUserManager extends BaseUpdateStatusManager<UserEntity> {
|
||||
getResult(): string {
|
||||
return `Success active data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserChangeStatusEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
EventTopics,
|
||||
columnUniques,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||
import { UserCreatedEvent } from '../../entities/event/user-created.event';
|
||||
import { UserRole } from '../../../constants';
|
||||
import { hashPassword } from 'src/core/helpers/password/bcrypt.helpers';
|
||||
import { SALT_OR_ROUNDS } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
@Injectable()
|
||||
export class CreateUserManager extends BaseCreateManager<UserEntity> {
|
||||
async beforeProcess(): Promise<void> {
|
||||
let role = UserRole.STAFF;
|
||||
if (this.data.is_super_admin || !this.data.user_privilege)
|
||||
role = UserRole.SUPERADMIN;
|
||||
|
||||
Object.assign(this.data, {
|
||||
role: role,
|
||||
password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async generateConfig(): Promise<void> {}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [
|
||||
{
|
||||
column: 'username',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserCreatedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserDeletedEvent } from '../../entities/event/user-deleted.event';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteUserManager extends BaseDeleteManager<UserEntity> {
|
||||
getResult(): string {
|
||||
return `Success`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserDeletedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserChangeStatusEvent } from '../../entities/event/user-change-status.event';
|
||||
|
||||
@Injectable()
|
||||
export class InactiveUserManager extends BaseUpdateStatusManager<UserEntity> {
|
||||
getResult(): string {
|
||||
return `Success inactive data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserChangeStatusEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserUpdatedEvent } from '../../entities/event/user-updated.event';
|
||||
import {
|
||||
EventTopics,
|
||||
columnUniques,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { hashPassword } from 'src/core/helpers/password/bcrypt.helpers';
|
||||
import { SALT_OR_ROUNDS } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
@Injectable()
|
||||
export class UpdatePasswordUserManager extends BaseUpdateManager<UserEntity> {
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
Object.assign(this.data, {
|
||||
password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserUpdatedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
|
||||
import { UserEntity } from '../../entities/user.entity';
|
||||
import { UserModel } from '../../../data/models/user.model';
|
||||
import { UserUpdatedEvent } from '../../entities/event/user-updated.event';
|
||||
import {
|
||||
EventTopics,
|
||||
columnUniques,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { UserRole } from '../../../constants';
|
||||
|
||||
@Injectable()
|
||||
export class UpdateUserManager extends BaseUpdateManager<UserEntity> {
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
let role = UserRole.STAFF;
|
||||
if (this.data.is_super_admin || !this.data.user_privilege)
|
||||
role = UserRole.SUPERADMIN;
|
||||
|
||||
Object.assign(this.data, {
|
||||
role: role,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [
|
||||
{
|
||||
column: 'username',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserUpdatedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateUserManager } from './managers/create-user.manager';
|
||||
import { UserDataService } from '../../data/services/user-data.service';
|
||||
import { UserEntity } from '../entities/user.entity';
|
||||
import { DeleteUserManager } from './managers/delete-user.manager';
|
||||
import { UpdateUserManager } from './managers/update-user.manager';
|
||||
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
|
||||
import { ActiveUserManager } from './managers/active-user.manager';
|
||||
import { InactiveUserManager } from './managers/inactive-user.manager';
|
||||
import { ConfirmUserManager } from './managers/confirm-user.manager';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { BatchConfirmUserManager } from './managers/batch-confirm-user.manager';
|
||||
import { BatchInactiveUserManager } from './managers/batch-inactive-user.manager';
|
||||
import { BatchActiveUserManager } from './managers/batch-active-user.manager';
|
||||
import { BatchDeleteUserManager } from './managers/batch-delete-user.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { UpdatePasswordUserManager } from './managers/update-password-user.manager';
|
||||
|
||||
@Injectable()
|
||||
export class UserDataOrchestrator extends BaseDataTransactionOrchestrator<UserEntity> {
|
||||
constructor(
|
||||
private createManager: CreateUserManager,
|
||||
private updateManager: UpdateUserManager,
|
||||
private deleteManager: DeleteUserManager,
|
||||
private activeManager: ActiveUserManager,
|
||||
private confirmManager: ConfirmUserManager,
|
||||
private inactiveManager: InactiveUserManager,
|
||||
private batchDeleteManager: BatchDeleteUserManager,
|
||||
private batchActiveManager: BatchActiveUserManager,
|
||||
private batchConfirmManager: BatchConfirmUserManager,
|
||||
private batchInactiveManager: BatchInactiveUserManager,
|
||||
private updatePasswordManager: UpdatePasswordUserManager,
|
||||
private serviceData: UserDataService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async create(data): Promise<UserEntity> {
|
||||
this.createManager.setData(data);
|
||||
this.createManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.createManager.execute();
|
||||
await this.createManager.generateConfig();
|
||||
return this.createManager.getResult();
|
||||
}
|
||||
|
||||
async update(dataId, data): Promise<UserEntity> {
|
||||
this.updateManager.setData(dataId, data);
|
||||
this.updateManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.updateManager.execute();
|
||||
return this.updateManager.getResult();
|
||||
}
|
||||
|
||||
async updatePassword(dataId, data): Promise<UserEntity> {
|
||||
this.updatePasswordManager.setData(dataId, data);
|
||||
this.updatePasswordManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.updatePasswordManager.execute();
|
||||
return this.updatePasswordManager.getResult();
|
||||
}
|
||||
|
||||
async delete(dataId): Promise<String> {
|
||||
this.deleteManager.setData(dataId);
|
||||
this.deleteManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.deleteManager.execute();
|
||||
return this.deleteManager.getResult();
|
||||
}
|
||||
|
||||
async batchDelete(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchDeleteManager.setData(dataIds);
|
||||
this.batchDeleteManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.batchDeleteManager.execute();
|
||||
return this.batchDeleteManager.getResult();
|
||||
}
|
||||
|
||||
async active(dataId): Promise<String> {
|
||||
this.activeManager.setData(dataId, STATUS.ACTIVE);
|
||||
this.activeManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.activeManager.execute();
|
||||
return this.activeManager.getResult();
|
||||
}
|
||||
|
||||
async batchActive(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchActiveManager.setData(dataIds, STATUS.ACTIVE);
|
||||
this.batchActiveManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.batchActiveManager.execute();
|
||||
return this.batchActiveManager.getResult();
|
||||
}
|
||||
|
||||
async confirm(dataId): Promise<String> {
|
||||
this.confirmManager.setData(dataId, STATUS.ACTIVE);
|
||||
this.confirmManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.confirmManager.execute();
|
||||
return this.confirmManager.getResult();
|
||||
}
|
||||
|
||||
async batchConfirm(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE);
|
||||
this.batchConfirmManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.batchConfirmManager.execute();
|
||||
return this.batchConfirmManager.getResult();
|
||||
}
|
||||
|
||||
async inactive(dataId): Promise<String> {
|
||||
this.inactiveManager.setData(dataId, STATUS.INACTIVE);
|
||||
this.inactiveManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.inactiveManager.execute();
|
||||
return this.inactiveManager.getResult();
|
||||
}
|
||||
|
||||
async batchInactive(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE);
|
||||
this.batchInactiveManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.batchInactiveManager.execute();
|
||||
return this.batchInactiveManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { IsString } from 'class-validator';
|
||||
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
|
||||
export class UpdatePasswordUserDto extends BaseStatusDto implements UserEntity {
|
||||
@ApiProperty({ name: 'password', required: true, example: 'Tenant123!' })
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@Exclude()
|
||||
name: string;
|
||||
|
||||
@Exclude()
|
||||
username: string;
|
||||
|
||||
@Exclude()
|
||||
share_margin: number;
|
||||
|
||||
@Exclude()
|
||||
email: string;
|
||||
|
||||
@Exclude()
|
||||
role: UserRole;
|
||||
|
||||
@Exclude()
|
||||
refresh_token: string;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { IsBoolean, IsObject, IsString, ValidateIf } from 'class-validator';
|
||||
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||
import { UserPrivilegeModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege.model';
|
||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
|
||||
export class UpdateUserDto extends BaseStatusDto implements UserEntity {
|
||||
@ApiProperty({ name: 'name', required: true, example: 'Amanda' })
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ name: 'username', required: true, example: 'amanda' })
|
||||
@IsString()
|
||||
username: string;
|
||||
|
||||
@ApiProperty({
|
||||
name: 'is_super_admin',
|
||||
type: Boolean,
|
||||
required: true,
|
||||
example: false,
|
||||
})
|
||||
@IsBoolean()
|
||||
is_super_admin: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
name: 'user_privilege',
|
||||
type: Object,
|
||||
required: false,
|
||||
example: {
|
||||
id: 'uuid',
|
||||
},
|
||||
})
|
||||
@IsObject()
|
||||
@ValidateIf((body) => body.user_privilege)
|
||||
user_privilege: UserPrivilegeModel;
|
||||
|
||||
@Exclude()
|
||||
share_margin: number;
|
||||
|
||||
@Exclude()
|
||||
email: string;
|
||||
|
||||
@Exclude()
|
||||
password: string;
|
||||
|
||||
@Exclude()
|
||||
role: UserRole;
|
||||
|
||||
@Exclude()
|
||||
refresh_token: string;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||
import { UserEntity } from '../../domain/entities/user.entity';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { IsString, ValidateIf, IsBoolean, IsObject } from 'class-validator';
|
||||
import { UserRole } from '../../constants';
|
||||
import { UserPrivilegeModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege.model';
|
||||
|
||||
export class UserDto extends BaseStatusDto implements UserEntity {
|
||||
@ApiProperty({ name: 'name', required: true, example: 'Amanda' })
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ name: 'username', required: true, example: 'amanda' })
|
||||
@IsString()
|
||||
username: string;
|
||||
|
||||
@ApiProperty({ name: 'password', required: true, example: 'Eigen123!' })
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@ApiProperty({
|
||||
name: 'user_privilege',
|
||||
type: Object,
|
||||
required: false,
|
||||
example: {
|
||||
id: 'uuid',
|
||||
},
|
||||
})
|
||||
@IsObject()
|
||||
@ValidateIf((body) => body.user_privilege)
|
||||
user_privilege: UserPrivilegeModel;
|
||||
|
||||
@ApiProperty({
|
||||
name: 'is_super_admin',
|
||||
type: Boolean,
|
||||
required: true,
|
||||
example: false,
|
||||
})
|
||||
@IsBoolean()
|
||||
is_super_admin: boolean;
|
||||
|
||||
@Exclude()
|
||||
share_margin: number;
|
||||
|
||||
@Exclude()
|
||||
email: string;
|
||||
|
||||
@Exclude()
|
||||
role: UserRole;
|
||||
|
||||
@Exclude()
|
||||
refresh_token: string;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
|
||||
import { UserDto } from './dto/user.dto';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { UserEntity } from '../domain/entities/user.entity';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { UpdatePasswordUserDto } from './dto/update-password-user.dto';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.USER.split('-').join(' ')} - data`)
|
||||
@Controller(MODULE_NAME.USER)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class UserDataController {
|
||||
constructor(private orchestrator: UserDataOrchestrator) {}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: UserDto): Promise<UserEntity> {
|
||||
return await this.orchestrator.create(data);
|
||||
}
|
||||
|
||||
@Put('/batch-delete')
|
||||
async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchDelete(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/active')
|
||||
async active(@Param('id') dataId: string): Promise<String> {
|
||||
return await this.orchestrator.active(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-active')
|
||||
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchActive(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/confirm')
|
||||
async confirm(@Param('id') dataId: string): Promise<String> {
|
||||
return await this.orchestrator.confirm(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-confirm')
|
||||
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchConfirm(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/inactive')
|
||||
async inactive(@Param('id') dataId: string): Promise<String> {
|
||||
return await this.orchestrator.inactive(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-inactive')
|
||||
async batchInactive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchInactive(body.ids);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Param('id') dataId: string,
|
||||
@Body() data: UpdateUserDto,
|
||||
): Promise<UserEntity> {
|
||||
return await this.orchestrator.update(dataId, data);
|
||||
}
|
||||
|
||||
@Put(':id/change-password')
|
||||
async updatePassword(
|
||||
@Param('id') dataId: string,
|
||||
@Body() data: UpdatePasswordUserDto,
|
||||
): Promise<UserEntity> {
|
||||
return await this.orchestrator.updatePassword(dataId, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') dataId: string): Promise<String> {
|
||||
return await this.orchestrator.delete(dataId);
|
||||
}
|
||||
}
|
|
@ -2,10 +2,27 @@ import { Module } from '@nestjs/common';
|
|||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { UserDataService } from './data/services/user-data.service';
|
||||
import { UserReadService } from './data/services/user-read.service';
|
||||
import { UserReadController } from './infrastructure/user-read.controller';
|
||||
import { UserReadOrchestrator } from './domain/usecases/user-read.orchestrator';
|
||||
import { UserDataController } from './infrastructure/user-data.controller';
|
||||
import { UserDataOrchestrator } from './domain/usecases/user-data.orchestrator';
|
||||
import { CreateUserManager } from './domain/usecases/managers/create-user.manager';
|
||||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { IndexUserManager } from './domain/usecases/managers/index-user.manager';
|
||||
import { DeleteUserManager } from './domain/usecases/managers/delete-user.manager';
|
||||
import { UpdateUserManager } from './domain/usecases/managers/update-user.manager';
|
||||
import { ActiveUserManager } from './domain/usecases/managers/active-user.manager';
|
||||
import { ConfirmUserManager } from './domain/usecases/managers/confirm-user.manager';
|
||||
import { InactiveUserManager } from './domain/usecases/managers/inactive-user.manager';
|
||||
import { DetailUserManager } from './domain/usecases/managers/detail-user.manager';
|
||||
import { BatchDeleteUserManager } from './domain/usecases/managers/batch-delete-user.manager';
|
||||
import { BatchActiveUserManager } from './domain/usecases/managers/batch-active-user.manager';
|
||||
import { BatchConfirmUserManager } from './domain/usecases/managers/batch-confirm-user.manager';
|
||||
import { BatchInactiveUserManager } from './domain/usecases/managers/batch-inactive-user.manager';
|
||||
import { UserModel } from './data/models/user.model';
|
||||
import { UserReadService } from './data/services.ts/user-read.service';
|
||||
import { UserDataService } from './data/services.ts/user-data.service';
|
||||
import { UpdatePasswordUserManager } from './domain/usecases/managers/update-password-user.manager';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -13,8 +30,27 @@ import { UserDataService } from './data/services.ts/user-data.service';
|
|||
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT),
|
||||
CqrsModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [UserReadService, UserDataService],
|
||||
exports: [UserDataService],
|
||||
controllers: [UserDataController, UserReadController],
|
||||
providers: [
|
||||
IndexUserManager,
|
||||
DetailUserManager,
|
||||
CreateUserManager,
|
||||
DeleteUserManager,
|
||||
UpdateUserManager,
|
||||
UpdatePasswordUserManager,
|
||||
ActiveUserManager,
|
||||
ConfirmUserManager,
|
||||
InactiveUserManager,
|
||||
BatchDeleteUserManager,
|
||||
BatchActiveUserManager,
|
||||
BatchConfirmUserManager,
|
||||
BatchInactiveUserManager,
|
||||
|
||||
UserDataService,
|
||||
UserReadService,
|
||||
|
||||
UserDataOrchestrator,
|
||||
UserReadOrchestrator,
|
||||
],
|
||||
})
|
||||
export class UserModule {}
|
||||
|
|
Loading…
Reference in New Issue