Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Excedentes
excedentes-backend
Commits
ec78d748
Commit
ec78d748
authored
1 year ago
by
Gabriel Fernando Giaretta
Browse files
Options
Download
Email Patches
Plain Diff
adicionadas timestamps e boolean deleted detalhados no banco
parent
a2bb2df9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/api/products/domain/products.service.ts
+14
-5
src/api/products/domain/products.service.ts
src/api/products/dto/createProductDto.ts
+2
-2
src/api/products/dto/createProductDto.ts
src/api/products/product.entity.ts
+13
-1
src/api/products/product.entity.ts
src/api/products/products.controller.ts
+14
-5
src/api/products/products.controller.ts
with
43 additions
and
13 deletions
+43
-13
src/api/products/domain/products.service.ts
View file @
ec78d748
...
...
@@ -27,6 +27,9 @@ export class ProductsService {
async
create
(
product
:
CreateProductDto
):
Promise
<
ProductEntity
>
{
const
newProduct
=
this
.
productRepository
.
create
(
product
);
newProduct
.
createdAt
=
new
Date
(
Date
.
now
());
newProduct
.
updatedAt
=
new
Date
(
Date
.
now
());
newProduct
.
deleted
=
false
;
return
await
this
.
productRepository
.
save
(
newProduct
);
}
...
...
@@ -43,13 +46,19 @@ export class ProductsService {
`Product with ID
${
id
}
not found`
,
);
}
entity
.
updatedAt
=
new
Date
(
Date
.
now
());
return
await
this
.
productRepository
.
save
(
entity
);
}
async
delete
(
id
:
number
)
{
const
result
=
await
this
.
productRepository
.
delete
(
id
);
if
(
result
.
affected
===
0
)
{
throw
new
NotFoundException
(
`Product with ID
${
id
}
not found`
);
async
delete
(
id_alimento
:
number
):
Promise
<
ProductEntity
>
{
const
product
=
await
this
.
productRepository
.
findOne
({
where
:
{
id_alimento
}
});
if
(
!
product
)
{
throw
new
NotFoundException
(
`Product with ID
${
id_alimento
}
not found`
,
);
}
product
.
deletedAt
=
new
Date
(
Date
.
now
());
product
.
deleted
=
true
;
return
await
this
.
productRepository
.
save
(
product
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/api/products/dto/createProductDto.ts
View file @
ec78d748
...
...
@@ -10,8 +10,8 @@ import {
export
class
CreateProductDto
{
@
ApiProperty
({
example
:
'
1
2345678901234
'
,
description
:
'
ID da empresa
'
,
example
:
'
1
'
,
description
:
'
ID da empresa
(temporario; será determinado pela empresa autenticada)
'
,
required
:
true
,
})
@
IsNotEmpty
({
message
:
'
Empresa nao pode ser vazia
'
})
...
...
This diff is collapsed.
Click to expand it.
src/api/products/product.entity.ts
View file @
ec78d748
import
{
BaseEntity
,
Column
,
Entity
,
PrimaryGeneratedColumn
}
from
'
typeorm
'
;
import
{
BaseEntity
,
Column
,
Entity
,
PrimaryGeneratedColumn
,
Timestamp
}
from
'
typeorm
'
;
@
Entity
(
'
alimentos
'
)
export
class
ProductEntity
extends
BaseEntity
{
...
...
@@ -36,4 +36,16 @@ export class ProductEntity extends BaseEntity {
@
Column
({
length
:
13
,
nullable
:
true
})
cod_barras
:
string
;
@
Column
(
'
timestamp
'
)
createdAt
:
Date
;
@
Column
(
'
timestamp
'
)
updatedAt
:
Date
;
@
Column
(
'
timestamp
'
,
{
nullable
:
true
})
deletedAt
:
Date
;
@
Column
({
type
:
'
bool
'
,
nullable
:
true
})
deleted
:
boolean
;
}
This diff is collapsed.
Click to expand it.
src/api/products/products.controller.ts
View file @
ec78d748
...
...
@@ -37,6 +37,12 @@ export class ProductsController {
}
@
ApiOperation
({
summary
:
'
Atualiza uma produto
'
})
@
ApiParam
({
name
:
'
id
'
,
type
:
Number
,
required
:
true
,
description
:
'
ID do Produto
'
,
})
@
Put
(
'
:id
'
)
async
update
(@
Param
(
'
id
'
)
id
:
number
,
@
Body
()
product
:
CreateProductDto
)
{
try
{
...
...
@@ -58,16 +64,19 @@ export class ProductsController {
}
@
ApiOperation
({
summary
:
'
Procura um produto por id
'
})
@
ApiParam
({
name
:
'
id
'
,
type
:
Number
,
required
:
true
,
description
:
'
ID do Produto
'
,
})
@
Get
(
'
:id
'
)
async
findOne
(@
Param
(
'
id
'
)
id
:
number
)
{
return
this
.
productService
.
findOne
(
id
);
}
@
ApiOperation
({
summary
:
'
Deleta um produto
'
})
@
ApiResponse
({
status
:
200
,
description
:
'
Produto deletado com sucesso.
'
,
})
@
ApiOperation
({
summary
:
'
Marca um produto como deletado
'
})
@
ApiResponse
({
status
:
200
,
description
:
'
Produto marcado como deletado com sucesso
'
})
@
ApiParam
({
name
:
'
id
'
,
type
:
Number
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help