Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Luc Didry
kresus
Commits
7e3d8b08
Commit
7e3d8b08
authored
Apr 22, 2019
by
Benjamin Bouvier
Browse files
Add validation checks for Account update;
parent
6c3a0e5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
client/store/backend.js
View file @
7e3d8b08
...
...
@@ -99,22 +99,28 @@ export function deleteOperation(opId) {
});
}
export
function
resyncBalance
(
accountId
)
{
return
buildFetchPromise
(
`api/
${
API_VERSION
}
/accounts/
${
accountId
}
/resync-balance`
).
then
(
data
=>
data
.
initialBalance
);
}
export
function
updateAccount
(
accountId
,
newFields
)
{
let
error
=
checkAllowedFields
(
newFields
,
[
'
excludeFromBalance
'
,
'
customLabel
'
]);
if
(
error
)
{
alert
(
`Developer error when updating an account:
${
error
}
`
);
return
;
}
export
function
updateAccount
(
accountId
,
attributes
)
{
return
buildFetchPromise
(
`api/
${
API_VERSION
}
/accounts/
${
accountId
}
`
,
{
method
:
'
PUT
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
attribute
s
)
body
:
JSON
.
stringify
(
newField
s
)
});
}
export
function
resyncBalance
(
accountId
)
{
return
buildFetchPromise
(
`api/
${
API_VERSION
}
/accounts/
${
accountId
}
/resync-balance`
).
then
(
data
=>
data
.
initialBalance
);
}
export
function
deleteAccount
(
accountId
)
{
return
buildFetchPromise
(
`api/
${
API_VERSION
}
/accounts/
${
accountId
}
`
,
{
method
:
'
DELETE
'
...
...
server/controllers/v1/accounts.js
View file @
7e3d8b08
...
...
@@ -7,6 +7,7 @@ import Transactions from '../../models/transactions';
import
accountManager
from
'
../../lib/accounts-manager
'
;
import
{
makeLogger
,
KError
,
asyncErr
}
from
'
../../helpers
'
;
import
{
checkAllowedFields
}
from
'
../../shared/validators
'
;
let
log
=
makeLogger
(
'
controllers/accounts
'
);
...
...
@@ -53,23 +54,18 @@ export async function destroyWithOperations(userId, account) {
}
}
// Update an account.
export
async
function
update
(
req
,
res
)
{
try
{
let
{
id
:
userId
}
=
req
.
user
;
let
attr
=
req
.
body
;
// We can only update the flag excludeFromBalance
// and the custom label of an account.
if
(
typeof
attr
.
excludeFromBalance
===
'
undefined
'
&&
typeof
attr
.
customLabel
===
'
undefined
'
)
{
throw
new
KError
(
'
Missing parameter
'
,
400
);
let
newFields
=
req
.
body
;
let
error
=
checkAllowedFields
(
newFields
,
[
'
excludeFromBalance
'
,
'
customLabel
'
]);
if
(
error
)
{
throw
new
KError
(
`when updating an account:
${
error
}
`
,
400
);
}
let
account
=
req
.
preloaded
.
account
;
let
newAccount
=
await
Accounts
.
update
(
userId
,
account
.
id
,
attr
);
let
newAccount
=
await
Accounts
.
update
(
userId
,
account
.
id
,
newFields
);
res
.
status
(
200
).
json
(
newAccount
);
}
catch
(
err
)
{
return
asyncErr
(
res
,
err
,
'
when updating an account
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment