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
CP - Planta
backend
Commits
4ab7ee5c
There was a problem fetching linked pipelines.
Commit
4ab7ee5c
authored
5 months ago
by
Rodrigo Oliveira Rosa
Browse files
Options
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into feature/batchs-expose
parents
c4ab58a0
ba9f29a7
Pipeline
#19360
passed with stages
in 6 minutes and 5 seconds
Changes
13
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
prisma/schema.prisma
+15
-15
prisma/schema.prisma
scripts/db_create.sql
+1
-1
scripts/db_create.sql
scripts/db_insert.sql
+1
-1
scripts/db_insert.sql
src/core/production/dto/create-production.dto.ts
+1
-1
src/core/production/dto/create-production.dto.ts
src/core/production/dto/production.schema.dto.ts
+2
-2
src/core/production/dto/production.schema.dto.ts
src/core/production/dto/response.production.dto.ts
+1
-1
src/core/production/dto/response.production.dto.ts
src/core/production/dto/update-production.dto.ts
+1
-1
src/core/production/dto/update-production.dto.ts
src/core/production/production.controller.ts
+3
-1
src/core/production/production.controller.ts
src/core/production/production.repository.ts
+3
-2
src/core/production/production.repository.ts
src/core/production/production.service.ts
+10
-9
src/core/production/production.service.ts
src/core/products/products.controller.ts
+112
-2
src/core/products/products.controller.ts
src/core/products/products.repository.ts
+31
-1
src/core/products/products.repository.ts
src/core/products/products.service.ts
+16
-0
src/core/products/products.service.ts
with
197 additions
and
37 deletions
+197
-37
prisma/schema.prisma
View file @
4ab7ee5c
...
...
@@ -249,21 +249,21 @@ model production_orders {
//
//
produto
final
atrelado
na
ordem
de
produ
çã
o
model
production_orders_items
{
id
Int
@
id
@
default
(
autoincrement
())
production_order_id
Int
sequence
Int
final_product_id
Int
prodution_quantity_estimated
Float
production_quantity_real
Float
production_quantity_loss
Float
lote
String
?
@
db
.
VarChar
(
255
)
lote_expiration
DateTime
?
created_at
DateTime
@
default
(
now
())
@
db
.
Timestamp
(
6
)
updated_at
DateTime
@
default
(
now
())
@
db
.
Timestamp
(
6
)
created_by
String
?
updated_by
String
?
final_product_made
products
@
relation
(
"final_product_made"
,
fields
:
[
final_product_id
],
references
:
[
id
],
onDelete
:
Cascade
,
map
:
"final_product_fkey"
)
production_order
production_orders
@
relation
(
fields
:
[
production_order_id
],
references
:
[
id
],
onDelete
:
Cascade
)
id
Int
@
id
@
default
(
autoincrement
())
production_order_id
Int
sequence
Int
final_product_id
Int
produ
c
tion_quantity_estimated
Float
production_quantity_real
Float
production_quantity_loss
Float
lote
String
?
@
db
.
VarChar
(
255
)
lote_expiration
DateTime
?
created_at
DateTime
@
default
(
now
())
@
db
.
Timestamp
(
6
)
updated_at
DateTime
@
default
(
now
())
@
db
.
Timestamp
(
6
)
created_by
String
?
updated_by
String
?
final_product_made
products
@
relation
(
"final_product_made"
,
fields
:
[
final_product_id
],
references
:
[
id
],
onDelete
:
Cascade
,
map
:
"final_product_fkey"
)
production_order
production_orders
@
relation
(
fields
:
[
production_order_id
],
references
:
[
id
],
onDelete
:
Cascade
)
}
//
Status
da
ordem
de
produ
çã
o
-
CRIADO
,
AGENDADO
,
ABERTO
,
EM
ANDAMENTO
,
FINALIZADO
,
PARADO
,
CANCELADO
...
...
This diff is collapsed.
Click to expand it.
scripts/db_create.sql
View file @
4ab7ee5c
...
...
@@ -185,7 +185,7 @@ CREATE TABLE "production_orders_items" (
"production_order_id"
INTEGER
NOT
NULL
,
"sequence"
INTEGER
NOT
NULL
,
"final_product_id"
INTEGER
NOT
NULL
,
"prodution_quantity_estimated"
DOUBLE
PRECISION
NOT
NULL
,
"produ
c
tion_quantity_estimated"
DOUBLE
PRECISION
NOT
NULL
,
"production_quantity_real"
DOUBLE
PRECISION
NOT
NULL
,
"production_quantity_loss"
DOUBLE
PRECISION
NOT
NULL
,
"lote"
VARCHAR
(
255
),
...
...
This diff is collapsed.
Click to expand it.
scripts/db_insert.sql
View file @
4ab7ee5c
...
...
@@ -318,7 +318,7 @@ VALUES
(
5
,
'Production E'
,
'2024-12-31 23:59:59'
,
'OPEN'
);
-- Insert into production_orders_items
INSERT
INTO
"production_orders_items"
(
"production_order_id"
,
"sequence"
,
"final_product_id"
,
"prodution_quantity_estimated"
,
"production_quantity_real"
,
"production_quantity_loss"
,
"lote"
,
"lote_expiration"
)
INSERT
INTO
"production_orders_items"
(
"production_order_id"
,
"sequence"
,
"final_product_id"
,
"produ
c
tion_quantity_estimated"
,
"production_quantity_real"
,
"production_quantity_loss"
,
"lote"
,
"lote_expiration"
)
VALUES
(
1
,
1
,
10
,
1000
.
0
,
950
.
0
,
50
.
0
,
'LoteTY123'
,
'2024-12-31 23:59:59'
),
(
2
,
2
,
11
,
2000
.
0
,
1900
.
0
,
100
.
0
,
'LoteER56'
,
'2024-12-15 23:59:59'
),
...
...
This diff is collapsed.
Click to expand it.
src/core/production/dto/create-production.dto.ts
View file @
4ab7ee5c
...
...
@@ -15,7 +15,7 @@ export class CreateProductionItemsDto {
readonly
production_order_id
:
number
;
readonly
sequence
:
number
;
readonly
final_product_id
:
number
;
readonly
prodution_quantity_estimated
:
number
;
readonly
produ
c
tion_quantity_estimated
:
number
;
readonly
production_quantity_real
:
number
;
readonly
production_quantity_loss
:
number
;
readonly
lote
:
string
;
...
...
This diff is collapsed.
Click to expand it.
src/core/production/dto/production.schema.dto.ts
View file @
4ab7ee5c
...
...
@@ -21,7 +21,7 @@ export const CreateProductionSchema = z.object({
.
number
()
.
int
()
.
positive
(
'
Final product is required
'
),
prodution_quantity_estimated
:
z
produ
c
tion_quantity_estimated
:
z
.
number
()
.
int
()
.
positive
(
'
Estimated quantity is required
'
),
...
...
@@ -53,7 +53,7 @@ export const UpdateProductionSchema = z.object({
production_items
:
z
.
array
(
z
.
object
({
prodution_quantity_estimated
:
z
produ
c
tion_quantity_estimated
:
z
.
number
()
.
int
()
.
positive
(
'
Estimated quantity is required
'
)
...
...
This diff is collapsed.
Click to expand it.
src/core/production/dto/response.production.dto.ts
View file @
4ab7ee5c
...
...
@@ -17,7 +17,7 @@ export class ResponseProductionItem {
production_order_id
:
number
;
sequence
:
number
;
final_product_id
:
number
;
prodution_quantity_estimated
:
number
;
produ
c
tion_quantity_estimated
:
number
;
production_quantity_real
:
number
;
production_quantity_loss
:
number
;
lote
:
string
;
...
...
This diff is collapsed.
Click to expand it.
src/core/production/dto/update-production.dto.ts
View file @
4ab7ee5c
...
...
@@ -10,7 +10,7 @@ export class UpdateProductionDto {
}
export
class
UpdateProductionItemsDto
{
readonly
prodution_quantity_estimated
:
number
;
readonly
produ
c
tion_quantity_estimated
:
number
;
readonly
production_quantity_real
:
number
;
readonly
production_quantity_loss
:
number
;
readonly
updated_at
:
Date
;
...
...
This diff is collapsed.
Click to expand it.
src/core/production/production.controller.ts
View file @
4ab7ee5c
...
...
@@ -40,6 +40,7 @@ export class ProductionController {
'
number
'
,
'
description
'
,
'
production_date
'
,
'
production_line
'
,
'
Production_Status
'
,
'
created_by
'
,
'
updated_by
'
...
...
@@ -51,6 +52,7 @@ export class ProductionController {
'
number
'
,
'
description
'
,
'
production_date
'
,
'
production_line
'
,
'
Production_Status
'
,
'
created_by
'
,
'
updated_by
'
...
...
@@ -75,7 +77,7 @@ export class ProductionController {
// production_order_id: item.production_order_id,
// sequence: item.sequence,
// final_product_id: item.final_product_id,
// prodution_quantity_estimated: item.prodution_quantity_estimated,
// produ
c
tion_quantity_estimated: item.produ
c
tion_quantity_estimated,
// production_quantity_real: item.production_quantity_real,
// production_quantity_loss: item.production_quantity_loss,
// lote: item.lote,
...
...
This diff is collapsed.
Click to expand it.
src/core/production/production.repository.ts
View file @
4ab7ee5c
...
...
@@ -47,6 +47,7 @@ export class ProductionRepository {
'
number
'
,
'
description
'
,
'
production_date
'
,
'
production_line
'
,
'
Production_Status
'
,
'
created_by
'
,
'
updated_by
'
...
...
@@ -84,7 +85,7 @@ export class ProductionRepository {
production_order_id
:
true
,
sequence
:
true
,
final_product_id
:
true
,
prodution_quantity_estimated
:
true
,
produ
c
tion_quantity_estimated
:
true
,
production_quantity_real
:
true
,
production_quantity_loss
:
true
,
lote
:
true
,
...
...
@@ -117,7 +118,7 @@ export class ProductionRepository {
description
:
true
}
},
prodution_quantity_estimated
:
true
,
produ
c
tion_quantity_estimated
:
true
,
production_quantity_real
:
true
,
production_quantity_loss
:
true
,
lote
:
true
,
...
...
This diff is collapsed.
Click to expand it.
src/core/production/production.service.ts
View file @
4ab7ee5c
...
...
@@ -26,10 +26,10 @@ export class ProductionService {
production_order_id
:
production
.
id
,
sequence
:
sequence
,
final_product_id
:
item
.
final_product_id
,
prodution_quantity_estimated
:
item
.
prodution_quantity_estimated
,
produ
c
tion_quantity_estimated
:
item
.
produ
c
tion_quantity_estimated
,
production_quantity_real
:
item
.
production_quantity_real
,
production_quantity_loss
:
item
.
prodution_quantity_estimated
-
item
.
production_quantity_real
,
item
.
produ
c
tion_quantity_estimated
-
item
.
production_quantity_real
,
lote
:
item
.
lote
,
lote_expiration
:
item
.
lote_expiration
,
created_at
:
new
Date
(),
...
...
@@ -100,13 +100,14 @@ export class ProductionService {
item
.
production_order_id
,
{
final_product_id
:
item
.
final_product_id
,
prodution_quantity_estimated
:
item
.
prodution_quantity_estimated
??
undefined
,
produ
c
tion_quantity_estimated
:
item
.
produ
c
tion_quantity_estimated
??
undefined
,
production_quantity_real
:
item
.
production_quantity_real
??
undefined
,
production_quantity_loss
:
item
.
prodution_quantity_estimated
&&
item
.
production_quantity_real
?
item
.
prodution_quantity_estimated
-
item
.
production_quantity_estimated
&&
item
.
production_quantity_real
?
item
.
production_quantity_estimated
-
item
.
production_quantity_real
:
undefined
,
updated_at
:
new
Date
(),
...
...
@@ -120,11 +121,11 @@ export class ProductionService {
production_order_id
:
id
,
sequence
:
sequence
,
final_product_id
:
item
.
final_product_id
!
,
prodution_quantity_estimated
:
item
.
prodution_quantity_estimated
!
,
produ
c
tion_quantity_estimated
:
item
.
produ
c
tion_quantity_estimated
!
,
production_quantity_real
:
item
.
production_quantity_real
!
,
production_quantity_loss
:
item
.
prodution_quantity_estimated
&&
item
.
production_quantity_real
?
item
.
prodution_quantity_estimated
-
item
.
produ
c
tion_quantity_estimated
&&
item
.
production_quantity_real
?
item
.
produ
c
tion_quantity_estimated
-
item
.
production_quantity_real
:
0
,
lote
:
item
.
lote
!
,
...
...
This diff is collapsed.
Click to expand it.
src/core/products/products.controller.ts
View file @
4ab7ee5c
...
...
@@ -172,6 +172,62 @@ export class ProductsController {
}
@
Get
()
@
ApiQuery
({
name
:
'
orderBy
'
,
required
:
false
,
description
:
'
Field to order by. Valid fields: id, description, code, sku, origin, category_id, group_id, supplier_id
'
,
enum
:
[
'
id
'
,
'
description
'
,
'
code
'
,
'
sku
'
,
'
origin
'
,
'
category_id
'
,
'
supplier_id
'
,
'
group_id
'
]
})
async
findAll
(
@
Query
(
'
orderBy
'
)
orderBy
:
string
=
'
id
'
):
Promise
<
ResponseProductsDto
[]
>
{
const
validOrderFields
=
[
'
id
'
,
'
description
'
,
'
code
'
,
'
sku
'
,
'
origin
'
,
'
category_id
'
,
'
group_id
'
,
'
supplier_id
'
];
if
(
!
validOrderFields
.
includes
(
orderBy
))
{
throw
new
BadRequestException
(
`Invalid order field:
${
orderBy
}
`
);
}
const
products
=
await
this
.
productsService
.
findAll
(
orderBy
);
return
products
.
map
(
product
=>
({
id
:
product
.
id
,
description
:
product
.
description
,
code
:
product
.
code
,
sku
:
product
.
sku
,
origin
:
product
.
origin
as
Origin
,
unit_measure
:
product
.
unit_measure
as
Unit_Measure
,
category_id
:
product
.
category_id
,
group_id
:
product
.
group_id
,
supplier_id
:
product
.
supplier_id
,
nutritional_info
:
typeof
product
.
nutritional_info
===
'
string
'
?
JSON
.
parse
(
product
.
nutritional_info
)
:
product
.
nutritional_info
,
active
:
product
.
active
,
created_at
:
product
.
created_at
,
updated_at
:
product
.
updated_at
}));
}
@
Get
(
'
made
'
)
@
ApiQuery
({
name
:
'
orderBy
'
,
required
:
false
,
...
...
@@ -187,7 +243,7 @@ export class ProductsController {
'
supplier_id
'
]
})
async
find
All
(
async
find
Made
(
@
Query
(
'
orderBy
'
)
orderBy
:
string
=
'
id
'
):
Promise
<
ResponseProductsDto
[]
>
{
const
validOrderFields
=
[
...
...
@@ -203,8 +259,62 @@ export class ProductsController {
if
(
!
validOrderFields
.
includes
(
orderBy
))
{
throw
new
BadRequestException
(
`Invalid order field:
${
orderBy
}
`
);
}
const
origin
=
Origin
.
MADE
;
const
products
=
await
this
.
productsService
.
findByOrigin
(
orderBy
,
origin
);
return
products
.
map
(
product
=>
({
id
:
product
.
id
,
description
:
product
.
description
,
code
:
product
.
code
,
sku
:
product
.
sku
,
origin
:
product
.
origin
as
Origin
,
unit_measure
:
product
.
unit_measure
as
Unit_Measure
,
category_id
:
product
.
category_id
,
group_id
:
product
.
group_id
,
supplier_id
:
product
.
supplier_id
,
nutritional_info
:
typeof
product
.
nutritional_info
===
'
string
'
?
JSON
.
parse
(
product
.
nutritional_info
)
:
product
.
nutritional_info
,
active
:
product
.
active
,
created_at
:
product
.
created_at
,
updated_at
:
product
.
updated_at
}));
}
const
products
=
await
this
.
productsService
.
findAll
(
orderBy
);
@
Get
(
'
raw-material
'
)
@
ApiQuery
({
name
:
'
orderBy
'
,
required
:
false
,
description
:
'
Field to order by. Valid fields: id, description, code, sku, category_id, group_id, supplier_id
'
,
enum
:
[
'
id
'
,
'
description
'
,
'
code
'
,
'
sku
'
,
'
category_id
'
,
'
group_id
'
,
'
supplier_id
'
]
})
async
findRaw
(
@
Query
(
'
orderBy
'
)
orderBy
:
string
=
'
id
'
):
Promise
<
ResponseProductsDto
[]
>
{
const
validOrderFields
=
[
'
id
'
,
'
description
'
,
'
code
'
,
'
sku
'
,
'
category_id
'
,
'
group_id
'
,
'
supplier_id
'
];
if
(
!
validOrderFields
.
includes
(
orderBy
))
{
throw
new
BadRequestException
(
`Invalid order field:
${
orderBy
}
`
);
}
const
origin
=
Origin
.
RAW_MATERIAL
;
const
products
=
await
this
.
productsService
.
findByOrigin
(
orderBy
,
origin
);
return
products
.
map
(
product
=>
({
id
:
product
.
id
,
description
:
product
.
description
,
...
...
This diff is collapsed.
Click to expand it.
src/core/products/products.repository.ts
View file @
4ab7ee5c
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
PrismaService
}
from
'
src/database/prisma/prisma.service
'
;
import
{
products
,
Prisma
}
from
'
@prisma/client
'
;
import
{
products
,
Prisma
,
Origin
}
from
'
@prisma/client
'
;
@
Injectable
()
export
class
ProductsRepository
{
...
...
@@ -41,6 +41,36 @@ export class ProductsRepository {
return
result
;
}
async
findByOrigin
(
orderBy
:
string
,
origin
:
string
):
Promise
<
products
[]
>
{
const
validOrderFields
=
[
'
id
'
,
'
code
'
,
'
description
'
,
'
sku
'
,
'
unit_measure
'
,
'
category_id
'
,
'
group_id
'
];
if
(
!
validOrderFields
.
includes
(
orderBy
))
{
throw
new
Error
(
'
Invalid order field
'
);
}
if
(
origin
===
Origin
.
MADE
)
{
const
result
=
await
this
.
prisma
.
products
.
findMany
({
where
:
{
active
:
true
,
origin
:
origin
},
orderBy
:
{
[
orderBy
]:
'
asc
'
}
});
return
result
;
}
const
result
=
await
this
.
prisma
.
products
.
findMany
({
where
:
{
active
:
true
,
origin
:
{
not
:
'
MADE
'
}
},
orderBy
:
{
[
orderBy
]:
'
asc
'
}
});
return
result
;
}
async
findById
(
id
:
number
):
Promise
<
products
|
null
>
{
const
product
=
this
.
prisma
.
products
.
findUnique
({
where
:
{
id
}
...
...
This diff is collapsed.
Click to expand it.
src/core/products/products.service.ts
View file @
4ab7ee5c
...
...
@@ -42,6 +42,22 @@ export class ProductsService {
return
findedProducts
.
map
(
product
=>
this
.
formatProductDate
(
product
));
}
async
findByOrigin
(
orderBy
:
string
,
origin
:
string
):
Promise
<
(
Omit
<
products
,
'
created_at
'
|
'
updated_at
'
>
&
{
created_at
:
string
;
updated_at
:
string
;
})[]
>
{
const
findedProducts
=
await
this
.
productsRepository
.
findByOrigin
(
orderBy
,
origin
);
return
findedProducts
.
map
(
product
=>
this
.
formatProductDate
(
product
));
}
async
findById
(
id
:
number
)
{
const
product
=
await
this
.
isValid
(
id
);
return
this
.
formatProductDate
(
product
);
...
...
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