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
kresusapp
kresus
Commits
d03afa63
Commit
d03afa63
authored
Dec 24, 2019
by
Nicolas Frandeboeuf
Browse files
Alerts: add access name next to account's name (fix
#719
)
parent
7342ab6a
Pipeline
#199983
passed with stages
in 8 minutes and 22 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
server/lib/alert-manager.js
View file @
d03afa63
...
...
@@ -37,11 +37,12 @@ ${$t('server.email.signature')}
async
checkAlertsForOperations
(
userId
,
access
,
operations
)
{
try
{
// Map account to names
let
accessLabel
=
access
.
getLabel
();
let
accounts
=
await
Accounts
.
byAccess
(
userId
,
access
);
let
accountsMap
=
new
Map
();
for
(
let
a
of
accounts
)
{
accountsMap
.
set
(
a
.
id
,
{
label
:
displayLabel
(
a
),
label
:
`
${
accessLabel
}
–
${
displayLabel
(
a
)
}
`
,
formatCurrency
:
await
a
.
getCurrencyFormatter
()
});
}
...
...
@@ -91,6 +92,7 @@ ${$t('server.email.signature')}
async
checkAlertsForAccounts
(
userId
,
access
)
{
try
{
let
accounts
=
await
Accounts
.
byAccess
(
userId
,
access
);
let
accessLabel
=
access
.
getLabel
();
for
(
let
account
of
accounts
)
{
let
alerts
=
await
Alerts
.
byAccountAndType
(
userId
,
account
.
id
,
'
balance
'
);
if
(
!
alerts
)
{
...
...
@@ -106,7 +108,7 @@ ${$t('server.email.signature')}
// Set the currency formatter
let
formatCurrency
=
await
account
.
getCurrencyFormatter
();
let
text
=
alert
.
formatAccountMessage
(
displayLabel
(
account
),
`
${
accessLabel
}
–
${
displayLabel
(
account
)
}
`
,
balance
,
formatCurrency
);
...
...
server/lib/report-manager.js
View file @
d03afa63
...
...
@@ -10,6 +10,7 @@ import {
import
Emailer
from
'
./emailer
'
;
import
Accesses
from
'
../models/accesses
'
;
import
Accounts
from
'
../models/accounts
'
;
import
Alerts
from
'
../models/alerts
'
;
import
Transactions
from
'
../models/transactions
'
;
...
...
@@ -112,7 +113,12 @@ class ReportManager {
}
if
(
count
)
{
let
email
=
await
this
.
getTextContent
(
accounts
,
operationsByAccount
,
frequencyKey
);
let
email
=
await
this
.
getTextContent
(
userId
,
accounts
,
operationsByAccount
,
frequencyKey
);
let
{
subject
,
content
}
=
email
;
...
...
@@ -128,7 +134,7 @@ class ReportManager {
}
}
async
getTextContent
(
accounts
,
operationsByAccount
,
frequencyKey
)
{
async
getTextContent
(
userId
,
accounts
,
operationsByAccount
,
frequencyKey
)
{
let
frequency
;
switch
(
frequencyKey
)
{
case
'
daily
'
:
...
...
@@ -152,10 +158,17 @@ class ReportManager {
content
+=
$t
(
'
server.email.report.pre
'
,
{
today
});
content
+=
'
\n
'
;
let
accountsNameMap
=
new
Map
();
for
(
let
account
of
accounts
)
{
if
(
!
accountsNameMap
.
has
(
account
.
id
))
{
let
access
=
await
Accesses
.
find
(
userId
,
account
.
accessId
);
accountsNameMap
.
set
(
account
.
id
,
`
${
access
.
getLabel
()}
–
${
displayLabel
(
account
)}
`
);
}
let
lastCheckDate
=
formatDate
.
toShortString
(
account
.
lastCheckDate
);
let
balance
=
await
account
.
computeBalance
();
content
+=
`\t*
${
displayLabel
(
account
)}
: `
;
content
+=
`\t*
${
accountsNameMap
.
get
(
account
.
id
)}
: `
;
content
+=
`
${
account
.
formatCurrency
(
balance
)}
(`
;
content
+=
$t
(
'
server.email.report.last_sync
'
);
content
+=
`
${
lastCheckDate
}
)\n`
;
...
...
@@ -179,7 +192,7 @@ class ReportManager {
return
1
;
});
content
+=
`\n
${
displayLabel
(
pair
.
account
)}
:\n`
;
content
+=
`\n
${
accountsNameMap
.
get
(
pair
.
account
.
id
)}
:\n`
;
for
(
let
op
of
operations
)
{
let
date
=
formatDate
.
toShortString
(
op
.
date
);
content
+=
`\t*
${
date
}
-
${
op
.
label
}
: `
;
...
...
server/models/pouch/accesses.js
View file @
d03afa63
import
*
as
cozydb
from
'
cozydb
'
;
import
AccessFields
from
'
./access-fields
'
;
import
{
bankVendorByUuid
}
from
'
../../lib/bank-vendors
'
;
import
{
assert
,
makeLogger
,
promisify
,
promisifyModel
,
FETCH_STATUS_SUCCESS
}
from
'
../../helpers
'
;
...
...
@@ -153,4 +154,13 @@ Access.prototype.canBePolled = function() {
);
};
// Returns the access name
Access
.
prototype
.
getLabel
=
function
()
{
if
(
this
.
customLabel
)
{
return
this
.
customLabel
;
}
return
bankVendorByUuid
(
this
.
vendorId
).
name
;
};
module
.
exports
=
Access
;
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