Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development
continuous-integration/drone/push Build is passing Details

pull/93/head
shancheas 2024-09-18 13:55:57 +07:00
commit ffbbf6e140
45 changed files with 831 additions and 79 deletions

View File

@ -77,6 +77,8 @@ import { ExportModule } from './modules/configuration/export/export.module';
import { TransactionDemographyModel } from './modules/transaction/transaction/data/models/transaction-demography.model'; import { TransactionDemographyModel } from './modules/transaction/transaction/data/models/transaction-demography.model';
import { SupersetModule } from './modules/configuration/superset/superset.module'; import { SupersetModule } from './modules/configuration/superset/superset.module';
import { GateScanModule } from './modules/gates/gate.module'; import { GateScanModule } from './modules/gates/gate.module';
import { UserLoginModel } from './modules/user-related/user/data/models/user-login.model';
import { LogUserLoginModel } from './modules/configuration/log/data/models/log-user-login.model';
@Module({ @Module({
imports: [ imports: [
@ -102,6 +104,7 @@ import { GateScanModule } from './modules/gates/gate.module';
ItemCategoryModel, ItemCategoryModel,
ItemRateModel, ItemRateModel,
LogModel, LogModel,
LogUserLoginModel,
NewsModel, NewsModel,
PaymentMethodModel, PaymentMethodModel,
PosLogModel, PosLogModel,
@ -118,6 +121,8 @@ import { GateScanModule } from './modules/gates/gate.module';
TransactionDemographyModel, TransactionDemographyModel,
TransactionItemBreakdownModel, TransactionItemBreakdownModel,
UserModel, UserModel,
UserLoginModel,
VipCategoryModel, VipCategoryModel,
VipCodeModel, VipCodeModel,

View File

@ -0,0 +1,4 @@
export enum LogUserType {
login = 'login',
logout = 'logout',
}

View File

@ -26,6 +26,8 @@ export enum TABLE_NAME {
TRANSACTION_ITEM_BREAKDOWN_TAX = 't_breakdown_item_taxes', TRANSACTION_ITEM_BREAKDOWN_TAX = 't_breakdown_item_taxes',
TRANSACTION_DEMOGRAPHY = 'transaction_demographies', TRANSACTION_DEMOGRAPHY = 'transaction_demographies',
USER = 'users', USER = 'users',
USER_LOGIN = 'users_login',
LOG_USER_LOGIN = 'log_users_login',
USER_PRIVILEGE = 'user_privileges', USER_PRIVILEGE = 'user_privileges',
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations', USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
VIP_CATEGORY = 'vip_categories', VIP_CATEGORY = 'vip_categories',

View File

@ -0,0 +1,21 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTableUserLogin1726115025759 implements MigrationInterface {
name = 'AddTableUserLogin1726115025759';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "users_login" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "login_date" bigint NOT NULL, "login_token" character varying, "user_id" uuid, CONSTRAINT "REL_2a80a213b51423ce5b8211f058" UNIQUE ("user_id"), CONSTRAINT "PK_e564194a9a22f8c623354284f75" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(`DROP TABLE "users_login"`);
}
}

View File

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class UpdateTableUserLogin1726122619596 implements MigrationInterface {
name = 'UpdateTableUserLogin1726122619596';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
}

View File

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTableLogUserLogin1726123955427 implements MigrationInterface {
name = 'AddTableLogUserLogin1726123955427';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."log_users_login_type_enum" AS ENUM('login', 'logout')`,
);
await queryRunner.query(
`CREATE TYPE "public"."log_users_login_role_enum" AS ENUM('superadmin', 'staff', 'tenant', 'queue_admin')`,
);
await queryRunner.query(
`CREATE TABLE "log_users_login" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."log_users_login_type_enum", "role" "public"."log_users_login_role_enum", "user_id" uuid, "username" character varying, "created_at" bigint, CONSTRAINT "PK_75141588aa6ee560504f7d3adce" PRIMARY KEY ("id"))`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "log_users_login"`);
await queryRunner.query(`DROP TYPE "public"."log_users_login_role_enum"`);
await queryRunner.query(`DROP TYPE "public"."log_users_login_type_enum"`);
}
}

View File

@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddColumnItemId1726139426994 implements MigrationInterface {
name = 'AddColumnItemId1726139426994';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users_login" ADD "item_id" uuid`);
await queryRunner.query(`ALTER TABLE "log_users_login" ADD "item_id" uuid`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "log_users_login" DROP COLUMN "item_id"`,
);
await queryRunner.query(`ALTER TABLE "users_login" DROP COLUMN "item_id"`);
}
}

View File

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddColumnItemName1726141393404 implements MigrationInterface {
name = 'AddColumnItemName1726141393404';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" ADD "item_name" character varying`,
);
await queryRunner.query(
`ALTER TABLE "log_users_login" ADD "item_name" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "log_users_login" DROP COLUMN "item_name"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" DROP COLUMN "item_name"`,
);
}
}

View File

@ -9,14 +9,32 @@ import { CqrsModule } from '@nestjs/cqrs';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model'; import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service'; import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
import { AuthAdminQueueController } from './infrastructure/auth-admin-queue.controller';
import { AuthAdminQueueOrchestrator } from './domain/auth-admin-queue.orchestrator';
import { LoginAdminQueueManager } from './domain/managers/admin-queue/login-admin-queue.manager';
import { LogoutAdminQueueManager } from './domain/managers/admin-queue/logout-admin-queue.manager';
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT), TypeOrmModule.forFeature(
[UserModel, UserLoginModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule, CqrsModule,
], ],
controllers: [AuthController], controllers: [AuthController, AuthAdminQueueController],
providers: [LoginManager, LogoutManager, UserDataService, AuthOrchestrator], providers: [
LoginManager,
LogoutManager,
UserDataService,
AuthOrchestrator,
// ADMIN QUEUE
AuthAdminQueueOrchestrator,
LoginAdminQueueManager,
LogoutAdminQueueManager,
],
}) })
export class AuthModule {} export class AuthModule {}

