Skip to content
Snippets Groups Projects
Select Git revision
  • aba7fafb4c9387ef91403573eb40b4d372dffdd9
  • master default protected
  • forbid-save-as
  • upload-via-token
  • moodle-integration
  • patch-double-tap-seek
  • patch_datum_anzeigen
  • patch_raum_anzeigen
  • intros
  • live_sources
  • bootstrap4
  • modules
12 results

config.py.example

Blame
  • Forked from Video AG Infrastruktur / website
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    transactions.js 1.17 KiB
    import { db } from "$lib/server/database";
    
    export async function buyArticles(userId, card, items, noBalance=false) {
    	const [user, ...itemTransactions] = await db.$transaction([
    		db.user.update({
    			where: { id: userId },
    			data: {
    				balance: {
    					decrement: noBalance===true ? 0 : items.reduce((sum, item) => sum + item.price + item.premium, 0)
    				},
    			}
    		}),
    		...items.map(item => db.item.update({
    			where: { code: item.code },
    			data: {
    				stock: { decrement: 1 },
    				bought: { increment: 1 },
    				transactions: {
    					create: {
    						price: item.price,
    						premium: item.premium,
    						card,
    						user: { connect: { id: userId } }
    					}
    				}
    			}
    		}))
    	]);
    	return { user, itemTransactions };
    }
    
    export async function transferMoney(fromId, card, toId, amount){
    	const [to, from] = await db.$transaction([
    		db.user.update({
    			where: { id: toId },
    			data: {
    				balance: {
    					increment: amount
    				},
    				moneyTransfersReceived: {
    					create: {
    						amount,
    						card,
    						from: { connect: { id: fromId } }
    					}
    				}
    			}
    		}),
    		db.user.update({
    			where: { id: fromId },
    			data: {
    				balance: {
    					decrement: amount
    				}
    			}
    		})
    	]);
    	return { to, from };
    }