Skip to content

Commit

Permalink
exchanging address relationship with employee
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissone committed May 15, 2021
1 parent dfe6df7 commit 3446109
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 71 deletions.
3 changes: 2 additions & 1 deletion src/entities/IAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface IAddress {
district: string
city: string
state: string
employeeCpf: string
createdAt: Date
updatedAt: Date
employee?: IEmployee
employee: IEmployee
}
1 change: 0 additions & 1 deletion src/entities/IEmployee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface IEmployee {
role: string
access: number
companyCnpj?: string
addressId?: number
createdAt: Date
updatedAt: Date
company?: ICompany
Expand Down
11 changes: 9 additions & 2 deletions src/external/database/entities/AddressEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const AddressEntity = new EntitySchema<IAddress>({
type: String,
nullable: false
},
employeeCpf: {
name: 'employee_cpf',
type: String,
nullable: false
},
createdAt: {
name: 'created_at',
type: 'datetime2',
Expand All @@ -40,9 +45,11 @@ export const AddressEntity = new EntitySchema<IAddress>({
relations: {
employee: {
type: 'one-to-one',
joinColumn: ({
name: 'employee_cpf'
}),
target: 'employee',
inverseSide: 'address',
nullable: true
nullable: false
}
}
})
9 changes: 1 addition & 8 deletions src/external/database/entities/EmployeeEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export const EmployeeEntity = new EntitySchema<IEmployee>({
type: String,
nullable: true,
},
addressId: {
name: 'address_id',
type: Number,
nullable: true,
},
createdAt: {
name: 'created_at',
type: 'datetime2',
Expand All @@ -81,10 +76,8 @@ export const EmployeeEntity = new EntitySchema<IEmployee>({
},
address: {
type: 'one-to-one',
joinColumn: ({
name: 'address_id'
}),
target: 'address',
inverseSide: 'employee',
nullable: true
},
absences: {
Expand Down
75 changes: 16 additions & 59 deletions src/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,52 +117,21 @@
"schema": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"district": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
}
"cnpj": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"street": {
"type": "string"
},
"district": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"createdAt": {
"type": "date-time",
"example": "2021-01-30T08:30:00Z"
},
"updatedAt": {
"type": "date-time",
"example": "2021-01-30T08:30:00Z"
}
}
"$ref": "#/definitions/Company"
}
},
"500": {
Expand Down Expand Up @@ -263,6 +232,9 @@
},
"state": {
"type": "string"
},
"employeeCpf": {
"type": "string"
}
}
}
Expand Down Expand Up @@ -397,9 +369,6 @@
},
"companyCpf": {
"type": "string"
},
"addressId": {
"type": "integer"
}
}
}
Expand Down Expand Up @@ -482,9 +451,6 @@
"companyCpf": {
"type": "string"
},
"addressId": {
"type": "integer"
},
"createdAt": {
"type": "date-time",
"example": "2021-01-30T08:30:00Z"
Expand Down Expand Up @@ -883,9 +849,6 @@
"companyCpf": {
"type": "string"
},
"addressId": {
"type": "integer"
},
"createdAt": {
"type": "date-time",
"example": "2021-01-30T08:30:00Z"
Expand Down Expand Up @@ -927,6 +890,9 @@
"city": {
"type": "string"
},
"employeeCpf": {
"type": "string"
},
"state": {
"type": "string"
},
Expand All @@ -947,19 +913,10 @@
"Company": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"street": {
"type": "string"
},
"district": {
"type": "string"
},
"city": {
"cnpj": {
"type": "string"
},
"state": {
"name": {
"type": "string"
},
"createdAt": {
Expand Down

0 comments on commit 3446109

Please sign in to comment.