HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/dmstechonline/whatsapp.dmstech.online/backup-2.7-swiftchats/app/Services/ChatNoteService.php
<?php

namespace App\Services;

use App\Http\Resources\ChatNoteResource;
use App\Models\ChatLog;
use App\Models\ChatNote;
use App\Models\Contact;

class ChatNoteService
{
    public function get(object $request)
    {
        $rows = (new ChatNote)->listAll($request->query('search'));

        return ChatNoteResource::collection($rows);
    }

    public function getByUuid($uuid = null)
    {
        return ChatNote::where('id', $uuid)->first();
    }

    public function store(object $request, $uuid = NULL)
    {
        $contact = Contact::where('uuid', $request->contact)->first();

        $note = $uuid === null ? new ChatNote() : ChatNote::where('uuid', $uuid)->firstOrFail();
        $note->contact_id = $contact->id;
        $note->content = $request->notes;
        $note->created_by = auth()->user()->id;
        $note->save();

        ChatLog::insert([
            'contact_id' => $contact->id,
            'entity_type' => 'notes',
            'entity_id' => $note->id,
            'created_at' => now()
        ]);

        return $note;
    }

    public function delete($uuid)
    {
        $note = ChatNote::where('uuid', $uuid)->firstOrFail();
        $note->deleted_at = date('Y-m-d H:i:s');
        $note->deleted_by = auth()->user()->id;
        $note->save();
    } 
}