From 428a6b76edabee96f5f882171c3686c87e272fe2 Mon Sep 17 00:00:00 2001 From: danilomelin Date: Tue, 11 Jul 2023 23:36:32 -0300 Subject: [PATCH] feat: mentor-cycle#53 - formatting field years of experience to experience --- .../migration.sql | 2 ++ .../migration.sql | 9 +++++++++ prisma/schema.prisma | 2 +- schema.gql | 6 +++--- src/modules/user/dto/create-user.input.ts | 11 ++++++++--- src/modules/user/entities/user.entity.ts | 4 ++-- src/modules/user/user.service.ts | 2 +- 7 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 prisma/migrations/20230712011055_transform_years_of_experience_into_string/migration.sql create mode 100644 prisma/migrations/20230712011520_rename_years_of_experience/migration.sql diff --git a/prisma/migrations/20230712011055_transform_years_of_experience_into_string/migration.sql b/prisma/migrations/20230712011055_transform_years_of_experience_into_string/migration.sql new file mode 100644 index 0000000..564f6cc --- /dev/null +++ b/prisma/migrations/20230712011055_transform_years_of_experience_into_string/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "users" ALTER COLUMN "years_of_experience" SET DATA TYPE TEXT; diff --git a/prisma/migrations/20230712011520_rename_years_of_experience/migration.sql b/prisma/migrations/20230712011520_rename_years_of_experience/migration.sql new file mode 100644 index 0000000..30a80fa --- /dev/null +++ b/prisma/migrations/20230712011520_rename_years_of_experience/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - You are about to drop the column `years_of_experience` on the `users` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "users" DROP COLUMN "years_of_experience", +ADD COLUMN "experience" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c221aa5..e6728bf 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -33,7 +33,7 @@ model User { linkedin String? github String? website String? - yearsOfExperience Float? @map("years_of_experience") + experience String? @map("experience") description String? jobTitle String? @map("job_title") jobCompany String? @map("job_company") diff --git a/schema.gql b/schema.gql index 8b5f8f8..369b72c 100644 --- a/schema.gql +++ b/schema.gql @@ -22,7 +22,7 @@ type User { firstName: String! lastName: String photoUrl: String - yearsOfExperience: Float + experience: String isEmailVerified: Boolean! isTermsAccepted: Boolean! onBoardingCompleted: Boolean! @@ -197,7 +197,7 @@ input CreateUserInput { email: String! password: String! photoUrl: String - yearsOfExperience: Float + experience: String! skills: [String!]! birthDate: DateTime zipCode: String! @@ -223,7 +223,7 @@ input UpdateUserDto { email: String password: String photoUrl: String - yearsOfExperience: Float + experience: String skills: [String!] birthDate: DateTime zipCode: String diff --git a/src/modules/user/dto/create-user.input.ts b/src/modules/user/dto/create-user.input.ts index 9746415..b8187cf 100644 --- a/src/modules/user/dto/create-user.input.ts +++ b/src/modules/user/dto/create-user.input.ts @@ -49,9 +49,14 @@ export class CreateUserInput { @IsUrl() photoUrl?: string; - @Field({ nullable: true }) + @Field() @IsOptional() - yearsOfExperience?: number; + @IsString() + @Length(3, 5) + @Matches(/^[0-9]{1,2}-(10|11|[0-9]{1})$/, { + message: 'experience should be on format "99-99" (years-months)', + }) + experience?: string; @Field(() => [String], { nullable: false }) @IsEnum(Skill, { each: true }) @@ -68,7 +73,7 @@ export class CreateUserInput { @IsString() @Length(9, 9) @Matches(/^[0-9]{5}-[0-9]{3}/, { - message: 'Zip code should be on format "99999-99"', + message: 'zipCode should be on format "99999-999"', }) zipCode?: string; diff --git a/src/modules/user/entities/user.entity.ts b/src/modules/user/entities/user.entity.ts index 8d776de..6f770ef 100644 --- a/src/modules/user/entities/user.entity.ts +++ b/src/modules/user/entities/user.entity.ts @@ -19,8 +19,8 @@ export class User { lastName?: string | null; @Field(() => String, { nullable: true }) photoUrl?: string | null; - @Field(() => Float, { nullable: true }) - yearsOfExperience?: number | null; + @Field(() => String, { nullable: true }) + experience?: string | null; @Field() isEmailVerified: boolean; @Field() diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index 75041fa..5ca6141 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -195,7 +195,7 @@ export class UserService { user.city, user.linkedin, user.github, - user.yearsOfExperience, + user.experience, user.description, user.jobTitle, user.jobCompany,