mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
feat(BE-281): unique uniformity weeks
This commit is contained in:
@@ -605,13 +605,13 @@ func (s uniformityService) UpdateOne(c *fiber.Ctx, req *validation.Update, id ui
|
||||
}
|
||||
|
||||
func (s *uniformityService) ensureUniqueUniformity(ctx context.Context, id uint, projectFlockKandangID uint, week int, uniformDate *time.Time) error {
|
||||
if projectFlockKandangID == 0 || week == 0 || uniformDate == nil || uniformDate.IsZero() {
|
||||
if projectFlockKandangID == 0 || week == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := s.Repository.DB().WithContext(ctx).
|
||||
Model(&entity.ProjectFlockKandangUniformity{}).
|
||||
Where("project_flock_kandang_id = ? AND week = ? AND uniform_date = ?", projectFlockKandangID, week, *uniformDate)
|
||||
Where("project_flock_kandang_id = ? AND week = ?", projectFlockKandangID, week)
|
||||
if id != 0 {
|
||||
query = query.Where("id <> ?", id)
|
||||
}
|
||||
@@ -621,7 +621,7 @@ func (s *uniformityService) ensureUniqueUniformity(ctx context.Context, id uint,
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to validate uniformity uniqueness")
|
||||
}
|
||||
if count > 0 {
|
||||
return fiber.NewError(fiber.StatusConflict, "Uniformity already exists for the same project flock kandang, week, and date")
|
||||
return fiber.NewError(fiber.StatusConflict, "Uniformity already exists for the same project flock kandang and week")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user