flaschengeist-balance/src/index.ts

50 lines
1.6 KiB
TypeScript

import { FG_Plugin } from '@flaschengeist/types';
import { defineAsyncComponent } from 'vue';
import routes from './routes';
import { BalanceNotification, SendFromNotification, SendToNotification } from 'app/balance';
import { useUserStore } from '@flaschengeist/api';
const BalanceTypes = {
send_to: 0x01,
send_from: 0x02,
};
function transpile(msg: FG_Plugin.Notification) {
console.log('notification:', msg);
const message = msg as BalanceNotification;
message.icon = 'mdi-cash';
const store = useUserStore();
void store.getUsers();
if (message.data.type === BalanceTypes.send_from) {
const receiver = <FG.User>store.findUser((<SendFromNotification>message.data).receiver_id);
const author = <FG.User>store.findUser((<SendFromNotification>message.data).author_id);
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${
receiver.display_name
} überwiesen.`;
} else {
const sender = <FG.User>store.findUser((<SendToNotification>message.data).sender_id);
console.log(sender);
message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`;
}
return message;
}
const plugin: FG_Plugin.Plugin = {
id: 'dev.flaschengeist.balance',
name: 'Balance',
innerRoutes: routes,
requiredModules: [['balance']],
version: '0.0.2',
notification: transpile,
widgets: [
{
priority: 0,
name: 'current',
permissions: ['balance_show'],
widget: defineAsyncComponent(() => import('./components/Widget.vue')),
},
],
};
export default plugin;