fix:(equipe) ajustado cadastro por regiao no acesso correspondente
This commit is contained in:
parent
c5f1c40243
commit
e86bd0a570
3 changed files with 28 additions and 7 deletions
|
|
@ -61,6 +61,7 @@ type registerRequest struct {
|
|||
Role string `json:"role" binding:"required"`
|
||||
EmpresaID string `json:"empresa_id"`
|
||||
TipoProfissional string `json:"tipo_profissional"` // New field
|
||||
Regiao string `json:"regiao"` // Optional: for AdminCreateUser override
|
||||
}
|
||||
|
||||
// Register godoc
|
||||
|
|
@ -513,9 +514,12 @@ func (h *Handler) AdminCreateUser(c *gin.Context) {
|
|||
|
||||
// Just reuse the request struct but call AdminCreateUser service
|
||||
regiao := c.GetString("regiao")
|
||||
// If Admin doesn't specify region in header?
|
||||
// Maybe Admin API should accept region in body?
|
||||
// For now use header context.
|
||||
|
||||
// If Admin explicitly sends regiao in body, use it (override context)
|
||||
if req.Regiao != "" {
|
||||
regiao = req.Regiao
|
||||
}
|
||||
|
||||
if regiao == "" {
|
||||
// Fallback or Error? Admin creation usually implies target region.
|
||||
// Let's assume header is present or default.
|
||||
|
|
|
|||
|
|
@ -235,13 +235,29 @@ func (s *Service) AdminCreateUser(ctx context.Context, email, senha, role, nome,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if ativo {
|
||||
// Approve user immediately
|
||||
err = s.ApproveUser(ctx, uuid.UUID(user.ID.Bytes).String())
|
||||
// Update Regions if provided
|
||||
if regiao != "" {
|
||||
err = s.queries.UpdateUsuarioRegions(ctx, generated.UpdateUsuarioRegionsParams{
|
||||
ID: pgtype.UUID{Bytes: user.ID.Bytes, Valid: true},
|
||||
RegioesPermitidas: []string{regiao},
|
||||
})
|
||||
if err != nil {
|
||||
_ = s.queries.DeleteUsuario(ctx, user.ID)
|
||||
return nil, err
|
||||
}
|
||||
// Update the user struct in memory too (important for the return value?)
|
||||
// user.RegioesPermitidas = []string{regiao} // Generated struct might differ, but return value is pointer to user.
|
||||
// Since we return &user, and user is local struct from CreateUsuario, it has empty RegioesPermitidas.
|
||||
// It's better to manually updating it if downstream depends on it, but usually ID/Email is enough.
|
||||
}
|
||||
|
||||
if ativo {
|
||||
// Approve user immediately (already active=true by default in DB? No, default false)
|
||||
err = s.ApproveUser(ctx, uuid.UUID(user.ID.Bytes).String())
|
||||
if err != nil {
|
||||
_ = s.queries.DeleteUsuario(ctx, user.ID)
|
||||
return nil, err
|
||||
}
|
||||
// Refresh user object to reflect changes if needed, but ID and Email are same.
|
||||
user.Ativo = true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ export const ProfessionalModal: React.FC<ProfessionalModalProps> = ({
|
|||
role: roles.find(r => r.id === formData.funcao_profissional_id)?.nome.toUpperCase().includes("PESQUISA") ? "RESEARCHER" : "PHOTOGRAPHER",
|
||||
tipo_profissional: roles.find(r => r.id === formData.funcao_profissional_id)?.nome || "",
|
||||
ativo: true,
|
||||
regiao: formData.regiao, // Pass selected region to creating user
|
||||
}, token);
|
||||
|
||||
if (createRes.error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue