ticketing Sapar notes finished
This commit is contained in:
parent
edaf9d74ba
commit
9f6391fe7c
|
|
@ -26,7 +26,20 @@ public function getTicketMessages(Request $request){
|
|||
|
||||
public function postMessage(MessageRequest $request){
|
||||
try{
|
||||
$message = new Message($request->only(['is_client', 'ticket_id', 'content']));
|
||||
$message = new Message($request->only(['ticket_id', 'content']));
|
||||
$message['is_client'] = true;
|
||||
$message->save();
|
||||
return MessageResource::make($message);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function postMessageAdmin(MessageRequest $request){
|
||||
try{
|
||||
$message = new Message($request->only(['ticket_id', 'content', 'admin_id', 'status_id']));
|
||||
$message['is_client'] = false;
|
||||
$message->save();
|
||||
return MessageResource::make($message);
|
||||
}
|
||||
|
|
@ -37,7 +50,7 @@ public function postMessage(MessageRequest $request){
|
|||
|
||||
public function getTickets(Request $request){
|
||||
$client = $request->user();
|
||||
$tickets = Ticket::with('status')->where('client_id', $client->id)->get();
|
||||
$tickets = Ticket::with('status')->where('client_id', $client->id)->orderBy('created_at', 'desc')->get();
|
||||
return TicketResource::collection($tickets);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ public function rules()
|
|||
{
|
||||
return [
|
||||
'content' => 'required',
|
||||
'ticket_id' => ['required', new TicketRule],
|
||||
'is_client' => 'required|boolean'
|
||||
'ticket_id' => ['required', new TicketRule]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,24 +14,13 @@ class MessageResource extends JsonResource
|
|||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
if(!$this->is_client){
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'content' => $this->content,
|
||||
'ticket_id' => $this->ticket_id,
|
||||
'is_client' => $this->is_client,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
else{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'content' => $this->content,
|
||||
'ticket_id' => $this->ticket_id,
|
||||
'is_client' => $this->is_client,
|
||||
'created_at' => $this->created_at,
|
||||
'admin' => $this->admin->name
|
||||
];
|
||||
}
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'content' => $this->content,
|
||||
'ticket_id' => $this->ticket_id,
|
||||
'is_client' => $this->is_client,
|
||||
'created_at' => $this->created_at,
|
||||
'admin' => $this->admin->name ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@
|
|||
$('#chat-messages').append('<div class="chat-log__item client"><h3 class="chat-log__author">Client<small class="small-date">' + dateString + '</small></h3><div class="chat-log__message"><p>' + element.content + '</p></div>');
|
||||
}
|
||||
else{
|
||||
$('#chat-messages').append('<div class="chat-log__item admin bg-gray-200"><h3 class="chat-log__author">{{backpack_user()->name}} <small class="small-date">' + dateString + '</small></h3><div class="chat-log__message">' + element.content + '</div></div>');
|
||||
$('#chat-messages').append('<div class="chat-log__item admin bg-gray-200"><h3 class="chat-log__author">You <small class="small-date">' + dateString + '</small></h3><div class="chat-log__message">' + element.content + '</div></div>');
|
||||
}
|
||||
});
|
||||
console.log(res);
|
||||
|
|
@ -139,7 +139,7 @@
|
|||
$('#messageForm').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
var settings = {
|
||||
"url": "/post-message",
|
||||
"url": "/post-message-admin",
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Content-Type": "application/json"
|
||||
|
|
@ -147,7 +147,6 @@
|
|||
"data": JSON.stringify({
|
||||
content: $('#message-content').val(),
|
||||
ticket_id: id,
|
||||
is_client: 0,
|
||||
status_id: 1,
|
||||
admin_id: {{backpack_user()->getAttribute('id')}}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@
|
|||
Route::crud('category', 'CategoryCrudController');
|
||||
Route::crud('message', 'MessageCrudController');
|
||||
}); // this should be the absolute last line of this file
|
||||
Route::post('/post-message', [TicketController::class, 'postMessage']);
|
||||
Route::post('/post-message-admin',[TicketController::class,'postMessageAdmin']);
|
||||
|
|
|
|||
|
|
@ -1356,9 +1356,6 @@
|
|||
"content": {
|
||||
"type": "string"
|
||||
},
|
||||
"is_client": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"ticket_id": {
|
||||
"type": "integer"
|
||||
}
|
||||
|
|
@ -1366,7 +1363,6 @@
|
|||
"type": "object",
|
||||
"example": {
|
||||
"content": "ilmedovamahri@gmail.com",
|
||||
"is_client": 1,
|
||||
"ticket_id": 2
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue