adapt treatment of gms-attributes in updateUserInfo

This commit is contained in:
Claus-Peter Huebner 2024-03-07 14:12:24 +01:00
parent 89f0e9a694
commit 4edb039e52
2 changed files with 44 additions and 20 deletions

View File

@ -541,8 +541,10 @@ export class UserResolver {
@Authorized([RIGHTS.UPDATE_USER_INFOS])
@Mutation(() => Boolean)
async updateUserInfos(
@Args()
{
@Args() updateUserInfosArgs: UpdateUserInfosArgs,
@Ctx() context: Context,
): Promise<boolean> {
const {
firstName,
lastName,
alias,
@ -555,14 +557,11 @@ export class UserResolver {
gmsPublishName,
gmsLocation,
gmsPublishLocation,
}: UpdateUserInfosArgs,
@Ctx() context: Context,
): Promise<boolean> {
} = updateUserInfosArgs
logger.info(
`updateUserInfos(${firstName}, ${lastName}, ${alias}, ${language}, ***, ***, ${hideAmountGDD}, ${hideAmountGDT}, ${gmsAllowed}, ${gmsPublishName}, ${gmsLocation}, ${gmsPublishLocation})...`,
)
const user = getUser(context)
const backupOriginalUser = user
// try {
if (firstName) {
@ -646,7 +645,7 @@ export class UserResolver {
await EVENT_USER_INFO_UPDATE(user)
// validate if user settings are changed with relevance to update gms-user
if (compareGmsRelevantUserSettings(user, backupOriginalUser)) {
if (compareGmsRelevantUserSettings(user, updateUserInfosArgs)) {
logger.debug(`changed user-settings relevant for gms-user update...`)
const homeCom = await getHomeCommunity()
if (homeCom.gmsApiKey !== null) {

View File

@ -1,43 +1,68 @@
import { Point } from '@dbTools/typeorm'
import { User as DbUser } from '@entity/User'
import { UpdateUserInfosArgs } from '@/graphql/arg/UpdateUserInfosArgs'
import { LogError } from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { Point2Location } from './Location2Point'
export function compareGmsRelevantUserSettings(orgUser: DbUser, changedUser: DbUser): boolean {
if (!orgUser && !changedUser) {
export function compareGmsRelevantUserSettings(
orgUser: DbUser,
updateUserInfosArgs: UpdateUserInfosArgs,
): boolean {
if (!orgUser) {
throw new LogError('comparison without any user is impossible')
}
logger.debug('compareGmsRelevantUserSettings:', orgUser, changedUser)
if (orgUser.alias !== changedUser.alias) {
logger.debug('compareGmsRelevantUserSettings:', orgUser, updateUserInfosArgs)
if (updateUserInfosArgs.alias && orgUser.alias !== updateUserInfosArgs.alias) {
return true
}
if (orgUser.firstName !== changedUser.firstName || orgUser.lastName !== changedUser.lastName) {
if (
(updateUserInfosArgs.firstName && orgUser.firstName !== updateUserInfosArgs.firstName) ||
(updateUserInfosArgs.lastName && orgUser.lastName !== updateUserInfosArgs.lastName)
) {
return true
}
if (orgUser.gmsAllowed !== changedUser.gmsAllowed) {
if (updateUserInfosArgs.gmsAllowed && orgUser.gmsAllowed !== updateUserInfosArgs.gmsAllowed) {
return true
}
if (orgUser.gmsPublishLocation !== changedUser.gmsPublishLocation) {
if (
updateUserInfosArgs.gmsPublishLocation &&
orgUser.gmsPublishLocation !== updateUserInfosArgs.gmsPublishLocation
) {
return true
}
if (orgUser.gmsPublishName !== changedUser.gmsPublishName) {
if (
updateUserInfosArgs.gmsPublishName &&
orgUser.gmsPublishName !== updateUserInfosArgs.gmsPublishName
) {
return true
}
if (orgUser.language !== changedUser.language) {
if (updateUserInfosArgs.language && orgUser.language !== updateUserInfosArgs.language) {
return true
}
if (orgUser.location === null && changedUser.location !== null) {
if (
updateUserInfosArgs.gmsLocation &&
orgUser.location === null &&
updateUserInfosArgs.gmsLocation !== null
) {
return true
}
if (orgUser.location !== null && changedUser.location === null) {
if (
updateUserInfosArgs.gmsLocation &&
orgUser.location !== null &&
updateUserInfosArgs.gmsLocation === null
) {
return true
}
if (orgUser.location !== null && changedUser.location !== null) {
if (
updateUserInfosArgs.gmsLocation &&
orgUser.location !== null &&
updateUserInfosArgs.gmsLocation !== null
) {
const orgLocation = Point2Location(orgUser.location as Point)
const changedLocation = Point2Location(changedUser.location as Point)
const changedLocation = updateUserInfosArgs.gmsLocation
if (
orgLocation.latitude !== changedLocation.latitude ||
orgLocation.longitude !== changedLocation.longitude