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_label: 'Print Receipt',
|
||||
actions: [PrivilegeAction.CREATE],
|
||||
index: 18,
|
||||
index: 19,
|
||||
},
|
||||
];
|
||||
|
|
|
@ -103,7 +103,7 @@ export class UserPrivilegeUpdateHandler
|
|||
const users = await this.userService
|
||||
.getManyByOptions({
|
||||
where: {
|
||||
user_privilege_id: data.user_privilege_id,
|
||||
user_privilege_id: data.user_privilege_id ?? data.id,
|
||||
status: STATUS.ACTIVE,
|
||||
},
|
||||
relations: [
|
||||
|
@ -113,7 +113,6 @@ export class UserPrivilegeUpdateHandler
|
|||
})
|
||||
.then((items) => {
|
||||
return items?.map((item) => {
|
||||
console.log(item, 'dsa');
|
||||
const user_privilege_configurations = item[
|
||||
'user_privilege'
|
||||
]?.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 { UserPrivilegeConfigurationService } from 'src/modules/user-related/user-privilege/data/service/user-privilege-configuration.service';
|
||||
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 { 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)
|
||||
export class UserPrivilegeConfigUpdateHandler
|
||||
implements IEventHandler<UserPrivilegeConfigUpdatedEvent>
|
||||
{
|
||||
constructor(private dataService: UserPrivilegeConfigurationService) {}
|
||||
constructor(
|
||||
private dataService: UserPrivilegeDataService,
|
||||
private eventBus: EventBus,
|
||||
) {}
|
||||
|
||||
async handle(event: UserPrivilegeConfigUpdatedEvent) {
|
||||
const data = event.data.data;
|
||||
console.log(data.user_privilege_id);
|
||||
const configurations = await this.dataService.getManyByOptions({
|
||||
const configuration = await this.dataService.getOneByOptions({
|
||||
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 createdConfig = configs
|
||||
configs
|
||||
.filter(
|
||||
(base) =>
|
||||
!configurations.some((data) => {
|
||||
!configurationData.some((data) => {
|
||||
return base.menu_label == data.menu_label;
|
||||
}),
|
||||
)
|
||||
.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 {
|
||||
...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
|
||||
.filter(
|
||||
(base) =>
|
||||
!configs.some((data) => {
|
||||
return base.menu_label == data.menu_label;
|
||||
}),
|
||||
)
|
||||
?.map((item) => item.id);
|
||||
Object.assign(configuration, {
|
||||
user_privilege_configurations: configurationData,
|
||||
});
|
||||
|
||||
const queryRunner = this.dataService
|
||||
.getRepository()
|
||||
.manager.connection.createQueryRunner();
|
||||
|
||||
if (createdConfig.length) {
|
||||
await this.dataService.createBatch(
|
||||
queryRunner,
|
||||
UserPrivilegeConfigurationModel,
|
||||
createdConfig,
|
||||
);
|
||||
}
|
||||
await this.dataService.update(
|
||||
queryRunner,
|
||||
UserPrivilegeConfigurationModel,
|
||||
{ id: data.user_privilege_id },
|
||||
configuration,
|
||||
);
|
||||
|
||||
if (deletedConfig.length) {
|
||||
await this.dataService.deleteByIds(
|
||||
queryRunner,
|
||||
UserPrivilegeConfigurationModel,
|
||||
deletedConfig,
|
||||
);
|
||||
}
|
||||
this.eventBus.publishAll([
|
||||
new UserPrivilegeUpdatedEvent({
|
||||
id: configuration.id,
|
||||
old: null,
|
||||
data: configuration,
|
||||
user: event.data.user,
|
||||
description: '',
|
||||
module: TABLE_NAME.USER_PRIVILEGE_CONFIGURATION,
|
||||
op: OPERATION.UPDATE,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import {
|
|||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
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()
|
||||
export class IndexUserPrivilegeConfigurationManager extends BaseIndexManager<UserPrivilegeConfigurationEntity> {
|
||||
|
@ -24,6 +26,62 @@ export class IndexUserPrivilegeConfigurationManager extends BaseIndexManager<Use
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue