Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a phone number column to the user_accounts table #2134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -23,6 +23,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 @@ -406,7 +406,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 @@ -447,6 +447,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 @@ -3783,6 +3783,9 @@ export interface User {
/** */
dob?: Date

/** */
phoneNumber?: string

/** */
createdAt: Date

Expand Down Expand Up @@ -3826,6 +3829,9 @@ export interface UserCreate {

/** */
dob?: Date

/** */
phoneNumber?: string
}

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

/** */
phoneNumber?: string

/** */
createdAt: Date

Expand Down Expand Up @@ -3956,6 +3965,9 @@ export interface UserUpdate {

/** */
dob?: Date

/** */
phoneNumber?: string
}

export interface UserFilterParams {
Expand Down Expand Up @@ -4012,6 +4024,9 @@ export interface UserInvite {

/** */
dob?: Date

/** */
phoneNumber?: string
}

export interface UserProfileUpdate {
Expand Down