[notification] add notification

This commit is contained in:
Tim Gröger 2021-11-27 00:38:01 +01:00
parent b4a607b620
commit 9c1b7eb9e1
3 changed files with 52 additions and 7 deletions

17
src/balance.d.ts vendored Normal file
View File

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

View File

@ -1,13 +1,41 @@
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: 'balance',
id: 'dev.flaschengeist.balance',
name: 'Balance',
innerRoutes: routes,
requiredModules: [['balance']],
version: '0.0.2',
notification: transpile,
widgets: [
{
priority: 0,

View File

@ -77,9 +77,9 @@ export const useBalanceStore = defineStore({
return data;
},
async getBalances(filter?: {limit?: number, offset?: number, sortBy?: string, descending?: boolean}) {
const { data } = await api.get<{balances: BalancesResponse[], count: number}>('/balance', {
params: filter
async getBalances(filter?: { limit?: number; offset?: number; sortBy?: string; descending?: boolean }) {
const { data } = await api.get<{ balances: BalancesResponse[]; count: number }>('/balance', {
params: filter,
});
this.balances = data.balances;
return { balances: this.balances, count: data.count };
@ -160,7 +160,7 @@ export const useBalanceStore = defineStore({
async getLimits(filter?: { userids: undefined | string }) {
const { data } = await api.get<Array<UserLimit>>('users/balance/limit', {
params: filter
params: filter,
});
this.user_limits = data;
},