mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FIX/BE-US] adjustment purchase,closing hpp expedition,supplier filter flags
This commit is contained in:
@@ -47,6 +47,10 @@ func (s supplierService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("NonstockSuppliers.Nonstock.Flags")
|
||||
}
|
||||
|
||||
func (s supplierService) withListRelations(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("CreatedUser")
|
||||
}
|
||||
|
||||
func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Supplier, int64, error) {
|
||||
if err := s.Validate.Struct(params); err != nil {
|
||||
return nil, 0, err
|
||||
@@ -63,7 +67,7 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
|
||||
suppliers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||
db = s.withRelations(db)
|
||||
db = s.withListRelations(db)
|
||||
if params.Search != "" {
|
||||
return db.Where("name ILIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
@@ -72,7 +76,23 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
db = db.Where("category ILIKE ?", "%"+params.Category+"%")
|
||||
}
|
||||
|
||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||
if params.Flag != "" {
|
||||
flag := strings.ToUpper(params.Flag)
|
||||
db = db.Where(`
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM nonstock_suppliers nsup
|
||||
JOIN nonstocks n ON n.id = nsup.nonstock_id
|
||||
JOIN flags f ON f.flagable_id = n.id AND f.flagable_type = ?
|
||||
WHERE nsup.supplier_id = suppliers.id
|
||||
AND UPPER(f.name) = ?
|
||||
)`,
|
||||
entity.FlagableTypeNonstock,
|
||||
flag,
|
||||
)
|
||||
}
|
||||
|
||||
return db.Order("suppliers.created_at DESC").Order("suppliers.updated_at DESC")
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user