[notification] add notification
This commit is contained in:
parent
b4a607b620
commit
9c1b7eb9e1
|
@ -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);
|
||||
}
|
30
src/index.ts
30
src/index.ts
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue