# Términos y Condiciones - [setTermsAndConditions]

## 🧾 **Descripción**

*Registra la aceptación de los Términos y Condiciones por parte del usuario logueado en la aplicación.*  
*El proceso localiza al empleado asociado al `user_id` (email del usuario) y actualiza los campos:*

- `<span style="color: rgb(224, 62, 45);"><strong>terminos_y_condiciones_app = 1</strong></span>`
- **<span style="color: rgb(224, 62, 45);">`fecha_terminos_y_condiciones = fecha/hora actual`</span>**

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fset-terms-and-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /<span class="hljs-built_in">set-terms</span><span class="hljs-operator">-and</span><span class="hljs-literal">-conditions</span>`**</span></div></div>> La ruta exacta depende de cómo esté configurado en tus <span style="color: rgb(224, 62, 45);">**`routes/api.php`**</span>.

---

# 🔐 **Seguridad**

- No requiere token explícito aquí, pero el backend usa <span style="color: rgb(224, 62, 45);">**`apiService`**</span>, que probablemente **sí exige autenticación** hacia ERPNext.
- Se recomienda proteger este endpoint detrás de autenticación de la app.

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22email_logued%22%3A-%22s" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos requeridos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1248" data-start="991"><thead data-end="1043" data-start="991"><tr data-end="1043" data-start="991"><th data-col-size="sm" data-end="1007" data-start="991">Campo</th><th data-col-size="sm" data-end="1016" data-start="1007">Tipo</th><th data-col-size="sm" data-end="1028" data-start="1016">Requerido</th><th data-col-size="lg" data-end="1043" data-start="1028">Descripción</th></tr></thead><tbody data-end="1248" data-start="1097"><tr data-end="1248" data-start="1097"><td data-col-size="sm" data-end="1113" data-start="1097">email\_logued</td><td data-col-size="sm" data-end="1122" data-start="1113">string</td><td data-col-size="sm" data-end="1134" data-start="1122">Sí</td><td data-col-size="lg" data-end="1248" data-start="1134">Email del usuario con el que inició sesión en la app. Este email debe coincidir con el `user_id` del Employee.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

## ✔️ 200 – Términos aceptados correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Terminos y Condiciones Aceptadas Correctamente"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 400 – Falta el email

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es necesario el email con el que ha entrado a la app"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 404 – No existe Employee asociado al usuario

**Incluye ambos casos del código:**

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al traer el empleado asociado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 500 – Error al actualizar Employee

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al aceptar terminos y condiciones"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuesta ERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 500 – Error inesperado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--11"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error en el servicio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica Interna**

1. **Validación inicial**  
    Si <span style="color: rgb(224, 62, 45);">**`email_logued`**</span> viene vacío → error
2. **Buscar Employee asociado al usuario**  
    **Consulta en ERP:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`GET Employee?limit=None  &fields=[<span class="hljs-string">"name"</span>,<span class="hljs-string">"terminos_y_condiciones_app"</span>]  &filters=<span class="hljs-string">[["user_id","=", email_logued]]</span>`</td></tr></tbody></table>
    
    </div></div>
3. **Manejo de errores:**
    
    
    - Respuesta sin `<span style="color: rgb(224, 62, 45);"><strong>data</strong></span>`
    - Array vacío
4. **Actualizar Employee**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`PUT Employee/{employee_name}{  <span class="hljs-string">"terminos_y_condiciones_app"</span>: <span class="hljs-number">1</span>,  <span class="hljs-string">"fecha_terminos_y_condiciones"</span>: <span class="hljs-string">"Y-m-d H:i:s"</span>}`</td></tr></tbody></table>
    
    </div></div>
5. **Si el response incluye** `"<span style="color: rgb(224, 62, 45);"><strong>data</strong></span>"` → éxito  
    Si no → error

---

# 📚 **Schemas**

### Request Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22email_logued%22%3A-%22s-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--15"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"object (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de Uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/set-terms-and-conditions \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"email_logued":"user@example.com"}'</span>`</td></tr></tbody></table>

</div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>