View File

@ -0,0 +1,28 @@
import { Injectable } from '@nestjs/common';
import { LoginAdminQueueManager } from './managers/admin-queue/login-admin-queue.manager';
import { LogoutAdminQueueManager } from './managers/admin-queue/logout-admin-queue.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 AuthAdminQueueOrchestrator {
constructor(
private loginManager: LoginAdminQueueManager,
private logoutManager: LogoutAdminQueueManager,
private serviceData: UserDataService,
) {}
async login(data): Promise<any> {
this.loginManager.setData(data);
this.loginManager.setService(this.serviceData, TABLE_NAME.USER);
await this.loginManager.execute();
return this.loginManager.getResult();
}
async logout(id?: string): Promise<any> {
if (id) this.logoutManager.setData({ id });
this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
await this.logoutManager.execute();
return this.logoutManager.getResult();
}
}

View File

@ -0,0 +1,165 @@
import {
HttpStatus,
Inject,
Injectable,
Logger,
UnauthorizedException,
} from '@nestjs/common';
import { validatePassword } from 'src/core/helpers/password/bcrypt.helpers';
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
import { SessionService } from 'src/core/sessions';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { In } from 'typeorm';
import { UserRole } from 'src/modules/user-related/user/constants';
import { LogUserType } from 'src/core/helpers/constant';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
@Injectable()
export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
@Inject()
protected session: SessionService;
protected token;
protected userLogin;
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async process(): Promise<void> {
const itemLogin = await this.dataService.getLoginUserByItem(
this.data.item_id,
);
// get user active by username
this.userLogin = await this.dataService.getOneByOptions({
where: {
username: this.data.username,
status: STATUS.ACTIVE,
role: In([UserRole.QUEUE_ADMIN, UserRole.SUPERADMIN]),
},
relations: ['user_login'],
});
if (!this.userLogin) this.throwError();
// validasi password
const valid = await validatePassword(
this.data.password,
this.userLogin?.password,
);
if (!valid) this.throwError();
const userLoginItem = await this.dataService.getOneByOptions({
where: {
id: itemLogin?.user_id,
},
});
if (this.userLogin.user_login) {
throw new UnauthorizedException({
statusCode: HttpStatus.UNAUTHORIZED,
message: `Akun anda sudah login di perangkat lain.`,
error: 'Unauthorized',
});
} else if (itemLogin) {
throw new UnauthorizedException({
statusCode: HttpStatus.UNAUTHORIZED,
message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
error: 'Unauthorized',
});
}
// * Disini untuk isi token
const tokenData = {
id: this.userLogin.id,
name: this.userLogin.name,
username: this.userLogin.username,
role: this.userLogin.role,
user_privilege_id: this.userLogin.user_privilege_id,
item_id: this.data.item_id,
item_name: this.data.item_name,
};
Logger.debug('Sign Token Admin Queue', 'LoginAdminQueueManager');
this.token = this.session.createAccessToken(tokenData);
Logger.debug('refreshToken Admin Queue', 'LoginAdminQueueManager');
const refreshToken = this.session.createAccessToken(tokenData);
Logger.debug('Update Refresh Token Admin Queue', 'LoginAdminQueueManager');
// Update refresh token
await this.dataService.update(
this.queryRunner,
this.entityTarget,
{ id: this.userLogin.id },
{
refresh_token: refreshToken,
user_login: {
user_id: this.userLogin.id,
login_token: this.token,
login_date: new Date().getTime(),
item_id: this.data.item_id,
item_name: this.data.item_name,
},
},
);
await this.publishEvents();
Logger.debug('Process Login Admin Queue Done', 'LoginAdminQueueManager');
return;
}
async afterProcess(): Promise<void> {
return;
}
getResult() {
return {
id: this.userLogin.id,
name: this.userLogin.name,
username: this.userLogin.username,
role: this.userLogin.role,
token: this.token,
item_id: this.data.item_id,
item_name: this.data.item_name,
};
}
get entityTarget(): any {
return UserModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: LogUserLoginEvent,
data: {
type: LogUserType.login,
role: this.userLogin.role,
user_id: this.userLogin.id,
username: this.userLogin.username,
created_at: new Date().getTime(),
item_id: this.data.item_id,
item_name: this.data.item_name,
},
},
];
}
// !throw errornya akan sama, untuk security
throwError() {
throw new UnauthorizedException({
statusCode: HttpStatus.UNAUTHORIZED,
message: `Gagal! username atau password tidak sesuai`,
error: 'Unauthorized',
});
}
}

