feat(server): business owned by user data model

This commit is contained in:
eneller
2026-07-23 14:28:20 +02:00
parent c876a45ef8
commit 0f4474d29b
15 changed files with 69 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
import express from 'express';
import { logger } from '../util/logging';
import { requireAuth } from '../util/auth';
import User from '../model/user';
import Account from '../model/user';
import { db } from '../util/db';
import Transaction from '../model/transaction';
import { SendRequest, SendResponse} from '../messages/Send';
@@ -12,9 +12,9 @@ const router = express.Router();
router.post('/', requireAuth, async (req, res) => {
try {
const sender = res.locals.user as User;
const sender = res.locals.user as Account;
const data : SendRequest = req.body;
const recipient = await User.findOne({where: {userID: data.recipientID}})
const recipient = await Account.findOne({where: {id: data.recipientID}})
if ( Number(data.amount) <= 0) {
return res.status(400).json(new Err('Invalid transfer amount'));
}
@@ -31,8 +31,8 @@ router.post('/', requireAuth, async (req, res) => {
await recipient.increment({balance: data.amount});
await Transaction.create({
amount: data.amount,
senderID: sender.userID,
receiverID: recipient.userID,
senderID: sender.id,
receiverID: recipient.id,
reference: data.reference
});
})