Fix CORS, timezone y configuraciones para producción
- Actualizar middleware CORS para permitir orígenes de producción y apps móviles - Cambiar timezone de America/Tijuana a America/Mexico_City en PostulationController - Agregar configuración de Google Maps - Agregar servicio de notificaciones push Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -124,7 +124,7 @@ class PostulationController extends Controller
|
||||
// Parsear fecha y hora del formato ISO que envía el frontend
|
||||
$dateStr = substr(strip_tags($request->setdate), 0, 10); // "2026-01-28"
|
||||
$timeStr = substr(strip_tags($request->sethour), 11, 8); // "19:47:00"
|
||||
$postulation->appointment = Carbon::createFromFormat('Y-m-d H:i:s', $dateStr . ' ' . $timeStr, 'America/Tijuana')->tz('UTC');
|
||||
$postulation->appointment = Carbon::createFromFormat('Y-m-d H:i:s', $dateStr . ' ' . $timeStr, 'America/Mexico_City')->tz('UTC');
|
||||
$postulation->amount = 5000;
|
||||
$postulation->details = preg_replace('/\d+/', '', strip_tags($request->details));
|
||||
$postulation->save();
|
||||
|
||||
@@ -12,15 +12,27 @@ class Cors
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$allowedOrigins = [
|
||||
'http://localhost',
|
||||
'https://localhost',
|
||||
'ionic://localhost',
|
||||
'https://jobhero.consultoria-as.com',
|
||||
'https://jobhero-api.consultoria-as.com',
|
||||
'capacitor://localhost',
|
||||
'http://localhost:8100'
|
||||
];
|
||||
|
||||
$allowedOrigins = ['http://localhost', 'ionic://localhost'];
|
||||
$origin = $request->server('HTTP_ORIGIN');
|
||||
|
||||
if (in_array($request->server('HTTP_ORIGIN'), $allowedOrigins)) {
|
||||
return $next($request)
|
||||
->header('Access-Control-Allow-Origin', $request->server('HTTP_ORIGIN'))
|
||||
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
|
||||
->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With, X-XSRF-TOKEN');
|
||||
}
|
||||
// Allow requests from mobile apps (no origin or capacitor/ionic)
|
||||
if (empty($origin) || in_array($origin, $allowedOrigins)) {
|
||||
$response = $next($request);
|
||||
$allowOrigin = empty($origin) ? '*' : $origin;
|
||||
return $response
|
||||
->header('Access-Control-Allow-Origin', $allowOrigin)
|
||||
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
|
||||
->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With, X-XSRF-TOKEN');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
207
app/Services/PushNotificationService.php
Normal file
207
app/Services/PushNotificationService.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use OneSignal;
|
||||
|
||||
class PushNotificationService
|
||||
{
|
||||
/**
|
||||
* Send notification to a specific user by their ID
|
||||
*
|
||||
* @param int $userId
|
||||
* @param string $message
|
||||
* @param string $heading
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToUser(int $userId, string $message, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
return OneSignal::sendNotificationUsingTags(
|
||||
$message,
|
||||
[
|
||||
['field' => 'tag', 'key' => 'iChamba_ID', 'relation' => '=', 'value' => (string) $userId]
|
||||
],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$heading,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification to multiple users
|
||||
*
|
||||
* @param array $userIds
|
||||
* @param string $message
|
||||
* @param string $heading
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function sendToUsers(array $userIds, string $message, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
$results = [];
|
||||
foreach ($userIds as $userId) {
|
||||
$results[$userId] = $this->sendToUser($userId, $message, $heading, $data);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send scheduled notification to a user
|
||||
*
|
||||
* @param int $userId
|
||||
* @param string $message
|
||||
* @param string $sendAt UTC datetime string
|
||||
* @param string $heading
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendScheduledToUser(int $userId, string $message, string $sendAt, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
return OneSignal::sendNotificationUsingTags(
|
||||
$message,
|
||||
[
|
||||
['field' => 'tag', 'key' => 'iChamba_ID', 'relation' => '=', 'value' => (string) $userId]
|
||||
],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$heading,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$sendAt,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification to all users with a specific role
|
||||
*
|
||||
* @param int $roleId
|
||||
* @param string $message
|
||||
* @param string $heading
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToRole(int $roleId, string $message, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
return OneSignal::sendNotificationUsingTags(
|
||||
$message,
|
||||
[
|
||||
['field' => 'tag', 'key' => 'iChamba_Role', 'relation' => '=', 'value' => (string) $roleId]
|
||||
],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$heading,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification types for contracts
|
||||
*/
|
||||
public function notifyContractHired(int $supplierId, string $address)
|
||||
{
|
||||
return $this->sendToUser(
|
||||
$supplierId,
|
||||
"Has sido contratado para un servicio. Dirígete a la sección de postulaciones contratadas para más detalles.",
|
||||
"¡Nuevo Contrato!"
|
||||
);
|
||||
}
|
||||
|
||||
public function notifyContractStarted(int $userId, string $address, string $date)
|
||||
{
|
||||
return $this->sendToUser(
|
||||
$userId,
|
||||
"El servicio en {$address} el día {$date} ha sido iniciado. Dirígete a la sección de servicios contratados para más detalles.",
|
||||
"Servicio Iniciado"
|
||||
);
|
||||
}
|
||||
|
||||
public function notifyContractCancelled(int $supplierId, string $address, string $date)
|
||||
{
|
||||
return $this->sendToUser(
|
||||
$supplierId,
|
||||
"El servicio en {$address} el día {$date} ha sido cancelado. Dirígete a la sección de servicios contratados para más detalles.",
|
||||
"Servicio Cancelado"
|
||||
);
|
||||
}
|
||||
|
||||
public function notifySupplierArrived(int $clientId, string $address)
|
||||
{
|
||||
return $this->sendToUser(
|
||||
$clientId,
|
||||
"El proveedor para el servicio en {$address} ha llegado. Dirígete a la sección de contratos confirmados para más detalles.",
|
||||
"Proveedor ha llegado"
|
||||
);
|
||||
}
|
||||
|
||||
public function notifyAppointmentReminder(int $userId, string $address, int $minutesBefore = 30)
|
||||
{
|
||||
return $this->sendToUser(
|
||||
$userId,
|
||||
"Tienes un servicio agendado hoy en {$address} en {$minutesBefore} minutos. Dirígete a la sección de contratos confirmados para más detalles.",
|
||||
"Recordatorio de Cita"
|
||||
);
|
||||
}
|
||||
|
||||
public function notifyNewPostulation(int $supplierId)
|
||||
{
|
||||
return $this->sendToUser(
|
||||
$supplierId,
|
||||
"Hay una nueva postulación disponible en tu área. Dirígete a la sección de postulaciones para ver más detalles.",
|
||||
"Nueva Postulación"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user