Skip to content

Commit

Permalink
Add a phone number column to the user_accounts table (bloom-housing#2134
Browse files Browse the repository at this point in the history
)

* Merge pull request #710 from CityOfDetroit/feature/add-phonenumber-to-user-entity

Add phone number to user accounts.

* Merge pull request #728 from CityOfDetroit/fix/modify-phone-number-test

Fix user E2E tests.

* Merge pull request #728 from CityOfDetroit/fix/modify-phone-number-test

Fix user E2E tests.

* fix: add validation groups to phoneNumber
  • Loading branch information
plunkettgoogle authored Nov 9, 2021
1 parent 96edc3b commit 2647df9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/core/src/auth/dto/user-profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class UserProfileUpdateDto extends PickType(User, [
"createdAt",
"updatedAt",
"language",
"phoneNumber",
] as const) {
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
Expand Down
17 changes: 16 additions & 1 deletion backend/core/src/auth/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ import {
} from "typeorm"
import { Listing } from "../../listings/entities/listing.entity"
import { Expose, Type } from "class-transformer"
import { IsDate, IsEmail, IsEnum, IsOptional, IsString, IsUUID, MaxLength } from "class-validator"
import {
IsDate,
IsEmail,
IsEnum,
IsOptional,
IsPhoneNumber,
IsString,
IsUUID,
MaxLength,
} from "class-validator"
import { ValidationsGroupsEnum } from "../../shared/types/validations-groups-enum"
import { ApiProperty } from "@nestjs/swagger"
import { Language } from "../../shared/types/language-enum"
Expand Down Expand Up @@ -77,6 +86,12 @@ export class User {
@Type(() => Date)
dob?: Date | null

@Column("varchar", { nullable: true })
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsPhoneNumber(null, { groups: [ValidationsGroupsEnum.default] })
phoneNumber?: string

@CreateDateColumn()
@Expose()
@IsDate({ groups: [ValidationsGroupsEnum.default] })
Expand Down
13 changes: 13 additions & 0 deletions backend/core/src/migration/1634848388161-add-phone-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class addPhoneNumber1634848388161 implements MigrationInterface {
name = "addPhoneNumber1634848388161"

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user_accounts" ADD "phone_number" character varying`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user_accounts" DROP COLUMN "phone_number"`)
}
}
3 changes: 2 additions & 1 deletion backend/core/test/user/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe("Applications", () => {
expect(token).toBeDefined()
})

it("should allow user to update user profile throguh PUT /userProfile/:id endpoint", async () => {
it("should allow user to update user profile through PUT /userProfile/:id endpoint", async () => {
const userCreateDto: UserCreateDto = {
password: "Abcdef1!",
passwordConfirmation: "Abcdef1!",
Expand Down Expand Up @@ -452,6 +452,7 @@ describe("Applications", () => {
...userCreateDto,
currentPassword: userCreateDto.password,
firstName: "NewFirstName",
phoneNumber: "+12025550194",
}

await supertest(app.getHttpServer())
Expand Down
15 changes: 15 additions & 0 deletions backend/core/types/src/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3893,6 +3893,9 @@ export interface User {
/** */
dob?: Date

/** */
phoneNumber?: string

/** */
createdAt: Date

Expand Down Expand Up @@ -3936,6 +3939,9 @@ export interface UserCreate {

/** */
dob?: Date

/** */
phoneNumber?: string
}

export interface UserBasic {
Expand Down Expand Up @@ -3972,6 +3978,9 @@ export interface UserBasic {
/** */
dob?: Date

/** */
phoneNumber?: string

/** */
createdAt: Date

Expand Down Expand Up @@ -4072,6 +4081,9 @@ export interface UserUpdate {

/** */
dob?: Date

/** */
phoneNumber?: string
}

export interface UserFilterParams {
Expand Down Expand Up @@ -4131,6 +4143,9 @@ export interface UserInvite {

/** */
dob?: Date

/** */
phoneNumber?: string
}

export interface UserProfileUpdate {
Expand Down

0 comments on commit 2647df9

Please sign in to comment.