Probably I know what causing this error, but I don't know how to fix it. I have some code with subscribe:
.subscribe(([a, b]: [any, any]) => {
if (this.files.length > 0) {
const setImagesStatus = (b.body.objectData as DtoSetAppBackgroundImagesStatus);
if (setImagesStatus.success) {
this.hasBackgroundImages = true;
this.files = [];
notify('Data successfully updated', 'success');
} else {
notify('Application background images upload error. ' + setImagesStatus.info, 'error', 9000);
}
} else {
notify('Data successfully updated', 'success');
}
const parsedUserBeforeChanges = new UserPreLogDataConverter(this.groupsService,this.groups).GetPreLogData(updateUserDto);
const parsedUserAfterChanges = new UserPreLogDataConverter(this.groupsService,this.groups).GetPreLogData(this.userWithNoChanges);
this.eventLogEndpointSvc
.addLogs(this.serverEventLogger
.LogChanges(JSON.parse(JSON.stringify(parsedUserBeforeChanges)),JSON.parse(JSON.stringify(parsedUserAfterChanges)),
() => {
this.userCustomLogFunction(parsedUserBeforeChanges,parsedUserAfterChanges);
}
)).subscribe().add(this.userWithNoChanges=JSON.parse(JSON.stringify(updateUserDto)));}
);
My this.userCustomLogFunction
looks like this:
userCustomLogFunction(userWithNoChanges: UserPreLogData,updateUserDto: UserPreLogData): Array<DtoEventLog>
{
const oldGroupIds = userWithNoChanges.groups.map(x=>x.id);
const newGroupIds = updateUserDto.groups.map(x=>x.id);
const addedToGroups = newGroupIds.filter(x => !oldGroupIds.some(y => JSON.stringify(x) === JSON.stringify(y)));
const deletedFromGroups = oldGroupIds.filter(x => !newGroupIds.some(y => JSON.stringify(x) === JSON.stringify(y)));
const groupLogs: DtoEventLog[] = [];
for(const id in addedToGroups)
{
const evLog = new DtoEventLog();
evLog.methodName = 'LiftaKitMobileAppTestUsers.Update';
evLog.objectId=addedToGroups[id].toString();
evLog.login=this.authService.getUser().login;
evLog.firstName =this.authService.getUser().firstName;
evLog.lastName = this.authService.getUser().lastName;
evLog.email = this.authService.getUser().email;
evLog.logType=EventLogType.UPDATE.toString();
evLog.scope=EventLogScope.GROUP.toString();
evLog.input ='Added user' + updateUserDto.firstName + ' ' + updateUserDto.lastName + ' login: ' + updateUserDto.login + ' no: '+ updateUserDto.no +', id: ' + updateUserDto.iD;
groupLogs.push(evLog);
}
for(const id in deletedFromGroups)
{
const evLog = new DtoEventLog();
evLog.methodName = 'LiftaKitMobileAppTestUsers.Update';
evLog.objectId=deletedFromGroups[id].toString();
evLog.login=this.authService.getUser().login;
evLog.firstName =this.authService.getUser().firstName;
evLog.lastName = this.authService.getUser().lastName;
evLog.email = this.authService.getUser().email;
evLog.logType=EventLogType.UPDATE.toString();
evLog.scope=EventLogScope.GROUP.toString();
evLog.input ='Deleted user' + updateUserDto.firstName + ' ' + updateUserDto.lastName + ' login: ' + updateUserDto.login + ' no: '+ updateUserDto.no +', id: ' + updateUserDto.iD;
groupLogs.push(evLog);
}
return groupLogs;
}
So as you see nothing special, and it works fine but.. Inside method LogChanges
I calling this method (passed as argument, and called as logMethod()
) and it always returns undefined. I don't know how to fix it...
LogChanges<Type>(ob1: Type,ob2: Type=null,logMethod: Function = () => new Array<DtoEventLog>()): Array<DtoEventLog> {
const additionalRelation = logMethod();
//rest code here
}
What should I do? I think there's something badly written in the first subscribe where I calling AddLogs and LogChanges.