pull transactions from db

test
dan 2019-11-24 14:40:19 -07:00
parent 2782a729f0
commit 99f8c96590
12 changed files with 112 additions and 31 deletions

View File

@ -1,4 +1,4 @@
<app-contributor-yearly-report *ngFor="let c of contributors; let i = index" [index]="i">
<app-contributor-yearly-report *ngFor="let c of contributors; let i = index" [index]="i" [contributorTransactions]="c">
</app-contributor-yearly-report>

View File

@ -1,5 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { PrintService } from 'src/app/services/print-service';
import { UserService } from 'src/app/services/user.service';
import { TransactionService } from 'src/app/services/transaction.service';
import { forkJoin } from 'rxjs';
@Component({
selector: 'app-contributor-all-reports',
@ -8,14 +11,36 @@ import { PrintService } from 'src/app/services/print-service';
})
export class ContributorAllReportsComponent implements OnInit {
public contributors: number[] = [];
public contributors: {contributor:{}, transactions:[]}[] = [];
constructor(private printService: PrintService) { }
constructor(private printService: PrintService, private userService: UserService, private transactionService: TransactionService) { }
ngOnInit() {
this.contributors.push(1);
this.contributors.push(2);
const query = forkJoin([this.userService.getAll(), this.transactionService.getByYear(2019)]);
query.subscribe(res => this.setup(res[0], res[1]));
this.printService.setPrinting(true);
}
private setup(contributorResult, transactionResult) {
const contributors = contributorResult.users;
const transactions = transactionResult.transactions;
const contrib = {};
transactions.forEach(t => {
if (contrib.hasOwnProperty(t.contributorId)) {
contrib[t.contributorId].transactions.push(t);
} else {
const con = contributors.find(c => c.id === t.contributorId);
if (con) {
contrib[con.id] = {contributor: con, transactions: [t]};
this.contributors.push(contrib[con.id]);
} else {
console.error('coould not find contributor for', t);
}
}
});
}
}

View File

