adapt database and entities on model of concept

This commit is contained in:
Claus-Peter Huebner 2023-12-18 21:10:34 +01:00
parent a941d06b55
commit e699108952
7 changed files with 38 additions and 121 deletions

View File

@ -24,18 +24,6 @@ registerEnumType(GmsPublishPhoneType, {
description: 'Type of Phone publishing', // this one is optional
})
export enum GmsPublishPostType {
GMS_PUBLISH_POST_NOTHING = 0,
GMS_PUBLISH_POST_COUNTRY = 1,
GMS_PUBLISH_POST_CITY = 2,
GMS_PUBLISH_POST_FULL = 3,
}
registerEnumType(GmsPublishPostType, {
name: 'GmsPublishPostType', // this one is mandatory
description: 'Type of name publishing', // this one is optional
})
export enum GmsLocationType {
GMS_LOCATION_TYPE_EXACT = 0,
GMS_LOCATION_TYPE_APPROXIMATE = 1,

View File

@ -1,11 +1,6 @@
import { User as dbUser } from '@entity/User'
import {
GmsLocationType,
GmsPublishNameType,
GmsPublishPhoneType,
GmsPublishPostType,
} from './GmsEnums'
import { GmsLocationType, GmsPublishNameType, GmsPublishPhoneType } from './GmsEnums'
export class GmsUser {
constructor(user: dbUser) {
@ -17,10 +12,6 @@ export class GmsUser {
this.firstName = this.getGmsFirstName(user)
this.lastName = this.getGmsLastName(user)
this.alias = user.alias ? user.alias : undefined
this.address = this.getGmsAddress(user)
// this.zipCode = this.getGmsZipCode(user)
// this.city = this.getGmsCity(user)
// this.country = this.getGmsCountry(user)
this.type = GmsLocationType.GMS_LOCATION_TYPE_RANDOM
this.location = null
}
@ -97,51 +88,4 @@ export class GmsUser {
return user.emailContact.phone
}
}
private getGmsAddress(user: dbUser): string | undefined {
if (user.gmsAllowed) {
if (user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_FULL) {
const address = [
'' + user.emailContact.country,
...(user.emailContact.zipCode ? user.emailContact.zipCode : ' '),
user.emailContact.city ? user.emailContact.city : ' ',
user.emailContact.address ? user.emailContact.address : ' ',
]
.map((a) => a.trim())
.filter(Boolean)
.join(', ')
return address
}
}
}
private getGmsZipCode(user: dbUser): string | undefined {
if (
user.gmsAllowed &&
(user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_CITY ||
user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_FULL)
) {
return user.emailContact.zipCode
}
}
private getGmsCity(user: dbUser): string | undefined {
if (
user.gmsAllowed &&
(user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_CITY ||
user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_FULL)
) {
return user.emailContact.city
}
}
private getGmsCountry(user: dbUser): string | undefined {
if (
user.gmsAllowed &&
(user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_COUNTRY ||
user.emailContact.gmsPublishPost === GmsPublishPostType.GMS_PUBLISH_POST_FULL)
) {
return user.emailContact.country
}
}
}

View File

@ -178,7 +178,9 @@ describe('UserResolver', () => {
communityUuid: homeCom.communityUuid,
foreign: false,
gmsAllowed: true,
gmsPublishName: 3,
gmsPublishName: 0,
gmsPublishLocation: 2,
location: null,
gmsRegistered: false,
gmsRegisteredAt: null,
},
@ -199,18 +201,13 @@ describe('UserResolver', () => {
emailVerificationCode: expect.any(String),
emailOptInTypeId: OptInType.EMAIL_OPT_IN_REGISTER,
emailResendCount: 0,
countryCode: null,
phone: null,
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: null,
gmsPublishEmail: false,
gmsPublishPhone: 0,
gmsPublishPost: 0,
address: null,
city: null,
country: null,
countryCode: null,
zipCode: null,
})
})
})

View File

@ -52,6 +52,8 @@ const communityDbUser: dbUser = {
communityUuid: '55555555-4444-4333-2222-11111111',
gmsPublishName: 0,
gmsAllowed: false,
location: null,
gmsPublishLocation: 2,
gmsRegistered: false,
gmsRegisteredAt: null,
}

View File

