feat: db
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
<i class="bi bi-person-fill fs-4 text-secondary"></i>
|
||||
</div>
|
||||
<div class="text-start">
|
||||
<h6 class="mb-0">{{ transaction.partner }}</h6>
|
||||
<h6 class="mb-0">{{ transaction.sender }}</h6>
|
||||
<small class="text-muted">{{ transaction.date | date:'medium' }}</small>
|
||||
</div>
|
||||
</div>
|
||||
@@ -35,7 +35,6 @@
|
||||
<h6 class="mb-0" [class.text-success]="transaction.amount > 0" [class.text-danger]="transaction.amount < 0">
|
||||
{{ transaction.amount | currency }}
|
||||
</h6>
|
||||
<small class="text-muted">{{ transaction.type }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CommonModule, CurrencyPipe, DatePipe } from '@angular/common';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { APIService } from '../../services/api';
|
||||
import { Transaction } from '@shared/interfaces/transaction';
|
||||
import Transaction from '@model/transaction';
|
||||
|
||||
@Component({
|
||||
selector: 'app-screen-profile',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Transaction } from '@shared/interfaces/transaction'
|
||||
import Transaction from '@model/transaction'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
|
||||
@@ -5,6 +5,8 @@ services:
|
||||
POSTGRES_PASSWORD: pass
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- ./.docker:/var/lib/postgresql
|
||||
|
||||
adminer:
|
||||
image: adminer
|
||||
|
||||
@@ -4,22 +4,22 @@ import User from './user';
|
||||
@Table
|
||||
export default class Transaction extends Model{
|
||||
@Column
|
||||
amount: number;
|
||||
amount!: number;
|
||||
|
||||
@Column
|
||||
@ForeignKey(()=> User)
|
||||
senderID: string;
|
||||
senderID!: string;
|
||||
|
||||
@BelongsTo(() => User, 'senderID')
|
||||
sender: User;
|
||||
sender!: User;
|
||||
|
||||
@Column
|
||||
@ForeignKey(()=> User)
|
||||
receiverID: string;
|
||||
receiverID!: string;
|
||||
|
||||
@BelongsTo(() => User, 'receiverID')
|
||||
receiver: User;
|
||||
receiver!: User;
|
||||
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
date!: Date;
|
||||
}
|
||||
@@ -4,18 +4,18 @@ import { Table, Column, Model, CreatedAt, DataType} from 'sequelize-typescript';
|
||||
export default class User extends Model{
|
||||
|
||||
@Column({primaryKey: true, unique: true, allowNull: false})
|
||||
userID: string;
|
||||
userID!: string;
|
||||
|
||||
@Column
|
||||
displayName: string;
|
||||
displayName!: string;
|
||||
|
||||
@Column(DataType.DECIMAL(20,2))
|
||||
balance: number;
|
||||
balance!: number;
|
||||
|
||||
@Column
|
||||
password: string;
|
||||
password!: string;
|
||||
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
creationDate!: Date;
|
||||
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
import express from 'express';
|
||||
import { Transaction } from "@shared/interfaces/transaction"
|
||||
import Transaction from '../model/transaction';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Mock data
|
||||
const mockTransactions: Transaction[] = [
|
||||
{ id: '1', partner: 'Alice Smith', amount: 50.00, date: new Date('2026-03-01'), type: 'Received' },
|
||||
{ id: '2', partner: 'Bob Johnson', amount: -25.50, date: new Date('2026-02-28'), type: 'Sent' },
|
||||
];
|
||||
|
||||
// GET /api/transactions
|
||||
router.get('/', (req, res) => {
|
||||
res.json(mockTransactions);
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const transactions = await Transaction.findAll({ limit: 10 });
|
||||
res.json(transactions);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch transactions:', err);
|
||||
res.status(500).json({ error: 'Failed to fetch transactions' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"module": "es2022",
|
||||
"lib": ["es2022", "dom"],
|
||||
"paths": {
|
||||
"@shared/*": ["shared/src/*"]
|
||||
"@model/*": ["server/src/model/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
Reference in New Issue
Block a user