func (r *RoleRepo) UpdateByID(id int, role *domain.Role, context usecases.QueryContext) (*domain.Role, error) { query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations) if err != nil { return nil, internalerrors.DatabaseError } dbName := utils.ToDBName("roles") oldRole := &domain.Role{} err = query.Where(dbName+".id = ?", id).First(oldRole).Error if err != nil { if strings.Contains(err.Error(), "record not found") { return nil, internalerrors.NotFound } return nil, internalerrors.DatabaseError } role.ID = oldRole.ID role.CreatedAt = oldRole.CreatedAt err = r.store.GetDB().Save(&role).Error if err != nil { if strings.Contains(err.Error(), "constraint") { return nil, internalerrors.NewViolatedConstraint(err.Error()) } return nil, internalerrors.DatabaseError } return role, nil }
func (i *RoleInter) scopeModel(role *domain.Role) error { role.CreatedAt = time.Time{} role.UpdatedAt = time.Time{} role.RoleMappings = []domain.RoleMapping{} role.AclMappings = []domain.AclMapping{} return nil }