adapt user migrations on concept requirements

This commit is contained in:
Claus-Peter Huebner 2023-12-20 21:07:15 +01:00
parent e699108952
commit ef73207609
3 changed files with 47 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import { registerEnumType } from 'type-graphql'
export enum GmsPublishNameType {
GMS_PUBLISH_NAME_NOTHING = 0,
GMS_PUBLISH_NAME_ALIAS_OR_INITALS = 0,
GMS_PUBLISH_NAME_INITIALS = 1,
GMS_PUBLISH_NAME_FIRST = 2,
GMS_PUBLISH_NAME_FIRST_INITIAL = 3,

View File

@ -11,7 +11,7 @@ export class GmsUser {
this.mobile = this.getGmsPhone(user)
this.firstName = this.getGmsFirstName(user)
this.lastName = this.getGmsLastName(user)
this.alias = user.alias ? user.alias : undefined
this.alias = this.getGmsAlias(user)
this.type = GmsLocationType.GMS_LOCATION_TYPE_RANDOM
this.location = null
}
@ -37,6 +37,16 @@ export class GmsUser {
language: string
location: unknown
private getGmsAlias(user: dbUser): string | undefined {
if (
user.gmsAllowed &&
user.alias &&
user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS
) {
return user.alias
}
}
private getGmsFirstName(user: dbUser): string | undefined {
if (
user.gmsAllowed &&
@ -46,8 +56,13 @@ export class GmsUser {
) {
return user.firstName
}
if (user.gmsAllowed && user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_INITIALS) {
return user.firstName.substring(0, 1) + '.'
if (
user.gmsAllowed &&
((!user.alias &&
user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS) ||
user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_INITIALS)
) {
return user.firstName.substring(0, 1)
}
}
@ -57,10 +72,12 @@ export class GmsUser {
}
if (
user.gmsAllowed &&
(user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_FIRST_INITIAL ||
((!user.alias &&
user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS) ||
user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_FIRST_INITIAL ||
user.gmsPublishName === GmsPublishNameType.GMS_PUBLISH_NAME_INITIALS)
) {
return user.lastName.substring(0, 1) + '.'
return user.lastName.substring(0, 1)
}
}

View File

@ -55,9 +55,15 @@ const run = async () => {
throw new LogError('HomeCommunity needs GMS-ApiKey to publish user data to GMS.')
}
// read the ids of all local users, which are still not gms registered
const userIds = await DbUser.query(
'SELECT `id` from `users` `u` where `u`.`foreign` = false and `deleted_at` is null and `gms_registered` = false',
)
const userIds = await DbUser.createQueryBuilder()
.select('id')
.where({ foreign: false })
.andWhere('deleted_at is null')
.andWhere({ gmsRegistered: false })
.getRawMany()
// const userIds = await DbUser.query(
// 'SELECT `id` from `users` `u` where `u`.`foreign` = false and `deleted_at` is null and `gms_registered` = false',
// )
logger.debug('userIds:', userIds)
for (const idStr of userIds) {
@ -68,18 +74,22 @@ const run = async () => {
})
if (user) {
logger.debug('found local User:', user)
const gmsUser = new GmsUser(user)
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
if (await createGmsUser(homeCom.gmsApiKey, gmsUser)) {
logger.debug('GMS user published successfully:', gmsUser)
user.gmsRegistered = true
user.gmsRegisteredAt = new Date()
await DbUser.save(user)
logger.debug('mark user as gms published:', user)
if (user.gmsAllowed) {
const gmsUser = new GmsUser(user)
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
if (await createGmsUser(homeCom.gmsApiKey, gmsUser)) {
logger.debug('GMS user published successfully:', gmsUser)
user.gmsRegistered = true
user.gmsRegisteredAt = new Date()
await DbUser.save(user)
logger.debug('mark user as gms published:', user)
}
} catch (err) {
logger.warn('publishing user fails with ', err)
}
} catch (err) {
logger.warn('publishing user fails with ', err)
} else {
logger.debug('GMS-Publishing not allowed by user settings:', user)
}
}
}