diff --git a/backend/src/apis/gms/model/GmsEnums.ts b/backend/src/apis/gms/model/GmsEnums.ts index db6e82825..5fa08a3f7 100644 --- a/backend/src/apis/gms/model/GmsEnums.ts +++ b/backend/src/apis/gms/model/GmsEnums.ts @@ -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, diff --git a/backend/src/apis/gms/model/GmsUser.ts b/backend/src/apis/gms/model/GmsUser.ts index 0c0202b0f..efea12304 100644 --- a/backend/src/apis/gms/model/GmsUser.ts +++ b/backend/src/apis/gms/model/GmsUser.ts @@ -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 - } - } } diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 2bcf3f165..a4892496b 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -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, }) }) }) diff --git a/backend/src/util/communityUser.ts b/backend/src/util/communityUser.ts index a0c4bf681..9e337dfe7 100644 --- a/backend/src/util/communityUser.ts +++ b/backend/src/util/communityUser.ts @@ -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, } diff --git a/database/entity/0079-introduce_gms_registration/User.ts b/database/entity/0079-introduce_gms_registration/User.ts index edcdd1257..f91129f31 100644 --- a/database/entity/0079-introduce_gms_registration/User.ts +++ b/database/entity/0079-introduce_gms_registration/User.ts @@ -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 diff --git a/database/entity/0079-introduce_gms_registration/UserContact.ts b/database/entity/0079-introduce_gms_registration/UserContact.ts index a3d0a8f52..82ae4c013 100644 --- a/database/entity/0079-introduce_gms_registration/UserContact.ts +++ b/database/entity/0079-introduce_gms_registration/UserContact.ts @@ -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 }) diff --git a/database/migrations/0079-introduce_gms_registration.ts b/database/migrations/0079-introduce_gms_registration.ts index 6de55333f..e02801a4f 100644 --- a/database/migrations/0079-introduce_gms_registration.ts +++ b/database/migrations/0079-introduce_gms_registration.ts @@ -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`;') }