mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
change default alias, add logic class for publishName enum
This commit is contained in:
parent
b40ad3254a
commit
37e91f86fd
@ -7,10 +7,7 @@ export class Account {
|
||||
if (user.alias && user.alias.length > 2) {
|
||||
this.username = user.alias
|
||||
} else {
|
||||
// Use the replace method to remove the part after '+' and before '@'
|
||||
// source: https://people.cs.rutgers.edu/~watrous/plus-signs-in-email-addresses.html
|
||||
// email address with + exist but humhub doesn't allow username with +
|
||||
this.username = user.emailContact.email.replace(/\+(.*)@/, '@')
|
||||
this.username = user.gradidoID
|
||||
}
|
||||
|
||||
this.email = user.emailContact.email
|
||||
|
||||
67
backend/src/data/PublishName.logic.ts
Normal file
67
backend/src/data/PublishName.logic.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { User } from '@entity/User'
|
||||
|
||||
import { GmsPublishNameType } from '@/graphql/enum/GmsPublishNameType';
|
||||
|
||||
export class PublishNameLogic {
|
||||
constructor(private user: User) {}
|
||||
|
||||
/**
|
||||
* get first name based on publishNameType: GmsPublishNameType value
|
||||
* @param publishNameType
|
||||
* @returns user.firstName for GMS_PUBLISH_NAME_FIRST, GMS_PUBLISH_NAME_FIRST_INITIAL or GMS_PUBLISH_NAME_FULL
|
||||
* first initial from user.firstName for GMS_PUBLISH_NAME_INITIALS or GMS_PUBLISH_NAME_ALIAS_OR_INITALS and empty alias
|
||||
*/
|
||||
public getFirstName(publishNameType: GmsPublishNameType): string | undefined {
|
||||
if (
|
||||
[
|
||||
GmsPublishNameType.GMS_PUBLISH_NAME_FIRST,
|
||||
GmsPublishNameType.GMS_PUBLISH_NAME_FIRST_INITIAL,
|
||||
GmsPublishNameType.GMS_PUBLISH_NAME_FULL,
|
||||
].includes(publishNameType)
|
||||
) {
|
||||
return this.user.firstName
|
||||
}
|
||||
if (
|
||||
(!this.user.alias &&
|
||||
publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS) ||
|
||||
publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_INITIALS
|
||||
) {
|
||||
return this.user.firstName.substring(0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get last name based on publishNameType: GmsPublishNameType value
|
||||
* @param publishNameType
|
||||
* @returns user.lastName for GMS_PUBLISH_NAME_FULL
|
||||
* first initial from user.lastName for GMS_PUBLISH_NAME_FIRST_INITIAL, GMS_PUBLISH_NAME_INITIALS or GMS_PUBLISH_NAME_ALIAS_OR_INITALS and empty alias
|
||||
*/
|
||||
public getLastName(publishNameType: GmsPublishNameType): string | undefined {
|
||||
if (publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_FULL) {
|
||||
return this.user.lastName
|
||||
}
|
||||
if (
|
||||
(!this.user.alias &&
|
||||
publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS) ||
|
||||
publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_FIRST_INITIAL ||
|
||||
publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_INITIALS
|
||||
) {
|
||||
return this.user.lastName.substring(0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
public getUsername(publishNameType: GmsPublishNameType): string {
|
||||
if (
|
||||
this.user.alias &&
|
||||
publishNameType === GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS
|
||||
) {
|
||||
return this.user.alias
|
||||
}
|
||||
const firstName = this.getFirstName(publishNameType)
|
||||
const lastName = this.getLastName(publishNameType)
|
||||
if (firstName && lastName) {
|
||||
return `${firstName} ${lastName}`
|
||||
}
|
||||
return this.user.gradidoID
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user