Browse Source

Merge pull request 'dev-wahyun' (#46) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#46
pull/1/head
farhantock 9 months ago
parent
commit
930a25c8a7
  1. 31
      app/Http/Controllers/AuthController.php
  2. 30
      app/Http/Controllers/ProductTransactionController.php
  3. 1
      app/Models/Company.php
  4. 25
      app/Models/ProductTransaction.php
  5. 1
      routes/web.php

31
app/Http/Controllers/AuthController.php

@ -113,18 +113,33 @@ class AuthController extends Controller
public function sendEmail(Request $request)
{
$hashed = Str::random(15);
if (empty($request->password)) {
$hashed = Str::random(15);
} else {
$hashed = $request->password;
}
$email = $request->email;
$user = User::select('email', 'name', 'username')->where('email', $email)->first();
if (!$user || empty($email)) {
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400);
return response()->json(['status' => 'error', 'message' => 'e-mail not found'], 400);
} else {
$this->reqHttpCurl($email, $hashed, $user->username, $user->name);
if (User::where('email', $email)->update(['password' => md5($hashed)]))
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400);
if($request->username) {
$username = $request->username;
$name = $request->username;
} else {
$username = $user->username;
$name = $user->name;
}
$this->reqHttpCurl($email, $hashed, $username, $name);
if(empty($request->password)) {
if (User::where('email', $email)->update(['password' => md5($hashed)])) {
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
}
} else {
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
}
}
}
@ -132,7 +147,7 @@ class AuthController extends Controller
{
$postData = [
"to" => $email,
"username" => $name,
"name" => $name,
"username" => $username,
"password" => $password,
"from" => "app.integrasia@integrasiautama.com",

30
app/Http/Controllers/ProductTransactionController.php

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProductTransaction;
class ProductTransactionController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'company_id' => 'required|integer',
'type_paket' => 'required|string',
'amount' => 'required',
'exp_ospro' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProductTransaction::create($data);
if ($result) {
return response()->json(['status' => 'success','data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Add data Transaction failed!', 'code' => 400], 400);
}
}
}

1
app/Models/Company.php

@ -33,6 +33,7 @@ class Company extends Model
'updated_at',
'updated_by',
'cluster',
'type_account',
'date_register'
];
}

25
app/Models/ProductTransaction.php

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProductTransaction extends Model
{
protected $table = 't_transaction';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'company_id',
'type_paket',
'amount',
'exp_ospro',
'pay_date',
'created_at',
'updated_at',
'created_by',
'updated_by'
];
}

1
routes/web.php

@ -9,6 +9,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
// Landing Route
$router->post('/send-email', 'AuthController@sendEmail');
$router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/product-transaction/add','ProductTransactionController@add');
$router->post('/company-management-user/search', 'CompanyController@search');
$router->post('/human-resource-user/add', 'HumanResourceController@add_user');
$router->get('/company-management-user/edit/{id}', 'CompanyController@edit');

Loading…
Cancel
Save