mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
change state_users table to user and rename colums in camelCase, adapt
This commit is contained in:
parent
c9f621e119
commit
0c7bb13b4e
@ -21,7 +21,7 @@ import { isAuthorized } from './auth/auth'
|
|||||||
// TODO implement
|
// TODO implement
|
||||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||||
|
|
||||||
const DB_VERSION = '0001-init_db'
|
const DB_VERSION = '0002-update_user'
|
||||||
|
|
||||||
const context = (args: any) => {
|
const context = (args: any) => {
|
||||||
const authorization = args.req.headers.authorization
|
const authorization = args.req.headers.authorization
|
||||||
|
|||||||
@ -223,22 +223,22 @@ class AppController extends Controller
|
|||||||
$public_key_bin = hex2bin($json['user']['public_hex']);
|
$public_key_bin = hex2bin($json['user']['public_hex']);
|
||||||
$stateUserQuery = $stateUserTable
|
$stateUserQuery = $stateUserTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->where(['public_key' => $public_key_bin])
|
->where(['pubkey' => $public_key_bin])
|
||||||
->contain('StateBalances', function ($q) {
|
->contain('StateBalances', function ($q) {
|
||||||
return $q->order(['record_date' => 'DESC'])
|
return $q->order(['record_date' => 'DESC'])
|
||||||
->limit(1);
|
->limit(1);
|
||||||
});
|
});
|
||||||
if ($stateUserQuery->count() == 1) {
|
if ($stateUserQuery->count() == 1) {
|
||||||
$stateUser = $stateUserQuery->first();
|
$stateUser = $stateUserQuery->first();
|
||||||
if ($stateUser->first_name != $json['user']['first_name'] ||
|
if ($stateUser->firstName != $json['user']['first_name'] ||
|
||||||
$stateUser->last_name != $json['user']['last_name'] ||
|
$stateUser->lastName != $json['user']['last_name'] ||
|
||||||
$stateUser->disabled != $json['user']['disabled'] ||
|
$stateUser->disabled != $json['user']['disabled'] ||
|
||||||
//$stateUser->username != $json['user']['username'] ||
|
//$stateUser->username != $json['user']['username'] ||
|
||||||
// -> throws error
|
// -> throws error
|
||||||
$stateUser->email != $json['user']['email']
|
$stateUser->email != $json['user']['email']
|
||||||
) {
|
) {
|
||||||
$stateUser->first_name = $json['user']['first_name'];
|
$stateUser->firstName = $json['user']['first_name'];
|
||||||
$stateUser->last_name = $json['user']['last_name'];
|
$stateUser->lastName = $json['user']['last_name'];
|
||||||
$stateUser->disabled = intval($json['user']['disabled']);
|
$stateUser->disabled = intval($json['user']['disabled']);
|
||||||
//$stateUser->username = $json['user']['username'];
|
//$stateUser->username = $json['user']['username'];
|
||||||
$stateUser->email = $json['user']['email'];
|
$stateUser->email = $json['user']['email'];
|
||||||
@ -250,9 +250,9 @@ class AppController extends Controller
|
|||||||
//echo $stateUser['id'];
|
//echo $stateUser['id'];
|
||||||
} else {
|
} else {
|
||||||
$newStateUser = $stateUserTable->newEntity();
|
$newStateUser = $stateUserTable->newEntity();
|
||||||
$newStateUser->public_key = $public_key_bin;
|
$newStateUser->pubkey = $public_key_bin;
|
||||||
$newStateUser->first_name = $json['user']['first_name'];
|
$newStateUser->firstName = $json['user']['first_name'];
|
||||||
$newStateUser->last_name = $json['user']['last_name'];
|
$newStateUser->lastName = $json['user']['last_name'];
|
||||||
$newStateUser->disabled = intval($json['user']['disabled']);
|
$newStateUser->disabled = intval($json['user']['disabled']);
|
||||||
//$newStateUser->username = $json['user']['username'];
|
//$newStateUser->username = $json['user']['username'];
|
||||||
$newStateUser->email = $json['user']['email'];
|
$newStateUser->email = $json['user']['email'];
|
||||||
|
|||||||
@ -308,7 +308,7 @@ class JsonRequestHandlerController extends AppController {
|
|||||||
$stateError = $stateErrorTable->newEntity();
|
$stateError = $stateErrorTable->newEntity();
|
||||||
//
|
//
|
||||||
$pubkey = hex2bin($jsonData->public_key);
|
$pubkey = hex2bin($jsonData->public_key);
|
||||||
$user_query = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $pubkey]);
|
$user_query = $stateUsersTable->find('all')->select(['id'])->where(['pubkey' => $pubkey]);
|
||||||
if($user_query->count() != 1) {
|
if($user_query->count() != 1) {
|
||||||
return $this->returnJson(['state' => 'error', 'msg' => 'user not found', 'details' => 'user pubkey hex:' . $jsonData->public_key]);
|
return $this->returnJson(['state' => 'error', 'msg' => 'user not found', 'details' => 'user pubkey hex:' . $jsonData->public_key]);
|
||||||
}
|
}
|
||||||
@ -412,7 +412,7 @@ class JsonRequestHandlerController extends AppController {
|
|||||||
//$pubkeys->sender
|
//$pubkeys->sender
|
||||||
//$pubkeys->receiver
|
//$pubkeys->receiver
|
||||||
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
||||||
$user = $stateUserTable->find('all')->where(['public_key' => hex2bin($pubkeys->sender)])->contain(['StateBalances']);
|
$user = $stateUserTable->find('all')->where(['pubkey' => hex2bin($pubkeys->sender)])->contain(['StateBalances']);
|
||||||
if(!$user->count()) {
|
if(!$user->count()) {
|
||||||
return $this->returnJson(['state' => 'not found', 'msg' => 'user not found or empty balance']);
|
return $this->returnJson(['state' => 'not found', 'msg' => 'user not found or empty balance']);
|
||||||
}
|
}
|
||||||
@ -461,7 +461,7 @@ class JsonRequestHandlerController extends AppController {
|
|||||||
|
|
||||||
private function userDelete($userPubkeyHex) {
|
private function userDelete($userPubkeyHex) {
|
||||||
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
||||||
$user = $stateUserTable->find('all')->where(['public_key' => hex2bin($userPubkeyHex)]);
|
$user = $stateUserTable->find('all')->where(['pubkey' => hex2bin($userPubkeyHex)]);
|
||||||
if(!$user || $user->count == 0) {
|
if(!$user || $user->count == 0) {
|
||||||
return $this->returnJson(['state' => 'error', 'msg' => 'user not found']);
|
return $this->returnJson(['state' => 'error', 'msg' => 'user not found']);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,7 +132,7 @@ class StateUserRolesController extends AppController
|
|||||||
|
|
||||||
$public_hex = hex2bin($requestData['public_hex']);
|
$public_hex = hex2bin($requestData['public_hex']);
|
||||||
|
|
||||||
$stateUser = $this->StateUsers->find('all')->where(['public_key' => $public_hex])->first();
|
$stateUser = $this->StateUsers->find('all')->where(['pubkey' => $public_hex])->first();
|
||||||
|
|
||||||
foreach($requestData['role_id'] as $role_id)
|
foreach($requestData['role_id'] as $role_id)
|
||||||
{
|
{
|
||||||
@ -158,7 +158,7 @@ class StateUserRolesController extends AppController
|
|||||||
|
|
||||||
$publichex = hex2bin($public_hex);
|
$publichex = hex2bin($public_hex);
|
||||||
|
|
||||||
$stateUser = $this->StateUsers->find('all')->where(['public_key' => $publichex])->first();
|
$stateUser = $this->StateUsers->find('all')->where(['pubkey' => $publichex])->first();
|
||||||
|
|
||||||
$stateUserRoles = $this->StateUserRoles->find('all')->where(['state_user_id' => $stateUser->id])->all();
|
$stateUserRoles = $this->StateUserRoles->find('all')->where(['state_user_id' => $stateUser->id])->all();
|
||||||
|
|
||||||
|
|||||||
@ -182,15 +182,15 @@ class StateUsersController extends AppController
|
|||||||
|
|
||||||
if($account_state == 'email not activated') {
|
if($account_state == 'email not activated') {
|
||||||
if(count($pubkeySorted) > 0) {
|
if(count($pubkeySorted) > 0) {
|
||||||
$communityUsers->where(['hex(public_key) IN' => array_keys($pubkeySorted)]);
|
$communityUsers->where(['hex(pubkey) IN' => array_keys($pubkeySorted)]);
|
||||||
} else {
|
} else {
|
||||||
$communityUsers = null;
|
$communityUsers = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$globalSearch = '%' . $searchString . '%';
|
$globalSearch = '%' . $searchString . '%';
|
||||||
$communityUsers->where(['OR' => [
|
$communityUsers->where(['OR' => [
|
||||||
'first_name LIKE' => $globalSearch,
|
'firstName LIKE' => $globalSearch,
|
||||||
'last_name LIKE' => $globalSearch,
|
'lastName LIKE' => $globalSearch,
|
||||||
'email LIKE' => $globalSearch
|
'email LIKE' => $globalSearch
|
||||||
]]);
|
]]);
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ class StateUsersController extends AppController
|
|||||||
//var_dump($communityUsers->toArray());
|
//var_dump($communityUsers->toArray());
|
||||||
if($communityUsers) {
|
if($communityUsers) {
|
||||||
foreach($communityUsers as $u) {
|
foreach($communityUsers as $u) {
|
||||||
$pubkey_hex = bin2hex(stream_get_contents($u->public_key));
|
$pubkey_hex = bin2hex(stream_get_contents($u->pubkey));
|
||||||
$u->public_hex = $pubkey_hex;
|
$u->public_hex = $pubkey_hex;
|
||||||
if(!isset($pubkeySorted[$pubkey_hex])) {
|
if(!isset($pubkeySorted[$pubkey_hex])) {
|
||||||
$pubkeySorted[$pubkey_hex] = ['login' => [], 'community' => []];
|
$pubkeySorted[$pubkey_hex] = ['login' => [], 'community' => []];
|
||||||
@ -229,9 +229,9 @@ class StateUsersController extends AppController
|
|||||||
$color = 'danger';
|
$color = 'danger';
|
||||||
if(count($user['community']) == 1) {
|
if(count($user['community']) == 1) {
|
||||||
$c_user = $user['community'][0];
|
$c_user = $user['community'][0];
|
||||||
$finalUser['name'] = $c_user->first_name . ' ' . $c_user->last_name;
|
$finalUser['name'] = $c_user->firstName . ' ' . $c_user->lastName;
|
||||||
$finalUser['first_name'] = $c_user->first_name;
|
$finalUser['first_name'] = $c_user->firstName;
|
||||||
$finalUser['last_name'] = $c_user->last_name;
|
$finalUser['last_name'] = $c_user->lastName;
|
||||||
$finalUser['email'] = $c_user->email;
|
$finalUser['email'] = $c_user->email;
|
||||||
}
|
}
|
||||||
} else if(count($user['login']) == 1) {
|
} else if(count($user['login']) == 1) {
|
||||||
@ -415,7 +415,7 @@ class StateUsersController extends AppController
|
|||||||
//$user = $jsonData['user'];
|
//$user = $jsonData['user'];
|
||||||
//var_dump($jsonData);
|
//var_dump($jsonData);
|
||||||
$pubkey = hex2bin($jsonData['pubkeyhex']);
|
$pubkey = hex2bin($jsonData['pubkeyhex']);
|
||||||
$stateUsers = $this->StateUsers->find('all')->where(['public_key' => $pubkey]);
|
$stateUsers = $this->StateUsers->find('all')->where(['pubkey' => $pubkey]);
|
||||||
if($stateUsers->count() != 1) {
|
if($stateUsers->count() != 1) {
|
||||||
return $this->returnJson(['state' => 'error', 'msg' => 'invalid result count']);
|
return $this->returnJson(['state' => 'error', 'msg' => 'invalid result count']);
|
||||||
}
|
}
|
||||||
@ -448,7 +448,7 @@ class StateUsersController extends AppController
|
|||||||
$pubkey = hex2bin($jsonData['pubkeyhex']);
|
$pubkey = hex2bin($jsonData['pubkeyhex']);
|
||||||
$stateUsers = $this->StateUsers
|
$stateUsers = $this->StateUsers
|
||||||
->find('all')
|
->find('all')
|
||||||
->where(['public_key' => $pubkey])
|
->where(['pubkey' => $pubkey])
|
||||||
->select(['id']);
|
->select(['id']);
|
||||||
if($stateUsers->count() != 1) {
|
if($stateUsers->count() != 1) {
|
||||||
return $this->returnJson(['state' => 'error', 'msg' => 'invalid result count']);
|
return $this->returnJson(['state' => 'error', 'msg' => 'invalid result count']);
|
||||||
|
|||||||
@ -101,7 +101,7 @@ class TransactionCreationsController extends AppController
|
|||||||
$receiverProposal = [];
|
$receiverProposal = [];
|
||||||
foreach ($stateUsers as $stateUser) {
|
foreach ($stateUsers as $stateUser) {
|
||||||
$name = $stateUser->email;
|
$name = $stateUser->email;
|
||||||
$keyHex = bin2hex(stream_get_contents($stateUser->public_key));
|
$keyHex = bin2hex(stream_get_contents($stateUser->pubkey));
|
||||||
if ($name === null) {
|
if ($name === null) {
|
||||||
$name = $stateUser->first_name . ' ' . $stateUser->last_name;
|
$name = $stateUser->first_name . ' ' . $stateUser->last_name;
|
||||||
}
|
}
|
||||||
@ -241,14 +241,14 @@ class TransactionCreationsController extends AppController
|
|||||||
$this->log("search for text: ".$requestData['searchText'], 'debug');
|
$this->log("search for text: ".$requestData['searchText'], 'debug');
|
||||||
$stateUsers = $stateUserTable
|
$stateUsers = $stateUserTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->select(['id', 'first_name', 'last_name', 'email'])
|
->select(['id', 'firstName', 'lastName', 'email'])
|
||||||
->order(['first_name', 'last_name'])
|
->order(['firstName', 'lastName'])
|
||||||
->where(
|
->where(
|
||||||
['AND' => [
|
['AND' => [
|
||||||
'disabled' => 0,
|
'disabled' => 0,
|
||||||
'OR' => [
|
'OR' => [
|
||||||
'LOWER(first_name) LIKE' => '%'.strtolower($requestData['searchText']).'%',
|
'LOWER(firstName) LIKE' => '%'.strtolower($requestData['searchText']).'%',
|
||||||
'LOWER(last_name) LIKE' => '%'.strtolower($requestData['searchText']).'%',
|
'LOWER(lastName) LIKE' => '%'.strtolower($requestData['searchText']).'%',
|
||||||
'LOWER(email) LIKE' => '%'.strtolower($requestData['searchText']).'%'
|
'LOWER(email) LIKE' => '%'.strtolower($requestData['searchText']).'%'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -265,10 +265,10 @@ class TransactionCreationsController extends AppController
|
|||||||
} else {
|
} else {
|
||||||
$stateUsers = $stateUserTable
|
$stateUsers = $stateUserTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->select(['id', 'first_name', 'last_name', 'email'])
|
->select(['id', 'firstName', 'lastName', 'email'])
|
||||||
//->order(['id'])
|
//->order(['id'])
|
||||||
->where(['disabled' => 0])
|
->where(['disabled' => 0])
|
||||||
->order(['first_name', 'last_name'])
|
->order(['firstName', 'lastName'])
|
||||||
->contain(['TransactionCreations' => [
|
->contain(['TransactionCreations' => [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'TransactionCreations.amount',
|
'TransactionCreations.amount',
|
||||||
@ -300,7 +300,7 @@ class TransactionCreationsController extends AppController
|
|||||||
|
|
||||||
//if($sumAmount < 20000000) {
|
//if($sumAmount < 20000000) {
|
||||||
array_push($possibleReceivers, [
|
array_push($possibleReceivers, [
|
||||||
'name' => $stateUser->first_name . ' ' . $stateUser->last_name,
|
'name' => $stateUser->firstName . ' ' . $stateUser->lastName,
|
||||||
'id' => $stateUser->id,
|
'id' => $stateUser->id,
|
||||||
'email' => $stateUser->email,
|
'email' => $stateUser->email,
|
||||||
'amount' => $sumAmount,
|
'amount' => $sumAmount,
|
||||||
@ -353,7 +353,7 @@ class TransactionCreationsController extends AppController
|
|||||||
}
|
}
|
||||||
$receiverUsers = $stateUserTable->find('all')
|
$receiverUsers = $stateUserTable->find('all')
|
||||||
->where(['id IN' => array_keys($users)])
|
->where(['id IN' => array_keys($users)])
|
||||||
->select(['public_key', 'email', 'id'])
|
->select(['pubkey', 'email', 'id'])
|
||||||
->contain(false);
|
->contain(false);
|
||||||
|
|
||||||
foreach ($receiverUsers as $receiverUser) {
|
foreach ($receiverUsers as $receiverUser) {
|
||||||
@ -371,7 +371,7 @@ class TransactionCreationsController extends AppController
|
|||||||
} else {
|
} else {
|
||||||
$pendings[$id] = $localAmountCent;
|
$pendings[$id] = $localAmountCent;
|
||||||
}
|
}
|
||||||
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
|
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->pubkey));
|
||||||
$requestAnswear = $this->JsonRequestClient->sendRequest(json_encode([
|
$requestAnswear = $this->JsonRequestClient->sendRequest(json_encode([
|
||||||
'session_id' => $session->read('session_id'),
|
'session_id' => $session->read('session_id'),
|
||||||
'email' => $receiverUser->email,
|
'email' => $receiverUser->email,
|
||||||
|
|||||||
@ -30,16 +30,14 @@ class StateUser extends Entity
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $_accessible = [
|
protected $_accessible = [
|
||||||
'index_id' => true,
|
'groupId' => true,
|
||||||
'state_group_id' => true,
|
'pubkey' => true,
|
||||||
'public_key' => true,
|
|
||||||
'email' => true,
|
'email' => true,
|
||||||
'first_name' => true,
|
'firstName' => true,
|
||||||
'last_name' => true,
|
'lastName' => true,
|
||||||
'disabled' => true,
|
'disabled' => true,
|
||||||
'username' => true,
|
'username' => true,
|
||||||
'index' => true,
|
'index' => true,
|
||||||
'state_group' => true,
|
|
||||||
'state_balances' => true,
|
'state_balances' => true,
|
||||||
'state_created' => true,
|
'state_created' => true,
|
||||||
'transaction_creations' => true,
|
'transaction_creations' => true,
|
||||||
@ -48,11 +46,11 @@ class StateUser extends Entity
|
|||||||
|
|
||||||
public function getEmailWithName()
|
public function getEmailWithName()
|
||||||
{
|
{
|
||||||
return $this->first_name . ' ' . $this->last_name . ' <' . $this->email . '>';
|
return $this->firstName . ' ' . $this->lastName . ' <' . $this->email . '>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNames()
|
public function getNames()
|
||||||
{
|
{
|
||||||
return $this->first_name . ' ' . $this->last_name;
|
return $this->firstName . ' ' . $this->lastName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,18 +37,10 @@ class StateUsersTable extends Table
|
|||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
|
|
||||||
$this->setTable('state_users');
|
$this->setTable('user');
|
||||||
$this->setDisplayField('email');
|
$this->setDisplayField('email');
|
||||||
$this->setPrimaryKey('id');
|
$this->setPrimaryKey('id');
|
||||||
|
|
||||||
/*$this->belongsTo('Indices', [
|
|
||||||
'foreignKey' => 'index_id',
|
|
||||||
'joinType' => 'INNER'
|
|
||||||
]);*/
|
|
||||||
$this->belongsTo('StateGroups', [
|
|
||||||
'foreignKey' => 'state_group_id',
|
|
||||||
'joinType' => 'INNER'
|
|
||||||
]);
|
|
||||||
$this->hasMany('StateBalances', [
|
$this->hasMany('StateBalances', [
|
||||||
'foreignKey' => 'state_user_id'
|
'foreignKey' => 'state_user_id'
|
||||||
]);
|
]);
|
||||||
@ -80,8 +72,8 @@ class StateUsersTable extends Table
|
|||||||
->allowEmptyString('id', null, 'create');
|
->allowEmptyString('id', null, 'create');
|
||||||
|
|
||||||
$validator
|
$validator
|
||||||
->requirePresence('public_key', 'create')
|
->requirePresence('pubkey', 'create')
|
||||||
->notEmptyString('public_key');
|
->notEmptyString('pubkey');
|
||||||
|
|
||||||
return $validator;
|
return $validator;
|
||||||
}
|
}
|
||||||
@ -124,7 +116,7 @@ class StateUsersTable extends Table
|
|||||||
$involvedUser = $this->find('all', [
|
$involvedUser = $this->find('all', [
|
||||||
'contain' => [],
|
'contain' => [],
|
||||||
'where' => ['id IN' => $involvedUserIds],
|
'where' => ['id IN' => $involvedUserIds],
|
||||||
'fields' => ['id', 'first_name', 'last_name', 'email'],
|
'fields' => ['id', 'firstName', 'lastName', 'email'],
|
||||||
]);
|
]);
|
||||||
//var_dump($involvedUser->toArray());
|
//var_dump($involvedUser->toArray());
|
||||||
$involvedUserIndices = [];
|
$involvedUserIndices = [];
|
||||||
|
|||||||
@ -49,13 +49,13 @@ class TransactionBase {
|
|||||||
protected function getStateUserId($publicKey) {
|
protected function getStateUserId($publicKey) {
|
||||||
|
|
||||||
$stateUsersTable = self::getTable('state_users');
|
$stateUsersTable = self::getTable('state_users');
|
||||||
$stateUser = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $publicKey])->first();
|
$stateUser = $stateUsersTable->find('all')->select(['id'])->where(['pubkey' => $publicKey])->first();
|
||||||
if($stateUser) {
|
if($stateUser) {
|
||||||
return $stateUser->id;
|
return $stateUser->id;
|
||||||
}
|
}
|
||||||
// create new entry
|
// create new entry
|
||||||
$stateUserEntity = $stateUsersTable->newEntity();
|
$stateUserEntity = $stateUsersTable->newEntity();
|
||||||
$stateUserEntity->public_key = $publicKey;
|
$stateUserEntity->pubkey = $publicKey;
|
||||||
if($stateUsersTable->save($stateUserEntity)) {
|
if($stateUsersTable->save($stateUserEntity)) {
|
||||||
return $stateUserEntity->id;
|
return $stateUserEntity->id;
|
||||||
} else {
|
} else {
|
||||||
@ -77,7 +77,7 @@ class TransactionBase {
|
|||||||
|
|
||||||
protected function getStateUserFromPublickey($publicKey) {
|
protected function getStateUserFromPublickey($publicKey) {
|
||||||
$stateUsersTable = self::getTable('state_users');
|
$stateUsersTable = self::getTable('state_users');
|
||||||
$stateUser = $stateUsersTable->find('all')->where(['public_key' => $publicKey])->first();
|
$stateUser = $stateUsersTable->find('all')->where(['pubkey' => $publicKey])->first();
|
||||||
if($stateUser) {
|
if($stateUser) {
|
||||||
return $stateUser;
|
return $stateUser;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,7 +95,7 @@ class TransactionCreation extends TransactionBase {
|
|||||||
$existingCreations2 = $this->transactionCreationsTable
|
$existingCreations2 = $this->transactionCreationsTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->select(['amount', 'state_user_id', 'target_date'])
|
->select(['amount', 'state_user_id', 'target_date'])
|
||||||
->contain(['StateUsers' => ['fields' => ['StateUsers.public_key']]]);
|
->contain(['StateUsers' => ['fields' => ['StateUsers.pubkey']]]);
|
||||||
$q = $existingCreations2;
|
$q = $existingCreations2;
|
||||||
$targetDate = $this->protoTransactionCreation->getTargetDate();
|
$targetDate = $this->protoTransactionCreation->getTargetDate();
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ class TransactionCreation extends TransactionBase {
|
|||||||
|
|
||||||
|
|
||||||
$receiverAmount = new \Proto\Gradido\TransferAmount();
|
$receiverAmount = new \Proto\Gradido\TransferAmount();
|
||||||
$receiverAmount->setPubkey(stream_get_contents($stateUser->public_key));
|
$receiverAmount->setPubkey(stream_get_contents($stateUser->pubkey));
|
||||||
$receiverAmount->setAmount($transactionCreationEntity->amount);
|
$receiverAmount->setAmount($transactionCreationEntity->amount);
|
||||||
|
|
||||||
$protoCreation->setReceiver($receiverAmount);
|
$protoCreation->setReceiver($receiverAmount);
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class TransactionTransfer extends TransactionBase {
|
|||||||
$user = $stateUsersTable
|
$user = $stateUsersTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->select(['id'])
|
->select(['id'])
|
||||||
->where(['public_key' => $senderPublic])
|
->where(['pubkey' => $senderPublic])
|
||||||
->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]])->first();
|
->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]])->first();
|
||||||
if(!$user) {
|
if(!$user) {
|
||||||
$this->addError($functionName, 'couldn\'t find sender in db' );
|
$this->addError($functionName, 'couldn\'t find sender in db' );
|
||||||
@ -114,7 +114,7 @@ class TransactionTransfer extends TransactionBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if receiver exist
|
// check if receiver exist
|
||||||
$receiver_user = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $receiver_public_key])->first();
|
$receiver_user = $stateUsersTable->find('all')->select(['id'])->where(['pubkey' => $receiver_public_key])->first();
|
||||||
if(!$receiver_user) {
|
if(!$receiver_user) {
|
||||||
$this->addError($functionName, 'couldn\'t find receiver in db' );
|
$this->addError($functionName, 'couldn\'t find receiver in db' );
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
56
database/migrations/0002-update_user.ts
Normal file
56
database/migrations/0002-update_user.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* FIRST MIGRATION
|
||||||
|
*
|
||||||
|
* This migration is special since it takes into account that
|
||||||
|
* the database can be setup already but also may not be.
|
||||||
|
* Therefore you will find all `CREATE TABLE` statements with
|
||||||
|
* a `IF NOT EXISTS`, all `INSERT` with an `IGNORE` and in the
|
||||||
|
* downgrade function all `DROP TABLE` with a `IF EXISTS`.
|
||||||
|
* This ensures compatibility for existing or non-existing
|
||||||
|
* databases.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||||
|
// write upgrade logic as parameter of queryFn
|
||||||
|
|
||||||
|
// rename table
|
||||||
|
await queryFn(`
|
||||||
|
ALTER TABLE state_users
|
||||||
|
RENAME TO user;
|
||||||
|
`)
|
||||||
|
// drop not used columns
|
||||||
|
await queryFn(`
|
||||||
|
ALTER TABLE user
|
||||||
|
DROP COLUMN index_id;
|
||||||
|
`)
|
||||||
|
// rename from snake case to camel case (cakePHP standard to typeorm standard)
|
||||||
|
await queryFn(`
|
||||||
|
ALTER TABLE user
|
||||||
|
CHANGE COLUMN group_id groupId int(10) unsigned NOT NULL DEFAULT '0',
|
||||||
|
CHANGE COLUMN public_key pubkey binary(32) NOT NULL,
|
||||||
|
CHANGE COLUMN first_name firstName varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||||
|
CHANGE COLUMN last_name lastName varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL;
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||||
|
// write downgrade logic as parameter of queryFn
|
||||||
|
// rename table
|
||||||
|
await queryFn(`
|
||||||
|
ALTER TABLE user
|
||||||
|
RENAME TO state_users;
|
||||||
|
`)
|
||||||
|
// put back dropped column
|
||||||
|
await queryFn(`
|
||||||
|
ALTER TABLE state_users
|
||||||
|
ADD index_id smallint(6) NOT NULL DEFAULT '0';
|
||||||
|
`)
|
||||||
|
// rename from camel case to snake case (typeorm standard to cakePHP standard)
|
||||||
|
await queryFn(`
|
||||||
|
ALTER TABLE state_users
|
||||||
|
CHANGE COLUMN groupId group_id int(10) unsigned NOT NULL DEFAULT '0',
|
||||||
|
CHANGE COLUMN pubkey public_key binary(32) NOT NULL,
|
||||||
|
CHANGE COLUMN firstName first_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||||
|
CHANGE COLUMN lastName last_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL;
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user