fix notifications, add notification when authorized person do debit or credit

This commit is contained in:
Tim Gröger 2023-05-10 01:11:09 +02:00
parent a876f99e13
commit 345227f5d4
2 changed files with 14 additions and 5 deletions

7
src/balance.d.ts vendored
View File

@ -2,16 +2,19 @@ import { FG_Plugin } from '@flaschengeist/types';
export interface SendFromNotification { export interface SendFromNotification {
receiver_id: string; receiver_id: string;
author_id: string;
} }
export interface SendToNotification { export interface SendToNotification {
sender_id: string; sender_id: string;
} }
export interface TransactionNotification {
author_id: string;
}
export interface BalanceNotification extends FG_Plugin.Notification { export interface BalanceNotification extends FG_Plugin.Notification {
data: { data: {
type: number; type: number;
amount: number; amount: number;
} & (SendFromNotification | SendToNotification); } & (SendFromNotification | SendToNotification | TransactionNotification);
} }

View File

@ -1,12 +1,14 @@
import { FG_Plugin } from '@flaschengeist/types'; import { FG_Plugin } from '@flaschengeist/types';
import { defineAsyncComponent } from 'vue'; import { defineAsyncComponent } from 'vue';
import routes from './routes'; import routes from './routes';
import { BalanceNotification, SendFromNotification, SendToNotification } from 'app/balance'; import { BalanceNotification, SendFromNotification, SendToNotification, TransactionNotification } from 'app/balance';
import { useUserStore } from '@flaschengeist/api'; import { useUserStore } from '@flaschengeist/api';
const BalanceTypes = { const BalanceTypes = {
send_to: 0x01, send_to: 0x01,
send_from: 0x02, send_from: 0x02,
add_from: 0x03,
sub_from: 0x04,
}; };
function transpile(msg: FG_Plugin.Notification) { function transpile(msg: FG_Plugin.Notification) {
@ -21,16 +23,20 @@ function transpile(msg: FG_Plugin.Notification) {
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${ message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${
receiver.display_name receiver.display_name
} überwiesen.`; } überwiesen.`;
} else { } else if (message.data.type === BalanceTypes.send_to) {
const sender = <FG.User>store.findUser((<SendToNotification>message.data).sender_id); const sender = <FG.User>store.findUser((<SendToNotification>message.data).sender_id);
console.log(sender); console.log(sender);
message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`; message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`;
} else {
const author = <FG.User>store.findUser((<TransactionNotification>message.data).author_id);
const abgebucht = message.data.type === BalanceTypes.add_from ? 'aufgeladen' : 'abgebucht';
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ dir ${abgebucht}.`;
} }
return message; return message;
} }
const plugin: FG_Plugin.Plugin = { const plugin: FG_Plugin.Plugin = {
id: 'dev.flaschengeist.balance', id: 'balance',
name: 'Balance', name: 'Balance',
innerRoutes: routes, innerRoutes: routes,
requiredModules: [['balance']], requiredModules: [['balance']],