@ -7,6 +7,7 @@ import {
OneToMany,
JoinColumn,
OneToOne,
Geometry,
} from 'typeorm'
import { Contribution } from '../Contribution'
import { ContributionMessage } from '../ContributionMessage'
@ -124,6 +125,18 @@ export class User extends BaseEntity {
@Column({ name: 'gms_allowed', type: 'bool', default: true })
gmsAllowed: boolean
@Column({ name: 'location', type: 'geometry', default: null, nullable: true })
location: Geometry | null
@Column({
name: 'gms_publish_location',
type: 'int',
unsigned: true,
nullable: false,
default: 2,
})
gmsPublishLocation: number
@Column({ name: 'gms_registered', type: 'bool', default: false })
gmsRegistered: boolean

View File

@ -5,6 +5,8 @@ import {
Column,
DeleteDateColumn,
OneToOne,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm'
import { User } from '../User'
@ -61,31 +63,14 @@ export class UserContact extends BaseEntity {
@Column({ name: 'gms_publish_phone', type: 'int', unsigned: true, nullable: false, default: 0 })
gmsPublishPhone: number
@Column({ length: 255, unique: false, nullable: true, collation: 'utf8mb4_unicode_ci' })
address: string
@Column({ length: 255, unique: false, nullable: true, collation: 'utf8mb4_unicode_ci' })
city: string
@Column({
name: 'zip_code',
length: 255,
unique: false,
nullable: true,
collation: 'utf8mb4_unicode_ci',
})
zipCode: string
@Column({ length: 255, unique: false, nullable: true, collation: 'utf8mb4_unicode_ci' })
country: string
@Column({ name: 'gms_publish_post', type: 'int', unsigned: true, nullable: false, default: 0 })
gmsPublishPost: number
@Column({ name: 'created_at', default: () => 'CURRENT_TIMESTAMP', nullable: false })
@CreateDateColumn({ name: 'created_at', default: () => 'CURRENT_TIMESTAMP(3)', nullable: false })
createdAt: Date
@Column({ name: 'updated_at', nullable: true, default: null, type: 'datetime' })
@UpdateDateColumn({
name: 'updated_at',
nullable: true,
onUpdate: 'CURRENT_TIMESTAMP(3)',
})
updatedAt: Date | null
@DeleteDateColumn({ name: 'deleted_at', nullable: true })

View File

@ -6,11 +6,17 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
'ALTER TABLE `users` MODIFY COLUMN `foreign` tinyint(1) NOT NULL DEFAULT 0 AFTER `id`;',
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `gms_publish_name` int unsigned NOT NULL DEFAULT 3 AFTER `last_name`;', // COMMENT '0:nothing, 1:initials only, 2:firstName only, 3:firstName + Initial of LastName, 4:fullName'
'ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `gms_publish_name` int unsigned NOT NULL DEFAULT 0 AFTER `last_name`;', // COMMENT '0:alias if exists or initials only , 1:initials only, 2:firstName only, 3:firstName + Initial of LastName, 4:fullName'
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `gms_allowed` tinyint(1) NOT NULL DEFAULT 1;',
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `location` geometry DEFAULT NULL NULL AFTER `gms_allowed`;',
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `gms_publish_location` int unsigned NOT NULL DEFAULT 2 AFTER `location`;', // COMMENT '0:exact, 1:approximate, 2:random'
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `gms_registered` tinyint(1) NOT NULL DEFAULT 0;',
)
@ -26,21 +32,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
await queryFn(
'ALTER TABLE `user_contacts` ADD COLUMN IF NOT EXISTS `gms_publish_phone` int unsigned NOT NULL DEFAULT 0 AFTER `phone`;', // COMMENT '0:nothing, 1:country_code only, 2:complet phone number'
)
await queryFn(
'ALTER TABLE `user_contacts` ADD COLUMN IF NOT EXISTS `address` varchar(255) DEFAULT NULL NULL AFTER `gms_publish_phone`;',
)
await queryFn(
'ALTER TABLE `user_contacts` ADD COLUMN IF NOT EXISTS `city` varchar(255) DEFAULT NULL NULL AFTER `address`;',
)
await queryFn(
'ALTER TABLE `user_contacts` ADD COLUMN IF NOT EXISTS `zip_code` varchar(255) DEFAULT NULL NULL AFTER `city`;',
)
await queryFn(
'ALTER TABLE `user_contacts` ADD COLUMN IF NOT EXISTS `country` varchar(255) DEFAULT NULL NULL AFTER `zip_code`;',
)
await queryFn(
'ALTER TABLE `user_contacts` ADD COLUMN IF NOT EXISTS `gms_publish_post` int unsigned NOT NULL DEFAULT 0 AFTER `country`;', // COMMENT '0:nothing, 1:country, 2:city, 3: detailed address'
)
await queryFn(
'ALTER TABLE `communities` ADD COLUMN IF NOT EXISTS `gms_api_key` varchar(512) DEFAULT NULL NULL AFTER `description`;',
)
@ -52,15 +43,12 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
)
await queryFn('ALTER TABLE `users` DROP COLUMN IF EXISTS `gms_publish_name`;')
await queryFn('ALTER TABLE `users` DROP COLUMN IF EXISTS `gms_allowed`;')
await queryFn('ALTER TABLE `users` DROP COLUMN IF EXISTS `location`;')
await queryFn('ALTER TABLE `users` DROP COLUMN IF EXISTS `gms_publish_location`;')
await queryFn('ALTER TABLE `users` DROP COLUMN IF EXISTS `gms_registered`;')
await queryFn('ALTER TABLE `users` DROP COLUMN IF EXISTS `gms_registered_at`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `gms_publish_email`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `country_code`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `gms_publish_phone`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `address`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `city`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `zip_code`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `country`;')
await queryFn('ALTER TABLE `user_contacts` DROP COLUMN IF EXISTS `gms_publish_post`;')
await queryFn('ALTER TABLE `communities` DROP COLUMN IF EXISTS `gms_api_key`;')
await queryFn('ALTER TABLE `communities` DROP COLUMN IF EXISTS `gms_api_key`;')
}