[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 { 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 { 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 = {
|
const plugin: FG_Plugin.Plugin = {
|
||||||
id: 'balance',
|
id: 'dev.flaschengeist.balance',
|
||||||
name: 'Balance',
|
name: 'Balance',
|
||||||
innerRoutes: routes,
|
innerRoutes: routes,
|
||||||
requiredModules: [['balance']],
|
requiredModules: [['balance']],
|
||||||
version: '0.0.2',
|
version: '0.0.2',
|
||||||
|
notification: transpile,
|
||||||
widgets: [
|
widgets: [
|
||||||
{
|
{
|
||||||
priority: 0,
|
priority: 0,
|
||||||
|
|
12
src/store.ts
12
src/store.ts
|
@ -77,12 +77,12 @@ export const useBalanceStore = defineStore({
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getBalances(filter?: {limit?: number, offset?: number, sortBy?: string, descending?: boolean}) {
|
async getBalances(filter?: { limit?: number; offset?: number; sortBy?: string; descending?: boolean }) {
|
||||||
const { data } = await api.get<{balances: BalancesResponse[], count: number}>('/balance', {
|
const { data } = await api.get<{ balances: BalancesResponse[]; count: number }>('/balance', {
|
||||||
params: filter
|
params: filter,
|
||||||
});
|
});
|
||||||
this.balances = data.balances;
|
this.balances = data.balances;
|
||||||
return {balances: this.balances, count: data.count};
|
return { balances: this.balances, count: data.count };
|
||||||
},
|
},
|
||||||
|
|
||||||
async changeBalance(amount: number, user: FG.User, sender: FG.User | undefined = undefined) {
|
async changeBalance(amount: number, user: FG.User, sender: FG.User | undefined = undefined) {
|
||||||
|
@ -158,9 +158,9 @@ export const useBalanceStore = defineStore({
|
||||||
this._balances_dirty = 0;
|
this._balances_dirty = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getLimits(filter?: {userids: undefined|string}) {
|
async getLimits(filter?: { userids: undefined | string }) {
|
||||||
const { data } = await api.get<Array<UserLimit>>('users/balance/limit', {
|
const { data } = await api.get<Array<UserLimit>>('users/balance/limit', {
|
||||||
params: filter
|
params: filter,
|
||||||
});
|
});
|
||||||
this.user_limits = data;
|
this.user_limits = data;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue