mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import { Point } from '@dbTools/typeorm'
|
|
import { User as DbUser } from '@entity/User'
|
|
|
|
import { UpdateUserInfosArgs } from '@/graphql/arg/UpdateUserInfosArgs'
|
|
import { PublishNameType } from '@/graphql/enum/PublishNameType'
|
|
import { LogError } from '@/server/LogError'
|
|
import { backendLogger as logger } from '@/server/logger'
|
|
|
|
import { Point2Location } from './Location2Point'
|
|
|
|
export function compareGmsRelevantUserSettings(
|
|
orgUser: DbUser,
|
|
updateUserInfosArgs: UpdateUserInfosArgs,
|
|
): boolean {
|
|
if (!orgUser) {
|
|
throw new LogError('comparison without any user is impossible')
|
|
}
|
|
logger.debug('compareGmsRelevantUserSettings:', orgUser, updateUserInfosArgs)
|
|
// nach GMS updaten, wenn alias gesetzt wird oder ist und PublishLevel die alias-Übermittlung erlaubt
|
|
if (
|
|
updateUserInfosArgs.alias &&
|
|
orgUser.alias !== updateUserInfosArgs.alias &&
|
|
((updateUserInfosArgs.gmsPublishName &&
|
|
updateUserInfosArgs.gmsPublishName.valueOf ===
|
|
PublishNameType.PUBLISH_NAME_ALIAS_OR_INITALS.valueOf) ||
|
|
(!updateUserInfosArgs.gmsPublishName &&
|
|
orgUser.gmsPublishName &&
|
|
orgUser.gmsPublishName.valueOf === PublishNameType.PUBLISH_NAME_ALIAS_OR_INITALS.valueOf))
|
|
) {
|
|
return true
|
|
}
|
|
if (
|
|
(updateUserInfosArgs.firstName && orgUser.firstName !== updateUserInfosArgs.firstName) ||
|
|
(updateUserInfosArgs.lastName && orgUser.lastName !== updateUserInfosArgs.lastName)
|
|
) {
|
|
return true
|
|
}
|
|
if (
|
|
updateUserInfosArgs.gmsAllowed !== undefined &&
|
|
updateUserInfosArgs.gmsAllowed &&
|
|
orgUser.gmsAllowed !== updateUserInfosArgs.gmsAllowed
|
|
) {
|
|
return true
|
|
}
|
|
if (
|
|
updateUserInfosArgs.gmsPublishLocation &&
|
|
orgUser.gmsPublishLocation !== updateUserInfosArgs.gmsPublishLocation
|
|
) {
|
|
return true
|
|
}
|
|
if (
|
|
updateUserInfosArgs.gmsPublishName &&
|
|
orgUser.gmsPublishName !== updateUserInfosArgs.gmsPublishName
|
|
) {
|
|
return true
|
|
}
|
|
if (updateUserInfosArgs.language && orgUser.language !== updateUserInfosArgs.language) {
|
|
return true
|
|
}
|
|
if (
|
|
updateUserInfosArgs.gmsLocation &&
|
|
orgUser.location === null &&
|
|
updateUserInfosArgs.gmsLocation !== null
|
|
) {
|
|
return true
|
|
}
|
|
if (
|
|
updateUserInfosArgs.gmsLocation &&
|
|
orgUser.location !== null &&
|
|
updateUserInfosArgs.gmsLocation === null
|
|
) {
|
|
return true
|
|
}
|
|
if (
|
|
updateUserInfosArgs.gmsLocation &&
|
|
orgUser.location !== null &&
|
|
updateUserInfosArgs.gmsLocation !== null
|
|
) {
|
|
const orgLocation = Point2Location(orgUser.location as Point)
|
|
const changedLocation = updateUserInfosArgs.gmsLocation
|
|
if (
|
|
orgLocation.latitude !== changedLocation.latitude ||
|
|
orgLocation.longitude !== changedLocation.longitude
|
|
) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|