mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-24 15:04:24 +00:00
changed the listing function on contacts frontend, still got issues
This commit is contained in:
@@ -16,14 +16,13 @@ class CompanyController extends Controller
|
||||
return '';
|
||||
}
|
||||
$output= array();
|
||||
$matchedTerms = Company::where('company_name', 'LIKE','%'. $request->search . '%')->get();
|
||||
$matchedTerms = Company::where('company_name', 'LIKE','%'. $request->search . '%')->where('id', '<>', Auth::user()->company()->first()->id)->get();
|
||||
|
||||
if($matchedTerms)
|
||||
{
|
||||
foreach ($matchedTerms as $key => $matchedTerm)
|
||||
{
|
||||
array_push($output, ['com_id'=> $matchedTerm->id, 'company_name' => $matchedTerm->company_name, 'tel_no' => $matchedTerm->tel_no,
|
||||
'contact_person'=>$matchedTerm->contact_person ]);
|
||||
array_push($output, ['recipient_id'=> $matchedTerm->id, 'company_name' => $matchedTerm->company_name, 'tel_no' => $matchedTerm->tel_no, 'contact_person'=>$matchedTerm->contact_person ]);
|
||||
}
|
||||
|
||||
return response($output);
|
||||
@@ -34,6 +33,7 @@ class CompanyController extends Controller
|
||||
public function update(Request $request)
|
||||
{
|
||||
$company = Company::where("user_id", Auth::user()->id)->first();
|
||||
|
||||
if (!$company)
|
||||
{
|
||||
return response()->json(['success'=> false, 'message'=>'Company not found'], 404);
|
||||
@@ -59,6 +59,22 @@ class CompanyController extends Controller
|
||||
return response()->json(['success'=> false, 'error'=> 'All the fields are required'], 400);
|
||||
//return response()->json(['success'=> false, 'error'=> $validator->messages()], 400);
|
||||
}
|
||||
|
||||
$company->company_name=$request->input('company_name');
|
||||
$company->registration_no=$request->input('registration_no');
|
||||
$company->tax_no=$request->input('tax_no');
|
||||
$company->tel_no=$request->input('tel_no');
|
||||
$company->fax=$request->input('fax');
|
||||
$company->address=$request->input('address');
|
||||
$company->city=$request->input('city');
|
||||
$company->postcode=$request->input('postcode');
|
||||
$company->state=$request->input('state');
|
||||
$company->country=$request->input('country');
|
||||
$company->contact_person=$request->input('contact_person');
|
||||
|
||||
$company->save();
|
||||
return response()->json(['success'=> true, 'message'=>'Company created successfully'],200);
|
||||
|
||||
}
|
||||
|
||||
public function create()
|
||||
|
||||
@@ -11,32 +11,51 @@ class ContactController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
//return Auth::user()->company()->first()->id;
|
||||
$output= array();
|
||||
$contacts = Contact::where('user_id', Auth::user()->id)->get();
|
||||
$companies= Contact::with('companies')->get();
|
||||
//$companies =\DB::table('companies')->select('contacts.com_id', 'companies.id', 'companies.company_name')->join('contacts', 'contacts.com_id', '=', 'companies.id')->get();
|
||||
//$companies = "SELECT contacts.com_id, companies.id, companies.company_name FROM `companies` INNER JOIN contacts ON contacts.com_id = companies.id";
|
||||
|
||||
// $companies = \DB::table('companies')
|
||||
// ->select('id', 'company_name')
|
||||
// ->where('com_id', Auth::user()->id)
|
||||
// ->get();
|
||||
// $contacts = Contact::where('sender_id', Auth::user()->id)->get();
|
||||
//$companies= Contact::with('companies')->get();
|
||||
$contacts =\DB::table('contacts')->select('contacts.id as contact_id', 'sender_company.company_name as sender_company_name', 'sender_company.id as sender_company_id', 'recipient_company.id as recipient_company_id', 'recipient_company.company_name as recipient_company_name', 'contacts.status', 'sender_company.tel_no as sender_tel_no', 'recipient_company.tel_no as recipient_tel_no', 'sender_company.contact_person as sender_contact_pers', 'recipient_company.contact_person as recipient_contact_pers')->leftJoin('companies as sender_company', 'sender_company.id', '=', 'contacts.sender_id')->leftJoin('companies as recipient_company', 'recipient_company.id', '=', 'contacts.recipient_id')->where('contacts.sender_id', Auth::user()->company()->first()->id)->orWhere('contacts.recipient_id', Auth::user()->company()->first()->id)->get();
|
||||
|
||||
if (!$contacts)
|
||||
{
|
||||
return response()->json(['message'=>'Access Denied!'], 404);
|
||||
}
|
||||
|
||||
return response()->json($companies, 200);
|
||||
$contacts2 = $contacts->toArray();
|
||||
// $toprint = $contacts2[0]->sender_company_name;
|
||||
// echo $toprint;
|
||||
$length = count($contacts2);
|
||||
|
||||
for ($i=0; $i < $length; $i++) {
|
||||
# code...
|
||||
if($contacts2[$i]->sender_company_id == Auth::user()->company()->first()->id){
|
||||
$contacts2[$i]->is_me = 1;
|
||||
}
|
||||
else{
|
||||
$contacts2[$i]->is_me = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// foreach ($contacts2 as $contact => $value) {
|
||||
// print_r($value->sender_company_name);
|
||||
// //if($value['sender_company_id'] == Auth::user()->company()->first()->id){
|
||||
// // var_dump($contact);
|
||||
// //print_r($value['sender_company_id']);
|
||||
// //}
|
||||
|
||||
// //$contact->helo
|
||||
// }
|
||||
return response()->json($contacts2, 200);
|
||||
}
|
||||
|
||||
public function sendRequest(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$com_id = $request->input('com_id');
|
||||
$recipient_id = $request->input('recipient_id');
|
||||
|
||||
// query to find company asisng to $company
|
||||
$company = Company::find($com_id);
|
||||
$company = Company::find($recipient_id);
|
||||
|
||||
// get user from session
|
||||
$request->user();
|
||||
@@ -44,51 +63,48 @@ class ContactController extends Controller
|
||||
|
||||
// prepare query
|
||||
$contact = new Contact();
|
||||
$contact->com_id = $company->id;
|
||||
$contact->user_id = $user->id;
|
||||
$contact->recipient_id = $company->id;
|
||||
$contact->sender_id = $user->id;
|
||||
$contact->save();
|
||||
|
||||
return response()->json($contact, 201);
|
||||
}
|
||||
|
||||
public function acceptRequest(Request $request, $id)
|
||||
public function acceptRequest(Request $request)
|
||||
{
|
||||
$contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first();
|
||||
$contact = Contact::where('id', $request->input('id'))->first();//->where('id', $id)->first();
|
||||
//$contact = Contact::where('id', '=', e($id))->first();
|
||||
if($contact)
|
||||
{
|
||||
$action=$request->input('action');
|
||||
if ($action==1)
|
||||
{
|
||||
$contact->status=1;
|
||||
}
|
||||
if ($action==0)
|
||||
{
|
||||
$contact->status=0;
|
||||
}
|
||||
else{
|
||||
|
||||
return response()->json(["message" => "not allowed"], 400);
|
||||
}
|
||||
$contact->status=1;
|
||||
|
||||
$saved = $contact->save();
|
||||
if ($saved){
|
||||
return response()->json($contact, 201);
|
||||
return response()->json(["success"=> true, "message" => "Successfully accepted"], 201);
|
||||
}
|
||||
return response()->json($contact, 400);
|
||||
else{
|
||||
return response()->json($contact, ["message" => "not saved"], 400);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return response()->json( ["message" => "not allowed"], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
$contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first();
|
||||
$contact = Contact::where('id', $request->input('id'))->first();
|
||||
//$contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first();
|
||||
|
||||
if (!$contact)
|
||||
{
|
||||
return response()->json(['message'=>'Access Denied!'], 404);
|
||||
}
|
||||
|
||||
$contact->delete($id);
|
||||
else
|
||||
{
|
||||
$contact->delete();
|
||||
}
|
||||
|
||||
return response()->json($contact, 204);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user