add test batches
This commit is contained in:
@@ -10,16 +10,18 @@ use RuntimeException;
|
||||
|
||||
class MessageCommandService
|
||||
{
|
||||
public function __construct(private GlobalConfigService $configService) {}
|
||||
public function __construct(private GlobalConfigService $configService)
|
||||
{
|
||||
}
|
||||
|
||||
public function create(int $senderId, array $payload, ?UploadedFile $attachment = null): Message
|
||||
{
|
||||
$recipientId = $payload['recipient_id'] ?? null;
|
||||
if (! $recipientId && ! empty($payload['recipient_role'])) {
|
||||
if (!$recipientId && !empty($payload['recipient_role'])) {
|
||||
$recipientId = $this->recipientIdFromRole($payload['recipient_role']);
|
||||
}
|
||||
|
||||
if (! $recipientId) {
|
||||
if (!$recipientId) {
|
||||
throw new RuntimeException('Recipient is required.');
|
||||
}
|
||||
|
||||
@@ -40,7 +42,7 @@ class MessageCommandService
|
||||
'message' => (string) $payload['message'],
|
||||
'sent_datetime' => now(),
|
||||
'read_status' => 0,
|
||||
'message_number' => 'MSG-'.now()->format('YmdHis'),
|
||||
'message_number' => 'MSG-' . now()->format('YmdHis'),
|
||||
'priority' => $payload['priority'] ?? 'normal',
|
||||
'attachment' => $path,
|
||||
'status' => $payload['status'] ?? 'sent',
|
||||
@@ -48,7 +50,7 @@ class MessageCommandService
|
||||
'school_year' => $payload['school_year'] ?? $this->configService->getSchoolYear() ?? '',
|
||||
]);
|
||||
|
||||
if (! $message) {
|
||||
if (!$message) {
|
||||
throw new RuntimeException('Failed to send message.');
|
||||
}
|
||||
|
||||
@@ -74,7 +76,7 @@ class MessageCommandService
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($updates)) {
|
||||
if (!empty($updates)) {
|
||||
$message->fill($updates);
|
||||
$message->save();
|
||||
}
|
||||
@@ -87,7 +89,6 @@ class MessageCommandService
|
||||
{
|
||||
return DB::transaction(function () use ($message) {
|
||||
$message->status = 'trashed';
|
||||
|
||||
return (bool) $message->save();
|
||||
});
|
||||
}
|
||||
@@ -116,7 +117,7 @@ class MessageCommandService
|
||||
];
|
||||
|
||||
$key = strtolower(trim($roleName));
|
||||
if (! isset($map[$key])) {
|
||||
if (!isset($map[$key])) {
|
||||
throw new RuntimeException('Invalid recipient role.');
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,11 @@ class MessageQueryService
|
||||
public function getUserRoleName(int $userId): ?string
|
||||
{
|
||||
$user = User::query()->with('roles')->find($userId);
|
||||
if (! $user) {
|
||||
if (!$user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$role = $user->roles->sortBy('id')->first();
|
||||
|
||||
return $role ? (string) $role->name : null;
|
||||
}
|
||||
|
||||
@@ -68,7 +67,7 @@ class MessageQueryService
|
||||
->pluck('id')
|
||||
->all();
|
||||
|
||||
if (! empty($ids)) {
|
||||
if (!empty($ids)) {
|
||||
Message::query()
|
||||
->whereIn('id', $ids)
|
||||
->update([
|
||||
@@ -91,7 +90,7 @@ class MessageQueryService
|
||||
{
|
||||
$query = Message::query()->with(['sender', 'recipient']);
|
||||
|
||||
if (! empty($filters['priority'])) {
|
||||
if (!empty($filters['priority'])) {
|
||||
$query->where('priority', $filters['priority']);
|
||||
}
|
||||
|
||||
@@ -99,8 +98,8 @@ class MessageQueryService
|
||||
$query->where('read_status', (int) $filters['read_status']);
|
||||
}
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$term = '%'.$filters['search'].'%';
|
||||
if (!empty($filters['search'])) {
|
||||
$term = '%' . $filters['search'] . '%';
|
||||
$query->where(function ($q) use ($term) {
|
||||
$q->where('subject', 'like', $term)
|
||||
->orWhere('message', 'like', $term);
|
||||
|
||||
@@ -22,7 +22,7 @@ class MessageRecipientService
|
||||
return $rows
|
||||
->map(fn ($row) => [
|
||||
'id' => (int) $row->teacher_id,
|
||||
'name' => trim($row->firstname.' '.$row->lastname),
|
||||
'name' => trim($row->firstname . ' ' . $row->lastname),
|
||||
])
|
||||
->unique('id')
|
||||
->values()
|
||||
@@ -81,7 +81,7 @@ class MessageRecipientService
|
||||
return $users
|
||||
->map(fn ($row) => [
|
||||
'id' => (int) $row->id,
|
||||
'name' => trim($row->firstname.' '.$row->lastname),
|
||||
'name' => trim($row->firstname . ' ' . $row->lastname),
|
||||
])
|
||||
->unique('id')
|
||||
->values()
|
||||
|
||||
Reference in New Issue
Block a user