Skip to content

Commit

Permalink
feat(usuário): adição de data nascimento no registro dos jogadores - …
Browse files Browse the repository at this point in the history
…VLC-118 (#81)

* fix: ajustado tipagem da data

* feat: adicionado novo campo de data de nascimento
  • Loading branch information
CeruttiMaicon authored Nov 28, 2023
1 parent d3b1533 commit 0a147dd
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 8 deletions.
18 changes: 13 additions & 5 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function rolesCustom(): BelongsToMany
PermissionRegistrar::$pivotRole
);

if (! PermissionRegistrar::$teams) {
if (!PermissionRegistrar::$teams) {
return $relation;
}

Expand Down Expand Up @@ -206,8 +206,16 @@ public function updateOrNewInformation($args)
$attributes['rg'] = $args['rg'];
}

if (! empty($attributes)) {
if (! $this->information) {
if (isset($args['birthDate'])) {
$attributes['birth_date'] = $args['birthDate'];
}

if (isset($args['birth_date'])) {
$attributes['birth_date'] = $args['birth_date'];
}

if (!empty($attributes)) {
if (!$this->information) {
$this->information = $this->information()->create($attributes);
} else {
$this->information->fill($attributes);
Expand Down Expand Up @@ -308,7 +316,7 @@ public function scopeFilterPosition(Builder $query, array $args)
$query->when(
isset($args['filter']) &&
isset($args['filter']['positionsIds']) &&
! empty($args['filter']['positionsIds']),
!empty($args['filter']['positionsIds']),
function ($query) use ($args) {
$query->whereHas('positions', function ($query) use ($args) {
$query->filterIds($args['filter']['positionsIds']);
Expand All @@ -322,7 +330,7 @@ public function scopeFilterTeam(Builder $query, array $args)
$query->when(
isset($args['filter']) &&
isset($args['filter']['teamsIds']) &&
! empty($args['filter']['teamsIds']),
!empty($args['filter']['teamsIds']),
function ($query) use ($args) {
$query->whereHas('teams', function ($query) use ($args) {
$query->filterIds($args['filter']['teamsIds']);
Expand Down
1 change: 1 addition & 0 deletions app/Models/UserInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UserInformation extends Model
'cpf',
'phone',
'rg',
'birth_date',
];

public function user()
Expand Down
1 change: 1 addition & 0 deletions database/factories/UserInformationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function definition()
'cpf' => $this->faker->numberBetween(10000000000, 99999999999),
'rg' => $this->faker->numberBetween(100000000, 999999999),
'phone' => $this->faker->phoneNumber(),
'birth_date' => $this->faker->date(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->string('cpf')->nullable();
$table->string('phone')->nullable();
$table->string('rg')->nullable();
$table->date('birth_date')->nullable();
$table->timestamps();
$table->softDeletes();

Expand Down
4 changes: 2 additions & 2 deletions graphql/training/TrainingType.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type Training {
status: Boolean

"Training dateStart. Must contain a date greater than dateEnd. Is required. A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
dateStart: String @rename(attribute: "date_start")
dateStart: DateTime @rename(attribute: "date_start")

"Training dateEnd. Must contain a date less than dateStart. Is required. A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
dateEnd: String @rename(attribute: "date_end")
dateEnd: DateTime @rename(attribute: "date_end")

"Training description."
description: String
Expand Down
5 changes: 4 additions & 1 deletion graphql/user/UserInformationType.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type UserInformation {
id: ID!

"User ID."
user_id: Int!
userId: Int! @rename(attribute: "user_id")

"User relation."
user: User @belongsTo(relation: "user")
Expand All @@ -18,6 +18,9 @@ type UserInformation {
"Phone number."
phone: String

"Birth date. A date string with format `Y-m-d`, e.g. `2018-05-23`."
birthDate: Date @rename(attribute: "birth_date")

"Date created. A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
createdAt: DateTime! @rename(attribute: "created_at")

Expand Down
2 changes: 2 additions & 0 deletions graphql/user/UserMutation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extend type Mutation @guard {
cpf: String
rg: String
phone: String
birthDate: String
roleId: [Int!]!
positionId: [Int]
teamId: [Int]
Expand All @@ -22,6 +23,7 @@ extend type Mutation @guard {
cpf: String
rg: String
phone: String
birthDate: String
roleId: [Int!]!
positionId: [Int]
teamId: [Int]
Expand Down
40 changes: 40 additions & 0 deletions tests/Feature/GraphQL/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,26 @@ public static function userCreateProvider()
'hasTeam' => false,
'hasPermission' => true,
],
'create user with birth date, success' => [
[
'name' => $faker->name,
'email' => $faker->email,
'positionId' => [1],
'teamId' => [1],
'roleId' => [3],
'password' => $password,
'birthDate' => $faker->date(),
],
'type_message_error' => false,
'expected_message' => false,
'expected' => [
'data' => [
'userCreate' => self::$data,
],
],
'hasTeam' => false,
'hasPermission' => true,
],
'create user with 2 roles, success' => [
[
'name' => $faker->name,
Expand Down Expand Up @@ -854,6 +874,26 @@ public static function userEditProvider()
'hasTeam' => false,
'hasPermission' => true,
],
'edit user with birth date, success' => [
[
'name' => $faker->name,

'password' => $password,
'birthDate' => $faker->date(),
'positionId' => [1],
'teamId' => [1],
'roleId' => [2],
],
'type_message_error' => false,
'expected_message' => false,
'expected' => [
'data' => [
'userEdit' => self::$data,
],
],
'hasTeam' => false,
'hasPermission' => true,
],
'edit user with 2 roles, success' => [
[
'name' => $faker->name,
Expand Down

0 comments on commit 0a147dd

Please sign in to comment.