View File

@ -0,0 +1,65 @@
import { LogUserType } from 'src/core/helpers/constant';
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
export class LogoutAdminQueueManager extends BaseCustomManager<UserEntity> {
protected userLogin;
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async process(): Promise<void> {
const id = this.data?.id ?? this.user.id;
this.userLogin = await this.dataService.getOneByOptions({
where: { id },
});
await this.dataService.update(
this.queryRunner,
this.entityTarget,
{ id: this.userLogin.id },
{
refresh_token: null,
user_login: null,
},
);
await this.publishEvents();
return;
}
async afterProcess(): Promise<void> {
return;
}
getResult() {
return `Success Logout User`;
}
get entityTarget(): any {
return UserModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: LogUserLoginEvent,
data: {
type: LogUserType.logout,
role: this.userLogin.role,
user_id: this.userLogin.id,
username: this.userLogin.name,
created_at: new Date().getTime(),
},
},
];
}
}

View File

@ -12,7 +12,10 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
import { EventTopics } from 'src/core/strings/constants/interface.constants'; import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model'; import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity'; import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { UserLoginEvent } from '../entities/login.event'; import { Not } from 'typeorm';
import { UserRole } from 'src/modules/user-related/user/constants';
import { LogUserType } from 'src/core/helpers/constant';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
@Injectable() @Injectable()
export class LoginManager extends BaseCustomManager<UserEntity> { export class LoginManager extends BaseCustomManager<UserEntity> {
@ -36,6 +39,7 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
where: { where: {
username: this.data.username, username: this.data.username,
status: STATUS.ACTIVE, status: STATUS.ACTIVE,
role: Not(UserRole.QUEUE_ADMIN),
}, },
relations: [ relations: [
'user_privilege', 'user_privilege',
@ -77,6 +81,7 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
}, },
); );
await this.publishEvents();
Logger.debug('Process Login Done', 'LoginManager'); Logger.debug('Process Login Done', 'LoginManager');
return; return;
} }
@ -119,11 +124,13 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
get eventTopics(): EventTopics[] { get eventTopics(): EventTopics[] {
return [ return [
{ {
topic: UserLoginEvent, topic: LogUserLoginEvent,
data: { data: {
id: this.userLogin.id, type: LogUserType.login,
type: 'login', role: this.userLogin.role,
timestamp: new Date().getTime(), user_id: this.userLogin.id,
username: this.userLogin.username,
created_at: new Date().getTime(),
}, },
}, },
]; ];

View File

@ -2,7 +2,8 @@ import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base
import { EventTopics } from 'src/core/strings/constants/interface.constants'; import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model'; import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity'; import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { UserLogoutEvent } from '../entities/logout.event'; import { LogUserType } from 'src/core/helpers/constant';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
export class LogoutManager extends BaseCustomManager<UserEntity> { export class LogoutManager extends BaseCustomManager<UserEntity> {
async validateProcess(): Promise<void> { async validateProcess(): Promise<void> {
@ -23,6 +24,7 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
}, },
); );
await this.publishEvents();
return; return;
} }
@ -41,11 +43,13 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
get eventTopics(): EventTopics[] { get eventTopics(): EventTopics[] {
return [ return [
{ {
topic: UserLogoutEvent, topic: LogUserLoginEvent,
data: { data: {
id: this.user.id, type: LogUserType.logout,
type: 'logout', role: this.user.role,
timestamp: new Date().getTime(), user_id: this.user.id,
username: this.user.name,
created_at: new Date().getTime(),
}, },
}, },
]; ];

View File

@ -0,0 +1,29 @@
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
import { ExcludePrivilege, Public } from 'src/core/guards';
import { ApiBearerAuth } from '@nestjs/swagger';
import { LoginQueueDto } from './dto/login.dto';
import { AuthAdminQueueOrchestrator } from '../domain/auth-admin-queue.orchestrator';
@Controller('v1/auth/queue')
export class AuthAdminQueueController {
constructor(private orchestrator: AuthAdminQueueOrchestrator) {}
@Post()
@Public(true)
async login(@Body() body: LoginQueueDto) {
return await this.orchestrator.login(body);
}
@ApiBearerAuth('JWT')
@Public(false)
@ExcludePrivilege()
@Delete('logout')
async logoout() {
return await this.orchestrator.logout();
}
@Put(':id/logout')
async logoutQueueAdmin(@Param('id') dataId: string) {
return await this.orchestrator.logout(dataId);
}
}

View File

@ -1,5 +1,5 @@
import { Body, Controller, Delete, Post } from '@nestjs/common'; import { Body, Controller, Delete, Post } from '@nestjs/common';
import { Public } from 'src/core/guards'; import { ExcludePrivilege, Public } from 'src/core/guards';
import { AuthOrchestrator } from '../domain/auth.orchestrator'; import { AuthOrchestrator } from '../domain/auth.orchestrator';
import { ApiBearerAuth } from '@nestjs/swagger'; import { ApiBearerAuth } from '@nestjs/swagger';
import { LoginDto } from './dto/login.dto'; import { LoginDto } from './dto/login.dto';
@ -16,6 +16,7 @@ export class AuthController {
@ApiBearerAuth('JWT') @ApiBearerAuth('JWT')
@Public(false) @Public(false)
@ExcludePrivilege()
@Delete('logout') @Delete('logout')
async logoout() { async logoout() {
return await this.orchestrator.logout(); return await this.orchestrator.logout();

View File

@ -11,3 +11,21 @@ export class LoginDto implements LoginRequest {
@IsString() @IsString()
password: string; password: string;
} }
export class LoginQueueDto implements LoginRequest {
@ApiProperty({ name: 'username', required: true, default: 'superadmin' })
@IsString()
username: string;
@ApiProperty({ name: 'password', required: true, default: 'Eigen123!' })
@IsString()
password: string;
@ApiProperty({ name: 'item_id', required: true, default: 'string' })
@IsString()
item_id: string;
@ApiProperty({ name: 'item_name', required: true, default: 'string' })
@IsString()
item_name: string;
}

View File

@ -51,6 +51,7 @@ import {
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service'; import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model'; import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
import { TransactionDemographyModel } from 'src/modules/transaction/transaction/data/models/transaction-demography.model'; import { TransactionDemographyModel } from 'src/modules/transaction/transaction/data/models/transaction-demography.model';
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
@Module({ @Module({
imports: [ imports: [
@ -61,6 +62,7 @@ import { TransactionDemographyModel } from 'src/modules/transaction/transaction/
ItemRateModel, ItemRateModel,
SeasonPeriodModel, SeasonPeriodModel,
UserModel, UserModel,
UserLoginModel,
TransactionModel, TransactionModel,
TransactionTaxModel, TransactionTaxModel,
TransactionItemModel, TransactionItemModel,

View File

@ -0,0 +1,34 @@
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserEntity } from '../../../../user-related/user/domain/entities/user.entity';
import { Column, Entity } from 'typeorm';
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { LogUserLoginEntity } from '../../domain/entities/log-user-login.entity';
import { UserRole } from '../../../../user-related/user/constants';
import { LogUserType } from 'src/core/helpers/constant';
@Entity(TABLE_NAME.LOG_USER_LOGIN)
export class LogUserLoginModel
extends BaseCoreModel<UserEntity>
implements LogUserLoginEntity
{
@Column({ type: 'enum', enum: LogUserType, nullable: true })
type: LogUserType;
@Column({ type: 'enum', enum: UserRole, nullable: true })
role: UserRole;
@Column({ type: 'uuid', nullable: true })
user_id: string;
@Column({ type: 'uuid', nullable: true })
item_id: string;
@Column({ type: 'varchar', nullable: true })
item_name: string;
@Column({ type: 'varchar', nullable: true })
username: string;
@Column({ type: 'bigint', nullable: true })
created_at: number;
}

View File

@ -0,0 +1,21 @@
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { LogUserLoginEntity } from '../../domain/entities/log-user-login.entity';
import { LogUserLoginModel } from '../models/log-user-login.model';
@Injectable()
export class LogUserLoginService extends BaseDataService<LogUserLoginEntity> {
constructor(
@InjectRepository(LogUserLoginModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<LogUserLoginModel>,
) {
super(repo);
}
async saveData(data) {
this.repo.save(data);
}
}

View File

@ -0,0 +1,13 @@
import { LogUserType } from 'src/core/helpers/constant';
import { UserRole } from '../../../../user-related/user/constants';
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
export interface LogUserLoginEntity extends BaseCoreEntity {
type: LogUserType;
role: UserRole;
user_id: string;
item_id: string;
item_name: string;
username: string;
created_at: number;
}

View File

@ -0,0 +1,5 @@
import { IEvent } from 'src/core/strings/constants/interface.constants';
export class LogUserLoginEvent {
constructor(public readonly data: IEvent) {}
}

View File

@ -0,0 +1,14 @@
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { LogUserLoginEvent } from '../entities/log-user-login.event';
import { LogUserLoginService } from '../../data/services/log-user-login.service';
@EventsHandler(LogUserLoginEvent)
export class LogUserLoginHandler implements IEventHandler<LogUserLoginEvent> {
constructor(private service: LogUserLoginService) {}
async handle(event: LogUserLoginEvent) {
const data = event.data.data;
await this.service.saveData(data);
}
}

View File

@ -12,12 +12,15 @@ import { LogService } from './data/services/log.service';
import { PosLogModel } from './data/models/pos-log.model'; import { PosLogModel } from './data/models/pos-log.model';
import { PosLogService } from './data/services/pos-log.service'; import { PosLogService } from './data/services/pos-log.service';
import { RecordPosLogHandler } from './domain/handlers/pos-log.handler'; import { RecordPosLogHandler } from './domain/handlers/pos-log.handler';
import { LogUserLoginModel } from './data/models/log-user-login.model';
import { LogUserLoginService } from './data/services/log-user-login.service';
import { LogUserLoginHandler } from './domain/handlers/log-user-login.handler';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature( TypeOrmModule.forFeature(
[LogModel, ErrorLogModel, PosLogModel], [LogModel, ErrorLogModel, PosLogModel, LogUserLoginModel],
CONNECTION_NAME.DEFAULT, CONNECTION_NAME.DEFAULT,
), ),
CqrsModule, CqrsModule,
@ -27,10 +30,12 @@ import { RecordPosLogHandler } from './domain/handlers/pos-log.handler';
RecordLogHandler, RecordLogHandler,
RecordPosLogHandler, RecordPosLogHandler,
RecordErrorLogHandler, RecordErrorLogHandler,
LogUserLoginHandler,
LogService, LogService,
PosLogService, PosLogService,
ErrorLogService, ErrorLogService,
LogUserLoginService,
], ],
}) })
export class LogModule {} export class LogModule {}

View File

@ -10,11 +10,13 @@ import { ItemRateReadService } from 'src/modules/item-related/item-rate/data/ser
import { FilterItemRateDto } from 'src/modules/item-related/item-rate/infrastructure/dto/filter-item-rate.dto'; import { FilterItemRateDto } from 'src/modules/item-related/item-rate/infrastructure/dto/filter-item-rate.dto';
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity'; import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
import { IndexItemRatesManager } from './managers/index-item-rates.manager'; import { IndexItemRatesManager } from './managers/index-item-rates.manager';
import { IndexItemQueueManager } from './managers/index-queue-item.manager';
@Injectable() @Injectable()
export class ItemReadOrchestrator extends BaseReadOrchestrator<ItemEntity> { export class ItemReadOrchestrator extends BaseReadOrchestrator<ItemEntity> {
constructor( constructor(
private indexManager: IndexItemManager, private indexManager: IndexItemManager,
private indexQueueManager: IndexItemQueueManager,
private detailManager: DetailItemManager, private detailManager: DetailItemManager,
private indexRateManager: IndexItemRatesManager, private indexRateManager: IndexItemRatesManager,
private serviceData: ItemReadService, private serviceData: ItemReadService,
@ -30,6 +32,13 @@ export class ItemReadOrchestrator extends BaseReadOrchestrator<ItemEntity> {
return this.indexManager.getResult(); return this.indexManager.getResult();
} }
async indexQueue(params): Promise<PaginationResponse<ItemEntity>> {
this.indexQueueManager.setFilterParam(params);
this.indexQueueManager.setService(this.serviceData, TABLE_NAME.ITEM);
await this.indexQueueManager.execute();
return this.indexQueueManager.getResult();
}
async detail(dataId: string): Promise<ItemEntity> { async detail(dataId: string): Promise<ItemEntity> {
this.detailManager.setData(dataId); this.detailManager.setData(dataId);
this.detailManager.setService(this.serviceData, TABLE_NAME.ITEM); this.detailManager.setService(this.serviceData, TABLE_NAME.ITEM);

View File

@ -0,0 +1,68 @@
import { Injectable } from '@nestjs/common';
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
import { ItemEntity } from '../../entities/item.entity';
import { SelectQueryBuilder } from 'typeorm';
import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable()
export class IndexItemQueueManager extends BaseIndexManager<ItemEntity> {
async prepareData(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async afterProcess(): Promise<void> {
return;
}
get relations(): RelationParam {
return {
// relation only join (for query purpose)
joinRelations: [],
// relation join and select (relasi yang ingin ditampilkan),
selectRelations: [],
// relation yang hanya ingin dihitung (akan return number)
countRelations: [],
};
}
get selects(): string[] {
return [
`${this.tableName}.id`,
`${this.tableName}.created_at`,
`${this.tableName}.name`,
];
}
get specificFilter(): Param[] {
return [
{
cols: `${this.tableName}.name`,
data: this.filterParam.names,
},
];
}
setQueryFilter(
queryBuilder: SelectQueryBuilder<ItemEntity>,
): SelectQueryBuilder<ItemEntity> {
queryBuilder.andWhere(`${this.tableName}.status = :status`, {
status: STATUS.ACTIVE,
});
queryBuilder.andWhere(`${this.tableName}.use_queue = :queue`, {
queue: true,
});
return queryBuilder;
}
}

View File

@ -0,0 +1,6 @@
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
export class FilterItemQueueDto
extends BaseFilterDto
implements BaseFilterEntity {}

View File

@ -6,7 +6,7 @@ import { ItemEntity } from '../domain/entities/item.entity';
import { ItemReadOrchestrator } from '../domain/usecases/item-read.orchestrator'; import { ItemReadOrchestrator } from '../domain/usecases/item-read.orchestrator';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants'; import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { Public } from 'src/core/guards'; import { ExcludePrivilege, Public } from 'src/core/guards';
import { ItemRateEntity } from '../../item-rate/domain/entities/item-rate.entity'; import { ItemRateEntity } from '../../item-rate/domain/entities/item-rate.entity';
import { FilterItemRateDto } from '../../item-rate/infrastructure/dto/filter-item-rate.dto'; import { FilterItemRateDto } from '../../item-rate/infrastructure/dto/filter-item-rate.dto';
@ -40,3 +40,19 @@ export class ItemReadController {
return await this.orchestrator.indexRate(params); return await this.orchestrator.indexRate(params);
} }
} }
@ApiTags(`Item Queue - Read`)
@Controller(`v1/item-queue`)
@Public(true)
export class ItemReadQueueController {
constructor(private orchestrator: ItemReadOrchestrator) {}
@Get()
@Pagination()
@ExcludePrivilege()
async indexQueue(
@Query() params: FilterItemDto,
): Promise<PaginationResponse<ItemEntity>> {
return await this.orchestrator.indexQueue(params);
}
}

View File

@ -4,7 +4,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { ItemDataService } from './data/services/item-data.service'; import { ItemDataService } from './data/services/item-data.service';
import { ItemReadService } from './data/services/item-read.service'; import { ItemReadService } from './data/services/item-read.service';
import { ItemReadController } from './infrastructure/item-read.controller'; import {
ItemReadController,
ItemReadQueueController,
} from './infrastructure/item-read.controller';
import { ItemReadOrchestrator } from './domain/usecases/item-read.orchestrator'; import { ItemReadOrchestrator } from './domain/usecases/item-read.orchestrator';
import { ItemDataController } from './infrastructure/item-data.controller'; import { ItemDataController } from './infrastructure/item-data.controller';
import { ItemDataOrchestrator } from './domain/usecases/item-data.orchestrator'; import { ItemDataOrchestrator } from './domain/usecases/item-data.orchestrator';
@ -26,6 +29,7 @@ import { ItemRateModel } from '../item-rate/data/models/item-rate.model';
import { ItemRateReadService } from '../item-rate/data/services/item-rate-read.service'; import { ItemRateReadService } from '../item-rate/data/services/item-rate-read.service';
import { IndexItemRatesManager } from './domain/usecases/managers/index-item-rates.manager'; import { IndexItemRatesManager } from './domain/usecases/managers/index-item-rates.manager';
import { UpdateItemRatePriceManager } from './domain/usecases/managers/update-item-rate-price.manager'; import { UpdateItemRatePriceManager } from './domain/usecases/managers/update-item-rate-price.manager';
import { IndexItemQueueManager } from './domain/usecases/managers/index-queue-item.manager';
@Global() @Global()
@Module({ @Module({
@ -37,9 +41,14 @@ import { UpdateItemRatePriceManager } from './domain/usecases/managers/update-it
), ),
CqrsModule, CqrsModule,
], ],
controllers: [ItemDataController, ItemReadController], controllers: [
ItemDataController,
ItemReadController,
ItemReadQueueController,
],
providers: [ providers: [
IndexItemManager, IndexItemManager,
IndexItemQueueManager,
IndexItemRatesManager, IndexItemRatesManager,
DetailItemManager, DetailItemManager,
CreateItemManager, CreateItemManager,
@ -63,6 +72,7 @@ import { UpdateItemRatePriceManager } from './domain/usecases/managers/update-it
], ],
exports: [ exports: [
IndexItemManager, IndexItemManager,
IndexItemQueueManager,
IndexItemRatesManager, IndexItemRatesManager,
DetailItemManager, DetailItemManager,
CreateItemManager, CreateItemManager,

View File

@ -128,23 +128,37 @@ export default <ReportConfigEntity>{
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{ {
column: 'tr_item__payment_total_dpp', column: 'tr_item__total_price',
query: 'tr_item.payment_total_dpp', query: 'tr_item.total_price',
label: 'Total Penjualan',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{
column: 'tr_item_bundling__payment_total_dpp',
query: 'tr_item_bundling.payment_total_dpp',
label: 'DPP', label: 'DPP',
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{ {
column: 'tr_item__payment_total_tax', column: 'tr_item_bundling__payment_total_tax',
query: 'tr_item.payment_total_tax', query: 'tr_item_bundling.payment_total_tax',
label: 'Total Pajak', label: 'Total Pajak',
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{ {
column: 'tr_item__total_price', column: 'tr_item_bundling__total_profit_share',
query: 'tr_item.total_price', query: 'tr_item_bundling.total_profit_share',
label: 'Total Penjualan', label: 'Profit Share',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{
column: 'tr_item_bundling__total_share_tenant',
query: 'tr_item_bundling.total_share_tenant',
label: 'Tenant Share',
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },

View File

@ -112,6 +112,13 @@ export default <ReportConfigEntity>{
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{
column: 'tr_item__total_price',
query: 'tr_item.total_price',
label: 'Total Penjualan',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{ {
column: 'tr_item__payment_total_dpp', column: 'tr_item__payment_total_dpp',
query: 'tr_item.payment_total_dpp', query: 'tr_item.payment_total_dpp',
@ -127,9 +134,16 @@ export default <ReportConfigEntity>{
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{ {
column: 'tr_item__total_price', column: 'tr_item__total_profit_share',
query: 'tr_item.total_price', query: 'tr_item.total_profit_share',
label: 'Total Penjualan', label: 'Profit Share',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{
column: 'tr_item__total_share_tenant',
query: 'tr_item.total_share_tenant',
label: 'Tenant Share',
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },

View File

@ -102,16 +102,9 @@ export default <ReportConfigEntity>{
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{ {
column: 'main__payment_total_dpp', column: 'main__payment_sub_total',
query: 'main.payment_total_dpp', query: 'main.payment_sub_total',
label: 'DPP', label: 'Subtotal',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{
column: 'main__payment_total_tax',
query: 'main.payment_total_tax',
label: 'Total Pajak',
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
@ -136,6 +129,27 @@ export default <ReportConfigEntity>{
type: DATA_TYPE.MEASURE, type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY, format: DATA_FORMAT.CURRENCY,
}, },
{
column: 'main__payment_total_dpp',
query: 'main.payment_total_dpp',
label: 'DPP',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{
column: 'main__payment_total_tax',
query: 'main.payment_total_tax',
label: 'Total Pajak',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{
column: 'main__payment_total_share',
query: 'main.payment_total_share',
label: 'Profit Share',
type: DATA_TYPE.MEASURE,
format: DATA_FORMAT.CURRENCY,
},
{ {
column: 'refund__refund_date', column: 'refund__refund_date',
query: 'refund.refund_date', query: 'refund.refund_date',

View File

@ -25,11 +25,15 @@ import { UserDataService } from '../user/data/services/user-data.service';
import { UserReadService } from '../user/data/services/user-read.service'; import { UserReadService } from '../user/data/services/user-read.service';
import { TenantItemReadController } from './infrastructure/tenant-item-read.controller'; import { TenantItemReadController } from './infrastructure/tenant-item-read.controller';
import { TenantItemDataController } from './infrastructure/tenant-item-data.controller'; import { TenantItemDataController } from './infrastructure/tenant-item-data.controller';
import { UserLoginModel } from '../user/data/models/user-login.model';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT), TypeOrmModule.forFeature(
[UserModel, UserLoginModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule, CqrsModule,
], ],
controllers: [ controllers: [

View File

@ -0,0 +1,36 @@
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserEntity } from '../../domain/entities/user.entity';
import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
import { UserLoginEntity } from '../../domain/entities/user-login.entity';
import { UserModel } from './user.model';
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
@Entity(TABLE_NAME.USER_LOGIN)
export class UserLoginModel
extends BaseCoreModel<UserEntity>
implements UserLoginEntity
{
@Column({ type: 'bigint', nullable: false })
login_date: number;
@Column({ type: 'varchar', name: 'login_token', nullable: true })
login_token: string;
@Column('varchar', { name: 'user_id', nullable: true })
user_id: string;
@Column({ type: 'uuid', nullable: true })
item_id: string;
@Column({ type: 'varchar', nullable: true })
item_name: string;
@OneToOne(() => UserModel, (model) => model.user_login, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
nullable: false,
orphanedRowAction: 'delete',
})
@JoinColumn({ name: 'user_id' })
user: UserModel;
}

View File

@ -1,10 +1,18 @@
import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserEntity } from '../../domain/entities/user.entity'; import { UserEntity } from '../../domain/entities/user.entity';
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm'; import {
Column,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
OneToOne,
} from 'typeorm';
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model'; 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 { UserPrivilegeModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege.model';
import { UserRole } from '../../constants'; import { UserRole } from '../../constants';
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'; import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
import { UserLoginModel } from './user-login.model';
@Entity(TABLE_NAME.USER) @Entity(TABLE_NAME.USER)
export class UserModel export class UserModel
@ -48,4 +56,10 @@ export class UserModel
onUpdate: 'CASCADE', onUpdate: 'CASCADE',
}) })
items: ItemModel[]; items: ItemModel[];
// relasi ke user login for admin queue
@OneToOne(() => UserLoginModel, (model) => model.user, {
cascade: true,
})
user_login: UserLoginModel;
} }

View File

@ -4,14 +4,24 @@ import { UserEntity } from '../../domain/entities/user.entity';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { UserModel } from '../models/user.model'; import { UserModel } from '../models/user.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm'; import { IsNull, Not, Repository } from 'typeorm';
import { UserLoginModel } from '../models/user-login.model';
@Injectable() @Injectable()
export class UserDataService extends BaseDataService<UserEntity> { export class UserDataService extends BaseDataService<UserEntity> {
constructor( constructor(
@InjectRepository(UserModel, CONNECTION_NAME.DEFAULT) @InjectRepository(UserModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<UserModel>, private repo: Repository<UserModel>,
@InjectRepository(UserLoginModel, CONNECTION_NAME.DEFAULT)
private repoLoginUser: Repository<UserLoginModel>,
) { ) {
super(repo); super(repo);
} }
async getLoginUserByItem(itemId: string) {
return this.repoLoginUser.findOne({
where: { item_id: itemId, user_id: Not(IsNull()) },
});
}
} }

View File

@ -0,0 +1,8 @@
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
export interface UserLoginEntity extends BaseCoreEntity {
login_date: number;
login_token: string;
item_id: string;
item_name: string;
}

View File

@ -15,12 +15,7 @@ import { SALT_OR_ROUNDS } from 'src/core/strings/constants/base.constants';
@Injectable() @Injectable()
export class CreateUserManager extends BaseCreateManager<UserEntity> { export class CreateUserManager extends BaseCreateManager<UserEntity> {
async beforeProcess(): Promise<void> { 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, { Object.assign(this.data, {
role: role,
password: await hashPassword(this.data.password, SALT_OR_ROUNDS), password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
}); });

View File

@ -36,6 +36,7 @@ export class DetailUserManager extends BaseDetailManager<UserEntity> {
`${this.tableName}.status`, `${this.tableName}.status`,
`${this.tableName}.name`, `${this.tableName}.name`,
`${this.tableName}.username`, `${this.tableName}.username`,
`${this.tableName}.role`,
`${this.tableName}.created_at`, `${this.tableName}.created_at`,
`${this.tableName}.creator_name`, `${this.tableName}.creator_name`,
`${this.tableName}.updated_at`, `${this.tableName}.updated_at`,

View File

@ -28,7 +28,7 @@ export class IndexUserManager extends BaseIndexManager<UserEntity> {
joinRelations: [], joinRelations: [],
// relation join and select (relasi yang ingin ditampilkan), // relation join and select (relasi yang ingin ditampilkan),
selectRelations: ['user_privilege'], selectRelations: ['user_privilege', 'user_login'],
// relation yang hanya ingin dihitung (akan return number) // relation yang hanya ingin dihitung (akan return number)
countRelations: [], countRelations: [],
@ -41,6 +41,7 @@ export class IndexUserManager extends BaseIndexManager<UserEntity> {
`${this.tableName}.status`, `${this.tableName}.status`,
`${this.tableName}.name`, `${this.tableName}.name`,
`${this.tableName}.username`, `${this.tableName}.username`,
`${this.tableName}.role`,
`${this.tableName}.created_at`, `${this.tableName}.created_at`,
`${this.tableName}.creator_name`, `${this.tableName}.creator_name`,
`${this.tableName}.updated_at`, `${this.tableName}.updated_at`,
@ -48,6 +49,11 @@ export class IndexUserManager extends BaseIndexManager<UserEntity> {
'user_privilege.id', 'user_privilege.id',
'user_privilege.name', 'user_privilege.name',
'user_login.id',
'user_login.login_date',
'user_login.item_id',
'user_login.item_name',
]; ];
} }

View File

@ -8,7 +8,6 @@ import {
columnUniques, columnUniques,
validateRelations, validateRelations,
} from 'src/core/strings/constants/interface.constants'; } from 'src/core/strings/constants/interface.constants';
import { UserRole } from '../../../constants';
@Injectable() @Injectable()
export class UpdateUserManager extends BaseUpdateManager<UserEntity> { export class UpdateUserManager extends BaseUpdateManager<UserEntity> {
@ -17,14 +16,6 @@ export class UpdateUserManager extends BaseUpdateManager<UserEntity> {
} }
async beforeProcess(): Promise<void> { 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; return;
} }

View File

@ -31,6 +31,7 @@ export class UserDataOrchestrator extends BaseDataTransactionOrchestrator<UserEn
private batchConfirmManager: BatchConfirmUserManager, private batchConfirmManager: BatchConfirmUserManager,
private batchInactiveManager: BatchInactiveUserManager, private batchInactiveManager: BatchInactiveUserManager,
private updatePasswordManager: UpdatePasswordUserManager, private updatePasswordManager: UpdatePasswordUserManager,
private serviceData: UserDataService, private serviceData: UserDataService,
) { ) {
super(); super();

View File

@ -15,14 +15,9 @@ export class UpdateUserDto extends BaseStatusDto implements UserEntity {
@IsString() @IsString()
username: string; username: string;
@ApiProperty({ @ApiProperty({ name: 'role', required: true, example: UserRole.STAFF })
name: 'is_super_admin', @IsString()
type: Boolean, role: UserRole;
required: true,
example: false,
})
@IsBoolean()
is_super_admin: boolean;
@ApiProperty({ @ApiProperty({
name: 'user_privilege', name: 'user_privilege',
@ -45,9 +40,6 @@ export class UpdateUserDto extends BaseStatusDto implements UserEntity {
@Exclude() @Exclude()
password: string; password: string;
@Exclude()
role: UserRole;
@Exclude() @Exclude()
refresh_token: string; refresh_token: string;
} }

View File

@ -31,14 +31,9 @@ export class UserDto extends BaseStatusDto implements UserEntity {
@ValidateIf((body) => body.user_privilege) @ValidateIf((body) => body.user_privilege)
user_privilege: UserPrivilegeModel; user_privilege: UserPrivilegeModel;
@ApiProperty({ @ApiProperty({ name: 'role', required: true, example: UserRole.STAFF })
name: 'is_super_admin', @IsString()
type: Boolean, role: UserRole;
required: true,
example: false,
})
@IsBoolean()
is_super_admin: boolean;
@Exclude() @Exclude()
share_margin: number; share_margin: number;
@ -46,9 +41,6 @@ export class UserDto extends BaseStatusDto implements UserEntity {
@Exclude() @Exclude()
email: string; email: string;
@Exclude()
role: UserRole;
@Exclude() @Exclude()
refresh_token: string; refresh_token: string;
} }

View File

@ -23,11 +23,15 @@ import { BatchConfirmUserManager } from './domain/usecases/managers/batch-confir
import { BatchInactiveUserManager } from './domain/usecases/managers/batch-inactive-user.manager'; import { BatchInactiveUserManager } from './domain/usecases/managers/batch-inactive-user.manager';
import { UserModel } from './data/models/user.model'; import { UserModel } from './data/models/user.model';
import { UpdatePasswordUserManager } from './domain/usecases/managers/update-password-user.manager'; import { UpdatePasswordUserManager } from './domain/usecases/managers/update-password-user.manager';
import { UserLoginModel } from './data/models/user-login.model';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT), TypeOrmModule.forFeature(
[UserModel, UserLoginModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule, CqrsModule,
], ],
controllers: [UserDataController, UserReadController], controllers: [UserDataController, UserReadController],