@ -10,6 +10,7 @@ import { Transaction } from '../add-transaction-page/transaction';
export class ContributorYearlyReportComponent implements OnInit {
@Input() index: number;
@Input() contributorTransactions: {contributor: {}, transactions: {}};
public transactions: Transaction[] = [];
public contributorName: string = 'Bob and Jill Handerson';
public contributorStreet: string = '7878 Washington St';
@ -30,30 +31,13 @@ export class ContributorYearlyReportComponent implements OnInit {
constructor(public printService: PrintService) { }
ngOnInit() {
const t = new Transaction();
t.amount = 100;
t.checkNumber = '3434';
t.contributorId = 45;
t.date = '2019-10-20';
t.description = 'Some description';
t.fundId = 1;
t.goodsOrServices = false;
t.taxYear = 2019;
t.typeId = 1;
for(let i = 0; i < 90; i++) {
const t2 = new Transaction();
t2.amount = 300;
t2.checkNumber = 'ghff';
t2.contributorId = 45;
t2.date = '2019-10-23';
t2.description = 'Missionary Family';
t2.fundId = 2;
t2.goodsOrServices = false;
t2.taxYear = 2019;
t2.typeId = 2;
this.transactions.push(t2);
}
this.transactions.push(t);
this.contributorCity = (<any>this.contributorTransactions.contributor).city;
this.contributorName = (<any>this.contributorTransactions.contributor).display;
this.contributorState = (<any>this.contributorTransactions.contributor).state;
this.contributorStreet = (<any>this.contributorTransactions.contributor).street;
this.contributorZip = (<any>this.contributorTransactions.contributor).zip;
this.transactions = <any>this.contributorTransactions.transactions;
}
public totalGeneral() {

View File

@ -14,6 +14,7 @@ export const SERMON_DELETE_URL = environment.baseUrl + "/api2/sermons/a/";
export const SERMON_UPDATE_URL = environment.baseUrl + "/api2/sermons/a/";
export const SERMON_DOWNLOAD_URL = environment.baseUrl + "/api2/sermons/download/";
export const TRANSACTION_CREATE_URL = environment.baseUrl + "/api2/transactions/a/";
export const TRANSACTION_GET_BY_YEAR_URL = environment.baseUrl + "/api2/transactions/a/";
export const USER_CREATE_URL = environment.baseUrl + "/api2/users/a/";
export const USER_GET_ALL_URL = environment.baseUrl + "/api2/users/a";
export const LOGIN_URL = environment.baseUrl + '/api2/login';

View File

@ -4,7 +4,7 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable, Subject, throwError, of } from 'rxjs';
import { catchError, map, tap, first } from 'rxjs/operators';
import { TRANSACTION_CREATE_URL } from '../constants/urls';
import { TRANSACTION_CREATE_URL, TRANSACTION_GET_BY_YEAR_URL } from '../constants/urls';
import { Transaction } from '../components/add-transaction-page/transaction';
@Injectable()
@ -41,6 +41,11 @@ export class TransactionService {
.pipe(tap(res => console.log(res)), catchError(this.handleError));
}
getByYear(taxYear: number) {
return this.httpClient.get(TRANSACTION_GET_BY_YEAR_URL + "?taxYear=" + taxYear, this.options)
.pipe(catchError(this.handleError));
}
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.

View File

@ -10,6 +10,10 @@ const path = require('path');
const { execFile } = require('child_process');
const fs = require('fs');
const cors = require('cors');
app.use(cors({origin:'http://localhost:4200', credentials: true}));
app.options('*', cors());
app.get('/secret',function(req,res){
res.json("You found the secret!");
});

View File

@ -22,6 +22,29 @@ exports.getAll = async function() {
return result;
}
exports.getByYear = async function(taxYear) {
const queryResult = await connectionAsync.query('SELECT * FROM Transactions WHERE DeletedDate IS NULL AND TaxYear = ?;', taxYear);
const result = [];
if (queryResult && queryResult.rows && queryResult.rows.length > 0) {
for(var i = 0 ; i < queryResult.rows.length; i++) {
const row = queryResult.rows[i];
const trans = {};
trans.id = row.Id;
trans.date = row.Date;
trans.typeId = row.TypeId;
trans.checkNumber = row.CheckNumber;
trans.contributorId = row.ContributorId;
trans.fundId = row.FundId;
trans.description = row.Description;
trans.amount = row.Amount;
trans.taxYear = row.TaxYear;
trans.goodsOrServices = row.GoodsOrServices == 1 ? true : false;
result.push(trans);
}
}
return result;
}
exports.addArray = async function(transactions) {
let conn = null;
try {

View File

@ -68,6 +68,7 @@ function rowToUser(row) {
user.street = row.Street;
user.city = row.City;
user.state = row.State;
user.zip = row.Zip;
user.country = row.Country;
user.emailVerified = row.EmailVerified;
user.emailVerificationCode = row.EmailVerificationCode;

View File

@ -146,6 +146,22 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
},
"dependencies": {
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
}
}
},
"crypto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",

View File

@ -12,6 +12,7 @@
"async": "^2.5.0",
"body-parser": "^1.18.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"express": "^4.15.4",
"moment-timezone": "^0.5.13",

View File

@ -14,4 +14,17 @@ router.post("/a/",async function(req,res) {
res.status(200).json({"status":200,"message":"transactions added","result":result});
});
router.get("/a/", async function(req, res) {
if (!res.locals.user || !res.locals.user.canDo || !res.locals.user.canDo('user_add')) {
res.status(401).json({"status":401,"message":"you are not authorized to add a transaction"});
return;
}
var trans = [];
if (req.query.taxYear) {
trans = await dbTransactions.getByYear(req.query.taxYear);
}
res.status(201).json({"status":201,"message":"transactions for " + req.query.taxYear,"transactions":trans});
});
module.exports = router;

View File

@ -12,8 +12,16 @@ router.get("/a/", async function(req, res) {
const users = await dbUsers.getAll();
const usersRes = users.map(x => {
return {
id: x.id,
value: x.id,
display: `${x.lastName} ${x.firstName}`
display: `${x.lastName} ${x.firstName}`,
street: x.street,
city: x.city,
state: x.state,
country: x.country,
zip: x.zip,
firstName: x.firstName,
lastName: x.lastName
};
});
res.status(201).json({"status":201,"message":"all users","users":usersRes});