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