fix(SPG-663) Pos Privileges - pemesanan seharusnya tidak ada create
parent
1590080468
commit
b7557a5f19
|
@ -179,6 +179,6 @@ export const PrivilegePOSConstant = [
|
||||||
menu: 'POS_DISCOUNT_CODE',
|
menu: 'POS_DISCOUNT_CODE',
|
||||||
menu_label: 'Print Receipt',
|
menu_label: 'Print Receipt',
|
||||||
actions: [PrivilegeAction.CREATE],
|
actions: [PrivilegeAction.CREATE],
|
||||||
index: 18,
|
index: 19,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -103,7 +103,7 @@ export class UserPrivilegeUpdateHandler
|
||||||
const users = await this.userService
|
const users = await this.userService
|
||||||
.getManyByOptions({
|
.getManyByOptions({
|
||||||
where: {
|
where: {
|
||||||
user_privilege_id: data.user_privilege_id,
|
user_privilege_id: data.user_privilege_id ?? data.id,
|
||||||
status: STATUS.ACTIVE,
|
status: STATUS.ACTIVE,
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
|
@ -113,7 +113,6 @@ export class UserPrivilegeUpdateHandler
|
||||||
})
|
})
|
||||||
.then((items) => {
|
.then((items) => {
|
||||||
return items?.map((item) => {
|
return items?.map((item) => {
|
||||||
console.log(item, 'dsa');
|
|
||||||
const user_privilege_configurations = item[
|
const user_privilege_configurations = item[
|
||||||
'user_privilege'
|
'user_privilege'
|
||||||
]?.user_privilege_configurations?.filter(
|
]?.user_privilege_configurations?.filter(
|
||||||
|
|
|
@ -1,66 +1,108 @@
|
||||||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
import { EventBus, EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
import { UserPrivilegeConfigUpdatedEvent } from '../../../entities/event/user-privilege-configuration-updated.event';
|
import { UserPrivilegeConfigUpdatedEvent } from '../../../entities/event/user-privilege-configuration-updated.event';
|
||||||
import { UserPrivilegeConfigurationService } from 'src/modules/user-related/user-privilege/data/service/user-privilege-configuration.service';
|
|
||||||
import { UserPrivilegeConfigurationHelper } from '../helpers/generate-user-privilege-configuration.helper';
|
import { UserPrivilegeConfigurationHelper } from '../helpers/generate-user-privilege-configuration.helper';
|
||||||
|
import { UserPrivilegeDataService } from 'src/modules/user-related/user-privilege/data/service/user-privilege-data.service';
|
||||||
|
import { PrivilegeAction } from 'src/core/strings/constants/privilege.constants';
|
||||||
import { UserPrivilegeConfigurationModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege-configuration.model';
|
import { UserPrivilegeConfigurationModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege-configuration.model';
|
||||||
|
import { UserPrivilegeUpdatedEvent } from '../../../entities/event/user-privilege-updated.event';
|
||||||
|
import { OPERATION } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
@EventsHandler(UserPrivilegeConfigUpdatedEvent)
|
@EventsHandler(UserPrivilegeConfigUpdatedEvent)
|
||||||
export class UserPrivilegeConfigUpdateHandler
|
export class UserPrivilegeConfigUpdateHandler
|
||||||
implements IEventHandler<UserPrivilegeConfigUpdatedEvent>
|
implements IEventHandler<UserPrivilegeConfigUpdatedEvent>
|
||||||
{
|
{
|
||||||
constructor(private dataService: UserPrivilegeConfigurationService) {}
|
constructor(
|
||||||
|
private dataService: UserPrivilegeDataService,
|
||||||
|
private eventBus: EventBus,
|
||||||
|
) {}
|
||||||
|
|
||||||
async handle(event: UserPrivilegeConfigUpdatedEvent) {
|
async handle(event: UserPrivilegeConfigUpdatedEvent) {
|
||||||
const data = event.data.data;
|
const data = event.data.data;
|
||||||
console.log(data.user_privilege_id);
|
const configuration = await this.dataService.getOneByOptions({
|
||||||
const configurations = await this.dataService.getManyByOptions({
|
|
||||||
where: {
|
where: {
|
||||||
user_privilege_id: data.user_privilege_id,
|
id: data.user_privilege_id,
|
||||||
},
|
},
|
||||||
|
relations: ['user_privilege_configurations'],
|
||||||
});
|
});
|
||||||
|
let configurationData = configuration?.[
|
||||||
|
'user_privilege_configurations'
|
||||||
|
]?.sort((a, b) => a.index - b.index);
|
||||||
const configs = UserPrivilegeConfigurationHelper.createConfigurations();
|
const configs = UserPrivilegeConfigurationHelper.createConfigurations();
|
||||||
|
|
||||||
const createdConfig = configs
|
configs
|
||||||
.filter(
|
.filter(
|
||||||
(base) =>
|
(base) =>
|
||||||
!configurations.some((data) => {
|
!configurationData.some((data) => {
|
||||||
return base.menu_label == data.menu_label;
|
return base.menu_label == data.menu_label;
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
|
Object.assign(item, {
|
||||||
|
user_privilege_id: data.user_privilege_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
configurationData.push(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
configurationData = configurationData
|
||||||
|
?.filter((item) =>
|
||||||
|
configs.some((data) => {
|
||||||
|
return item.menu_label == data.menu_label;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
?.map((item) => {
|
||||||
|
const exist = configs.find(
|
||||||
|
(config) => config.menu_label == item.menu_label,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
user_privilege_id: data.user_privilege_id,
|
view: exist.actions.includes(PrivilegeAction.VIEW)
|
||||||
|
? item.view ?? false
|
||||||
|
: null,
|
||||||
|
cancel: exist.actions.includes(PrivilegeAction.CANCEL)
|
||||||
|
? item.cancel ?? false
|
||||||
|
: null,
|
||||||
|
confirm: exist.actions.includes(PrivilegeAction.CONFIRM)
|
||||||
|
? item.confirm ?? false
|
||||||
|
: null,
|
||||||
|
create: exist.actions.includes(PrivilegeAction.CREATE)
|
||||||
|
? item.create ?? false
|
||||||
|
: null,
|
||||||
|
delete: exist.actions.includes(PrivilegeAction.DELETE)
|
||||||
|
? item.delete ?? false
|
||||||
|
: null,
|
||||||
|
edit: exist.actions.includes(PrivilegeAction.EDIT)
|
||||||
|
? item.edit ?? false
|
||||||
|
: null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const deletedConfig = configurations
|
Object.assign(configuration, {
|
||||||
.filter(
|
user_privilege_configurations: configurationData,
|
||||||
(base) =>
|
});
|
||||||
!configs.some((data) => {
|
|
||||||
return base.menu_label == data.menu_label;
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
?.map((item) => item.id);
|
|
||||||
|
|
||||||
const queryRunner = this.dataService
|
const queryRunner = this.dataService
|
||||||
.getRepository()
|
.getRepository()
|
||||||
.manager.connection.createQueryRunner();
|
.manager.connection.createQueryRunner();
|
||||||
|
|
||||||
if (createdConfig.length) {
|
await this.dataService.update(
|
||||||
await this.dataService.createBatch(
|
queryRunner,
|
||||||
queryRunner,
|
UserPrivilegeConfigurationModel,
|
||||||
UserPrivilegeConfigurationModel,
|
{ id: data.user_privilege_id },
|
||||||
createdConfig,
|
configuration,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (deletedConfig.length) {
|
this.eventBus.publishAll([
|
||||||
await this.dataService.deleteByIds(
|
new UserPrivilegeUpdatedEvent({
|
||||||
queryRunner,
|
id: configuration.id,
|
||||||
UserPrivilegeConfigurationModel,
|
old: null,
|
||||||
deletedConfig,
|
data: configuration,
|
||||||
);
|
user: event.data.user,
|
||||||
}
|
description: '',
|
||||||
|
module: TABLE_NAME.USER_PRIVILEGE_CONFIGURATION,
|
||||||
|
op: OPERATION.UPDATE,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import {
|
||||||
RelationParam,
|
RelationParam,
|
||||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { UserPrivilegeConfigurationHelper } from '../helpers/generate-user-privilege-configuration.helper';
|
||||||
|
import { PrivilegeAction } from 'src/core/strings/constants/privilege.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexUserPrivilegeConfigurationManager extends BaseIndexManager<UserPrivilegeConfigurationEntity> {
|
export class IndexUserPrivilegeConfigurationManager extends BaseIndexManager<UserPrivilegeConfigurationEntity> {
|
||||||
|
@ -24,6 +26,62 @@ export class IndexUserPrivilegeConfigurationManager extends BaseIndexManager<Use
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
async afterProcess(): Promise<void> {
|
||||||
|
const configs = UserPrivilegeConfigurationHelper.createConfigurations()
|
||||||
|
.filter((item) => this.filterParam.modules.includes(item.module))
|
||||||
|
?.map((item) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
configs
|
||||||
|
.filter(
|
||||||
|
(base) =>
|
||||||
|
!this.result.data.some((data) => {
|
||||||
|
return base.menu_label == data.menu_label;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.map((item) => {
|
||||||
|
Object.assign(item, {
|
||||||
|
user_privilege_id: this.filterParam.user_privilege_ids?.[0],
|
||||||
|
});
|
||||||
|
|
||||||
|
this.result.data.push(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.result.data = this.result.data
|
||||||
|
?.filter((item) =>
|
||||||
|
configs.some((data) => {
|
||||||
|
return item.menu_label == data.menu_label;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
?.map((item) => {
|
||||||
|
const exist = configs.find(
|
||||||
|
(config) => config.menu_label == item.menu_label,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
view: exist.actions.includes(PrivilegeAction.VIEW)
|
||||||
|
? item.view ?? false
|
||||||
|
: null,
|
||||||
|
cancel: exist.actions.includes(PrivilegeAction.CANCEL)
|
||||||
|
? item.cancel ?? false
|
||||||
|
: null,
|
||||||
|
confirm: exist.actions.includes(PrivilegeAction.CONFIRM)
|
||||||
|
? item.confirm ?? false
|
||||||
|
: null,
|
||||||
|
create: exist.actions.includes(PrivilegeAction.CREATE)
|
||||||
|
? item.create ?? false
|
||||||
|
: null,
|
||||||
|
delete: exist.actions.includes(PrivilegeAction.DELETE)
|
||||||
|
? item.delete ?? false
|
||||||
|
: null,
|
||||||
|
edit: exist.actions.includes(PrivilegeAction.EDIT)
|
||||||
|
? item.edit ?? false
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue