Skip to content

Commit

Permalink
updating multiple bank records
Browse files Browse the repository at this point in the history
closes #137
  • Loading branch information
dangowans committed Nov 19, 2020
1 parent 4bef8d0 commit c0f2cfe
Show file tree
Hide file tree
Showing 71 changed files with 1,090 additions and 3,876 deletions.
19 changes: 0 additions & 19 deletions .snyk

This file was deleted.

2 changes: 2 additions & 0 deletions handlers/organizations-post/doAddBankRecord.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
19 changes: 19 additions & 0 deletions handlers/organizations-post/doAddBankRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const addOrganizationBankRecord_1 = require("../../helpers/licencesDB/addOrganizationBankRecord");
exports.handler = (req, res) => {
const success = addOrganizationBankRecord_1.addOrganizationBankRecord(req.body, req.session);
if (success) {
return res.json({
success: true,
message: "Record added successfully."
});
}
else {
return res.json({
success: false,
message: "Please make sure that the record you are trying to create does not already exist."
});
}
};
25 changes: 25 additions & 0 deletions handlers/organizations-post/doAddBankRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { RequestHandler } from "express";

import { addOrganizationBankRecord } from "../../helpers/licencesDB/addOrganizationBankRecord";


export const handler: RequestHandler = (req, res) => {

const success = addOrganizationBankRecord(req.body, req.session);

if (success) {

return res.json({
success: true,
message: "Record added successfully."
});

} else {

return res.json({
success: false,
message: "Please make sure that the record you are trying to create does not already exist."
});

}
};
2 changes: 2 additions & 0 deletions handlers/organizations-post/doDeleteBankRecord.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
19 changes: 19 additions & 0 deletions handlers/organizations-post/doDeleteBankRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const deleteOrganizationBankRecord_1 = require("../../helpers/licencesDB/deleteOrganizationBankRecord");
exports.handler = (req, res) => {
const success = deleteOrganizationBankRecord_1.deleteOrganizationBankRecord(req.body.organizationID, req.body.recordIndex, req.session);
if (success) {
res.json({
success: true,
message: "Organization updated successfully."
});
}
else {
res.json({
success: false,
message: "Record Not Saved"
});
}
};
22 changes: 22 additions & 0 deletions handlers/organizations-post/doDeleteBankRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { RequestHandler } from "express";

import { deleteOrganizationBankRecord } from "../../helpers/licencesDB/deleteOrganizationBankRecord";


export const handler: RequestHandler = (req, res) => {

const success =
deleteOrganizationBankRecord(req.body.organizationID, req.body.recordIndex, req.session);

if (success) {
res.json({
success: true,
message: "Organization updated successfully."
});
} else {
res.json({
success: false,
message: "Record Not Saved"
});
}
};
2 changes: 2 additions & 0 deletions handlers/organizations-post/doEditBankRecord.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
19 changes: 19 additions & 0 deletions handlers/organizations-post/doEditBankRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const updateOrganizationBankRecord_1 = require("../../helpers/licencesDB/updateOrganizationBankRecord");
exports.handler = (req, res) => {
const success = updateOrganizationBankRecord_1.updateOrganizationBankRecord(req.body, req.session);
if (success) {
return res.json({
success: true,
message: "Record updated successfully."
});
}
else {
return res.json({
success: false,
message: "Please try again."
});
}
};
25 changes: 25 additions & 0 deletions handlers/organizations-post/doEditBankRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { RequestHandler } from "express";

import { updateOrganizationBankRecord } from "../../helpers/licencesDB/updateOrganizationBankRecord";


export const handler: RequestHandler = (req, res) => {

const success = updateOrganizationBankRecord(req.body, req.session);

if (success) {

return res.json({
success: true,
message: "Record updated successfully."
});

} else {

return res.json({
success: false,
message: "Please try again."
});

}
};
2 changes: 2 additions & 0 deletions handlers/organizations-post/doUpdateBankRecordsByMonth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
69 changes: 69 additions & 0 deletions handlers/organizations-post/doUpdateBankRecordsByMonth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const addOrganizationBankRecord_1 = require("../../helpers/licencesDB/addOrganizationBankRecord");
const updateOrganizationBankRecord_1 = require("../../helpers/licencesDB/updateOrganizationBankRecord");
const deleteOrganizationBankRecord_1 = require("../../helpers/licencesDB/deleteOrganizationBankRecord");
const bankRecordIsBlank = (bankRecord) => {
if (bankRecord.recordDateString === "" && bankRecord.recordNote === "" && !bankRecord.recordIsNA) {
return true;
}
return false;
};
exports.handler = (req, res) => {
const organizationID = parseInt(req.body.organizationID, 10);
const accountNumber = req.body.accountNumber;
const bankingYear = parseInt(req.body.bankingYear, 10);
const bankingMonth = parseInt(req.body.bankingMonth, 10);
const maxBankRecordTypeIndex = parseInt(req.body.bankRecordTypeIndex, 10);
let success = true;
for (let typeIndex = 0; typeIndex <= maxBankRecordTypeIndex; typeIndex += 1) {
const typeIndexString = typeIndex.toString();
const recordIndex = (req.body["recordIndex-" + typeIndexString] === "" ? null : parseInt(req.body["recordIndex-" + typeIndexString], 10));
const bankRecord = {
recordType: "bankRecord",
organizationID,
accountNumber,
bankingYear,
bankingMonth,
recordIndex,
bankRecordType: req.body["bankRecordType-" + typeIndexString],
recordDateString: req.body["recordDateString-" + typeIndexString],
recordNote: req.body["recordNote-" + typeIndexString],
recordIsNA: (req.body["recordIsNA-" + typeIndexString] === "1")
};
if (req.body["recordIndex-" + typeIndexString] === "") {
if (!bankRecordIsBlank(bankRecord)) {
const addSuccess = addOrganizationBankRecord_1.addOrganizationBankRecord(bankRecord, req.session);
if (!addSuccess) {
success = false;
}
}
}
else {
if (bankRecordIsBlank(bankRecord)) {
const deleteSuccess = deleteOrganizationBankRecord_1.deleteOrganizationBankRecord(organizationID, recordIndex, req.session);
if (!deleteSuccess) {
success = false;
}
}
else {
const updateSuccess = updateOrganizationBankRecord_1.updateOrganizationBankRecord(bankRecord, req.session);
if (!updateSuccess) {
success = false;
}
}
}
}
if (success) {
return res.json({
success: true
});
}
else {
return res.json({
success: false,
message: "Please try again."
});
}
};
86 changes: 86 additions & 0 deletions handlers/organizations-post/doUpdateBankRecordsByMonth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { RequestHandler } from "express";

import { addOrganizationBankRecord } from "../../helpers/licencesDB/addOrganizationBankRecord";
import { updateOrganizationBankRecord } from "../../helpers/licencesDB/updateOrganizationBankRecord";
import { deleteOrganizationBankRecord } from "../../helpers/licencesDB/deleteOrganizationBankRecord";

import type * as llm from "../../types/recordTypes";


const bankRecordIsBlank = (bankRecord: llm.OrganizationBankRecord) => {

if (bankRecord.recordDateString === "" && bankRecord.recordNote === "" && !bankRecord.recordIsNA) {
return true;
}
return false;
};


export const handler: RequestHandler = (req, res) => {

const organizationID = parseInt(req.body.organizationID, 10);
const accountNumber = req.body.accountNumber;
const bankingYear = parseInt(req.body.bankingYear, 10);
const bankingMonth = parseInt(req.body.bankingMonth, 10);

const maxBankRecordTypeIndex = parseInt(req.body.bankRecordTypeIndex, 10);

let success = true;

for (let typeIndex = 0; typeIndex <= maxBankRecordTypeIndex; typeIndex += 1) {

const typeIndexString = typeIndex.toString();

const recordIndex = (req.body["recordIndex-" + typeIndexString] === "" ? null : parseInt(req.body["recordIndex-" + typeIndexString], 10));

const bankRecord: llm.OrganizationBankRecord = {
recordType: "bankRecord",
organizationID,
accountNumber,
bankingYear,
bankingMonth,
recordIndex,
bankRecordType: req.body["bankRecordType-" + typeIndexString],
recordDateString: req.body["recordDateString-" + typeIndexString],
recordNote: req.body["recordNote-" + typeIndexString],
recordIsNA: (req.body["recordIsNA-" + typeIndexString] === "1")
};

if (req.body["recordIndex-" + typeIndexString] === "") {

if (!bankRecordIsBlank(bankRecord)) {
const addSuccess = addOrganizationBankRecord(bankRecord, req.session);
if (!addSuccess) {
success = false;
}
}

} else {

if (bankRecordIsBlank(bankRecord)) {
const deleteSuccess = deleteOrganizationBankRecord(organizationID, recordIndex, req.session);
if (!deleteSuccess) {
success = false;
}
} else {
const updateSuccess = updateOrganizationBankRecord(bankRecord, req.session);
if (!updateSuccess) {
success = false;
}
}
}
}

if (success) {
return res.json({
success: true
});

} else {
return res.json({
success: false,
message: "Please try again."
});
}

};
26 changes: 12 additions & 14 deletions helpers/licencesDB-organizations.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type * as llm from "../types/recordTypes";
export declare const createOrganization: (reqBody: llm.Organization, reqSession: any) => number;
export declare const updateOrganization: (reqBody: llm.Organization, reqSession: any) => boolean;
export declare const deleteOrganization: (organizationID: number, reqSession: any) => boolean;
export declare const restoreOrganization: (organizationID: number, reqSession: any) => boolean;
import type * as expressSession from "express-session";
export declare const createOrganization: (reqBody: llm.Organization, reqSession: expressSession.Session) => number;
export declare const updateOrganization: (reqBody: llm.Organization, reqSession: expressSession.Session) => boolean;
export declare const deleteOrganization: (organizationID: number, reqSession: expressSession.Session) => boolean;
export declare const restoreOrganization: (organizationID: number, reqSession: expressSession.Session) => boolean;
export declare const getInactiveOrganizations: (inactiveYears: number) => llm.Organization[];
export declare const getDeletedOrganizations: () => llm.Organization[];
export declare const deleteOrganizationRepresentative: (organizationID: number, representativeIndex: number) => boolean;
export declare const setDefaultOrganizationRepresentative: (organizationID: number, representativeIndex: number) => boolean;
export declare const getOrganizationRemark: (organizationID: number, remarkIndex: number, reqSession: any) => llm.OrganizationRemark;
export declare const addOrganizationRemark: (reqBody: llm.OrganizationRemark, reqSession: any) => number;
export declare const updateOrganizationRemark: (reqBody: llm.OrganizationRemark, reqSession: any) => boolean;
export declare const deleteOrganizationRemark: (organizationID: number, remarkIndex: number, reqSession: any) => boolean;
export declare const getOrganizationReminder: (organizationID: number, reminderIndex: number, reqSession: any) => llm.OrganizationReminder;
export declare const getOrganizationRemark: (organizationID: number, remarkIndex: number, reqSession: expressSession.Session) => llm.OrganizationRemark;
export declare const addOrganizationRemark: (reqBody: llm.OrganizationRemark, reqSession: expressSession.Session) => number;
export declare const updateOrganizationRemark: (reqBody: llm.OrganizationRemark, reqSession: expressSession.Session) => boolean;
export declare const deleteOrganizationRemark: (organizationID: number, remarkIndex: number, reqSession: expressSession.Session) => boolean;
export declare const getOrganizationReminder: (organizationID: number, reminderIndex: number, reqSession: expressSession.Session) => llm.OrganizationReminder;
export declare const updateOrganizationReminder: (reqBody: {
organizationID: string;
reminderIndex: string;
Expand All @@ -20,10 +21,7 @@ export declare const updateOrganizationReminder: (reqBody: {
reminderStatus: string;
reminderNote: string;
dismissedDateString: string;
}, reqSession: any) => boolean;
export declare const dismissOrganizationReminder: (organizationID: number, reminderIndex: number, reqSession: any) => boolean;
}, reqSession: expressSession.Session) => boolean;
export declare const dismissOrganizationReminder: (organizationID: number, reminderIndex: number, reqSession: expressSession.Session) => boolean;
export declare const getOrganizationBankRecords: (organizationID: number, accountNumber: string, bankingYear: number) => llm.OrganizationBankRecord[];
export declare const getOrganizationBankRecordStats: (organizationID: number) => any[];
export declare const addOrganizationBankRecord: (reqBody: llm.OrganizationBankRecord, reqSession: any) => boolean;
export declare const updateOrganizationBankRecord: (reqBody: llm.OrganizationBankRecord, reqSession: any) => boolean;
export declare const deleteOrganizationBankRecord: (organizationID: number, recordIndex: number, reqSession: any) => boolean;
Loading

0 comments on commit c0f2cfe

Please sign in to comment.