mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
Compare commits
16 Commits
plaid-env-
...
v0.17.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8862810706 | ||
|
|
3dadbeac4d | ||
|
|
494d2c1fe0 | ||
|
|
d27562bd43 | ||
|
|
fc9995c4da | ||
|
|
7dc769004d | ||
|
|
909a70e2c5 | ||
|
|
84dd0fa86b | ||
|
|
a4719fe15b | ||
|
|
fd915b503f | ||
|
|
bbba54c08e | ||
|
|
f241e2bede | ||
|
|
175bc243f3 | ||
|
|
7c06c8bb8a | ||
|
|
8fd930caac | ||
|
|
e175307da4 |
23
.env.example
23
.env.example
@@ -75,30 +75,9 @@ PLAID_ENV=sandbox
|
|||||||
# Your Plaid keys, which can be found in the Plaid Dashboard.
|
# Your Plaid keys, which can be found in the Plaid Dashboard.
|
||||||
# https://dashboard.plaid.com/account/keys
|
# https://dashboard.plaid.com/account/keys
|
||||||
PLAID_CLIENT_ID=
|
PLAID_CLIENT_ID=
|
||||||
PLAID_SECRET_DEVELOPMENT=
|
PLAID_SECRET=
|
||||||
PLAID_SECRET_SANDBOX=
|
|
||||||
|
|
||||||
PLAID_LINK_WEBHOOK=
|
PLAID_LINK_WEBHOOK=
|
||||||
|
|
||||||
# (Optional) Redirect URI settings section
|
|
||||||
# Only required for OAuth redirect URI testing (not common on desktop):
|
|
||||||
# Sandbox Mode:
|
|
||||||
# Set the PLAID_SANDBOX_REDIRECT_URI below to 'http://localhost:3001/oauth-link'.
|
|
||||||
# The OAuth redirect flow requires an endpoint on the developer's website
|
|
||||||
# that the bank website should redirect to. You will also need to configure
|
|
||||||
# this redirect URI for your client ID through the Plaid developer dashboard
|
|
||||||
# at https://dashboard.plaid.com/team/api.
|
|
||||||
# Development mode:
|
|
||||||
# When running in development mode, you must use an https:// url.
|
|
||||||
# You will need to configure this https:// redirect URI in the Plaid developer dashboard.
|
|
||||||
# Instructions to create a self-signed certificate for localhost can be found at
|
|
||||||
# https://github.com/plaid/pattern/blob/master/README.md#testing-oauth.
|
|
||||||
# If your system is not set up to run localhost with https://, you will be unable to test
|
|
||||||
# the OAuth in development and should leave the PLAID_DEVELOPMENT_REDIRECT_URI blank.
|
|
||||||
|
|
||||||
PLAID_SANDBOX_REDIRECT_URI=
|
|
||||||
PLAID_DEVELOPMENT_REDIRECT_URI=
|
|
||||||
|
|
||||||
# https://docs.lemonsqueezy.com/guides/developer-guide/getting-started#create-an-api-key
|
# https://docs.lemonsqueezy.com/guides/developer-guide/getting-started#create-an-api-key
|
||||||
LEMONSQUEEZY_API_KEY=
|
LEMONSQUEEZY_API_KEY=
|
||||||
LEMONSQUEEZY_STORE_ID=
|
LEMONSQUEEZY_STORE_ID=
|
||||||
|
|||||||
35
CHANGELOG.md
35
CHANGELOG.md
@@ -2,6 +2,41 @@
|
|||||||
|
|
||||||
All notable changes to Bigcapital server-side will be in this file.
|
All notable changes to Bigcapital server-side will be in this file.
|
||||||
|
|
||||||
|
## [0.17.0] - 04-06-2024
|
||||||
|
|
||||||
|
### New
|
||||||
|
|
||||||
|
* feat: Upload and attach documents by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/461
|
||||||
|
* feat: Export resource tables to pdf by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/460
|
||||||
|
* feat: Build and deploy develop Docker container by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/476
|
||||||
|
* feat: Internal docker virtual network by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/478
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
* fix: Skip send confirmation email if disabled by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/459
|
||||||
|
* fix: Lemon Squeezy redirect to base url by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/479
|
||||||
|
* fix: Organize Plaid env variables for development and sandbox envs by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/480
|
||||||
|
* fix: Plaid syncs deposit imports as withdrawals by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/481
|
||||||
|
* fix: Validate the s3 configures exist by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/482
|
||||||
|
* fix: Run migrations only for initialized tenants by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/484
|
||||||
|
|
||||||
|
## [0.16.16] -
|
||||||
|
|
||||||
|
* feat: handle http exceptions by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/456
|
||||||
|
* feat: add the missing Newrelic env vars to docker-compose.prod file by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/457
|
||||||
|
* fix: add the signup email confirmation env var by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/458
|
||||||
|
|
||||||
|
## [0.16.14] -
|
||||||
|
|
||||||
|
* fix: Typo in setup wizard by @ccantrell72 in https://github.com/bigcapitalhq/bigcapital/pull/440
|
||||||
|
* fix: Showing the real mail address on email confirmation view by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/445
|
||||||
|
* fix: Auto-increment setting parsing by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/453
|
||||||
|
|
||||||
|
## [0.16.12] -
|
||||||
|
|
||||||
|
* feat: Create a manifest list for `webapp` Docker image and push it to DockerHub. by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/436
|
||||||
|
* feat: Combine arm64 and amd64 in one Github action runner by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/437
|
||||||
|
|
||||||
## [0.16.11] - 06-05-2024
|
## [0.16.11] - 06-05-2024
|
||||||
|
|
||||||
### improvements
|
### improvements
|
||||||
|
|||||||
@@ -22,11 +22,15 @@ services:
|
|||||||
- server
|
- server
|
||||||
- webapp
|
- webapp
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
webapp:
|
webapp:
|
||||||
container_name: bigcapital-webapp
|
container_name: bigcapital-webapp
|
||||||
image: bigcapitalhq/webapp:latest
|
image: bigcapitalhq/webapp:latest
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
server:
|
server:
|
||||||
container_name: bigcapital-server
|
container_name: bigcapital-server
|
||||||
@@ -89,14 +93,17 @@ services:
|
|||||||
- GOTENBERG_URL=${GOTENBERG_URL}
|
- GOTENBERG_URL=${GOTENBERG_URL}
|
||||||
- GOTENBERG_DOCS_URL=${GOTENBERG_DOCS_URL}
|
- GOTENBERG_DOCS_URL=${GOTENBERG_DOCS_URL}
|
||||||
|
|
||||||
|
# Exchange Rate
|
||||||
|
- EXCHANGE_RATE_SERVICE=${EXCHANGE_RATE_SERVICE}
|
||||||
|
- OPEN_EXCHANGE_RATE_APP_ID-${OPEN_EXCHANGE_RATE_APP_ID}
|
||||||
|
|
||||||
# Bank Sync
|
# Bank Sync
|
||||||
- BANKING_CONNECT=${BANKING_CONNECT}
|
- BANKING_CONNECT=${BANKING_CONNECT}
|
||||||
|
|
||||||
# Plaid
|
# Plaid
|
||||||
- PLAID_ENV=${PLAID_ENV}
|
- PLAID_ENV=${PLAID_ENV}
|
||||||
- PLAID_CLIENT_ID=${PLAID_CLIENT_ID}
|
- PLAID_CLIENT_ID=${PLAID_CLIENT_ID}
|
||||||
- PLAID_SECRET_DEVELOPMENT=${PLAID_SECRET_DEVELOPMENT}
|
- PLAID_SECRET=${PLAID_SECRET}
|
||||||
- PLAID_SECRET_SANDBOX=${b8cf42b441e110451e2f69ad7e1e9f}
|
|
||||||
- PLAID_LINK_WEBHOOK=${PLAID_LINK_WEBHOOK}
|
- PLAID_LINK_WEBHOOK=${PLAID_LINK_WEBHOOK}
|
||||||
|
|
||||||
# Lemon Squeez
|
# Lemon Squeez
|
||||||
@@ -120,6 +127,8 @@ services:
|
|||||||
- S3_SECRET_ACCESS_KEY=${S3_SECRET_ACCESS_KEY}
|
- S3_SECRET_ACCESS_KEY=${S3_SECRET_ACCESS_KEY}
|
||||||
- S3_ENDPOINT=${S3_ENDPOINT}
|
- S3_ENDPOINT=${S3_ENDPOINT}
|
||||||
- S3_BUCKET=${S3_BUCKET}
|
- S3_BUCKET=${S3_BUCKET}
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
database_migration:
|
database_migration:
|
||||||
container_name: bigcapital-database-migration
|
container_name: bigcapital-database-migration
|
||||||
@@ -137,6 +146,8 @@ services:
|
|||||||
- TENANT_DB_NAME_PERFIX=${TENANT_DB_NAME_PERFIX}
|
- TENANT_DB_NAME_PERFIX=${TENANT_DB_NAME_PERFIX}
|
||||||
depends_on:
|
depends_on:
|
||||||
- mysql
|
- mysql
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
container_name: bigcapital-mysql
|
container_name: bigcapital-mysql
|
||||||
@@ -152,6 +163,8 @@ services:
|
|||||||
- mysql:/var/lib/mysql
|
- mysql:/var/lib/mysql
|
||||||
expose:
|
expose:
|
||||||
- '3306'
|
- '3306'
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
container_name: bigcapital-mongo
|
container_name: bigcapital-mongo
|
||||||
@@ -161,6 +174,8 @@ services:
|
|||||||
- '27017'
|
- '27017'
|
||||||
volumes:
|
volumes:
|
||||||
- mongo:/var/lib/mongodb
|
- mongo:/var/lib/mongodb
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
container_name: bigcapital-redis
|
container_name: bigcapital-redis
|
||||||
@@ -171,11 +186,15 @@ services:
|
|||||||
- '6379'
|
- '6379'
|
||||||
volumes:
|
volumes:
|
||||||
- redis:/data
|
- redis:/data
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
gotenberg:
|
gotenberg:
|
||||||
image: gotenberg/gotenberg:7
|
image: gotenberg/gotenberg:7
|
||||||
expose:
|
expose:
|
||||||
- '9000'
|
- '9000'
|
||||||
|
networks:
|
||||||
|
- bigcapital_network
|
||||||
|
|
||||||
# Volumes
|
# Volumes
|
||||||
volumes:
|
volumes:
|
||||||
@@ -190,3 +209,8 @@ volumes:
|
|||||||
redis:
|
redis:
|
||||||
name: bigcapital_prod_redis
|
name: bigcapital_prod_redis
|
||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
|
# Networks
|
||||||
|
networks:
|
||||||
|
bigcapital_network:
|
||||||
|
driver: bridge
|
||||||
|
|||||||
@@ -4,12 +4,16 @@ import { Router, Response, NextFunction, Request } from 'express';
|
|||||||
import { body, param } from 'express-validator';
|
import { body, param } from 'express-validator';
|
||||||
import BaseController from '@/api/controllers/BaseController';
|
import BaseController from '@/api/controllers/BaseController';
|
||||||
import { AttachmentsApplication } from '@/services/Attachments/AttachmentsApplication';
|
import { AttachmentsApplication } from '@/services/Attachments/AttachmentsApplication';
|
||||||
|
import { AttachmentUploadPipeline } from '@/services/Attachments/S3UploadPipeline';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class AttachmentsController extends BaseController {
|
export class AttachmentsController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
private attachmentsApplication: AttachmentsApplication;
|
private attachmentsApplication: AttachmentsApplication;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private uploadPipelineService: AttachmentUploadPipeline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
*/
|
*/
|
||||||
@@ -18,7 +22,8 @@ export class AttachmentsController extends BaseController {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/',
|
'/',
|
||||||
this.attachmentsApplication.uploadPipeline.single('file'),
|
this.uploadPipelineService.validateS3Configured,
|
||||||
|
this.uploadPipelineService.uploadPipeline().single('file'),
|
||||||
this.validateUploadedFileExistance,
|
this.validateUploadedFileExistance,
|
||||||
this.uploadAttachment.bind(this)
|
this.uploadAttachment.bind(this)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Router } from 'express';
|
import { NextFunction, Router, Request, Response } from 'express';
|
||||||
import { PlaidApplication } from '@/services/Banking/Plaid/PlaidApplication';
|
|
||||||
import { Request, Response } from 'express';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { PlaidApplication } from '@/services/Banking/Plaid/PlaidApplication';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
import { LemonSqueezyWebhooks } from '@/services/Subscription/LemonSqueezyWebhooks';
|
import { LemonSqueezyWebhooks } from '@/services/Subscription/LemonSqueezyWebhooks';
|
||||||
import { PlaidWebhookTenantBootMiddleware } from '@/services/Banking/Plaid/PlaidWebhookTenantBootMiddleware';
|
import { PlaidWebhookTenantBootMiddleware } from '@/services/Banking/Plaid/PlaidWebhookTenantBootMiddleware';
|
||||||
@@ -34,7 +33,7 @@ export class Webhooks extends BaseController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @returns {Response}
|
* @returns {Response}
|
||||||
*/
|
*/
|
||||||
public async lemonWebhooks(req: Request, res: Response, next: any) {
|
public async lemonWebhooks(req: Request, res: Response, next: NextFunction) {
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
const signature = req.headers['x-signature'] ?? '';
|
const signature = req.headers['x-signature'] ?? '';
|
||||||
const rawBody = req.rawBody;
|
const rawBody = req.rawBody;
|
||||||
@@ -57,8 +56,10 @@ export class Webhooks extends BaseController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @returns {Response}
|
* @returns {Response}
|
||||||
*/
|
*/
|
||||||
public async plaidWebhooks(req: Request, res: Response) {
|
public async plaidWebhooks(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
|
|
||||||
|
try {
|
||||||
const {
|
const {
|
||||||
webhook_type: webhookType,
|
webhook_type: webhookType,
|
||||||
webhook_code: webhookCode,
|
webhook_code: webhookCode,
|
||||||
@@ -72,5 +73,8 @@ export class Webhooks extends BaseController {
|
|||||||
webhookCode
|
webhookCode
|
||||||
);
|
);
|
||||||
return res.status(200).send({ code: 200, message: 'ok' });
|
return res.status(200).send({ code: 200, message: 'ok' });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ function getAllSystemTenants(knex) {
|
|||||||
return knex('tenants');
|
return knex('tenants');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllInitializedSystemTenants(knex) {
|
||||||
|
return knex('tenants').whereNotNull('initializedAt');
|
||||||
|
}
|
||||||
|
|
||||||
// module.exports = {
|
// module.exports = {
|
||||||
// log,
|
// log,
|
||||||
// success,
|
// success,
|
||||||
@@ -183,7 +187,7 @@ commander
|
|||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
try {
|
try {
|
||||||
const sysKnex = await initSystemKnex();
|
const sysKnex = await initSystemKnex();
|
||||||
const tenants = await getAllSystemTenants(sysKnex);
|
const tenants = await getAllInitializedSystemTenants(sysKnex);
|
||||||
const tenantsOrgsIds = tenants.map((tenant) => tenant.organizationId);
|
const tenantsOrgsIds = tenants.map((tenant) => tenant.organizationId);
|
||||||
|
|
||||||
if (cmd.tenant_id && tenantsOrgsIds.indexOf(cmd.tenant_id) === -1) {
|
if (cmd.tenant_id && tenantsOrgsIds.indexOf(cmd.tenant_id) === -1) {
|
||||||
@@ -220,7 +224,6 @@ commander
|
|||||||
const oper = migrateTenant(cmd.tenant_id);
|
const oper = migrateTenant(cmd.tenant_id);
|
||||||
migrateOpers.push(oper);
|
migrateOpers.push(oper);
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(migrateOpers).then(() => {
|
Promise.all(migrateOpers).then(() => {
|
||||||
success('All tenants are migrated.');
|
success('All tenants are migrated.');
|
||||||
});
|
});
|
||||||
@@ -280,4 +283,3 @@ commander
|
|||||||
exit(error);
|
exit(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -235,6 +235,6 @@ module.exports = {
|
|||||||
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
||||||
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
||||||
endpoint: process.env.S3_ENDPOINT,
|
endpoint: process.env.S3_ENDPOINT,
|
||||||
bucket: process.env.S3_BUCKET,
|
bucket: process.env.S3_BUCKET || 'bigcapital-documents',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
exports.up = function (knex) {
|
||||||
|
return knex.schema.createTable('storage', (table) => {
|
||||||
|
table.increments('id').primary();
|
||||||
|
table.string('key').notNullable();
|
||||||
|
table.string('path').notNullable();
|
||||||
|
table.string('extension').notNullable();
|
||||||
|
table.integer('expire_in');
|
||||||
|
table.timestamps();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function (knex) {
|
||||||
|
return knex.schema.dropTableIfExists('storage');
|
||||||
|
};
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
exports.up = function (knex) {
|
||||||
|
return knex.schema.dropTableIfExists('storage');
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function (knex) {};
|
||||||
@@ -164,3 +164,7 @@ export enum TaxRateAction {
|
|||||||
DELETE = 'Delete',
|
DELETE = 'Delete',
|
||||||
VIEW = 'View',
|
VIEW = 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CreateAccountParams {
|
||||||
|
ignoreUniqueName: boolean;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
IAccountEventCreatedPayload,
|
IAccountEventCreatedPayload,
|
||||||
IAccountEventCreatingPayload,
|
IAccountEventCreatingPayload,
|
||||||
IAccountCreateDTO,
|
IAccountCreateDTO,
|
||||||
|
CreateAccountParams,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import events from '@/subscribers/events';
|
import events from '@/subscribers/events';
|
||||||
import UnitOfWork from '@/services/UnitOfWork';
|
import UnitOfWork from '@/services/UnitOfWork';
|
||||||
@@ -36,13 +37,16 @@ export class CreateAccount {
|
|||||||
private authorize = async (
|
private authorize = async (
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
accountDTO: IAccountCreateDTO,
|
accountDTO: IAccountCreateDTO,
|
||||||
baseCurrency: string
|
baseCurrency: string,
|
||||||
|
params?: CreateAccountParams
|
||||||
) => {
|
) => {
|
||||||
// Validate account name uniquiness.
|
// Validate account name uniquiness.
|
||||||
|
if (!params.ignoreUniqueName) {
|
||||||
await this.validator.validateAccountNameUniquiness(
|
await this.validator.validateAccountNameUniquiness(
|
||||||
tenantId,
|
tenantId,
|
||||||
accountDTO.name
|
accountDTO.name
|
||||||
);
|
);
|
||||||
|
}
|
||||||
// Validate the account code uniquiness.
|
// Validate the account code uniquiness.
|
||||||
if (accountDTO.code) {
|
if (accountDTO.code) {
|
||||||
await this.validator.isAccountCodeUniqueOrThrowError(
|
await this.validator.isAccountCodeUniqueOrThrowError(
|
||||||
@@ -104,7 +108,8 @@ export class CreateAccount {
|
|||||||
public createAccount = async (
|
public createAccount = async (
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
accountDTO: IAccountCreateDTO,
|
accountDTO: IAccountCreateDTO,
|
||||||
trx?: Knex.Transaction
|
trx?: Knex.Transaction,
|
||||||
|
params: CreateAccountParams = { ignoreUniqueName: false }
|
||||||
): Promise<IAccount> => {
|
): Promise<IAccount> => {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
@@ -112,8 +117,12 @@ export class CreateAccount {
|
|||||||
const tenantMeta = await TenantMetadata.query().findOne({ tenantId });
|
const tenantMeta = await TenantMetadata.query().findOne({ tenantId });
|
||||||
|
|
||||||
// Authorize the account creation.
|
// Authorize the account creation.
|
||||||
await this.authorize(tenantId, accountDTO, tenantMeta.baseCurrency);
|
await this.authorize(
|
||||||
|
tenantId,
|
||||||
|
accountDTO,
|
||||||
|
tenantMeta.baseCurrency,
|
||||||
|
params
|
||||||
|
);
|
||||||
// Transformes the DTO to model.
|
// Transformes the DTO to model.
|
||||||
const accountInputModel = this.transformDTOToModel(
|
const accountInputModel = this.transformDTOToModel(
|
||||||
accountDTO,
|
accountDTO,
|
||||||
@@ -148,3 +157,4 @@ export class CreateAccount {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import { Inject, Service } from 'typedi';
|
|||||||
import { UploadDocument } from './UploadDocument';
|
import { UploadDocument } from './UploadDocument';
|
||||||
import { DeleteAttachment } from './DeleteAttachment';
|
import { DeleteAttachment } from './DeleteAttachment';
|
||||||
import { GetAttachment } from './GetAttachment';
|
import { GetAttachment } from './GetAttachment';
|
||||||
import { AttachmentUploadPipeline } from './S3UploadPipeline';
|
|
||||||
import { LinkAttachment } from './LinkAttachment';
|
import { LinkAttachment } from './LinkAttachment';
|
||||||
import { UnlinkAttachment } from './UnlinkAttachment';
|
import { UnlinkAttachment } from './UnlinkAttachment';
|
||||||
import { getAttachmentPresignedUrl } from './GetAttachmentPresignedUrl';
|
import { getAttachmentPresignedUrl } from './GetAttachmentPresignedUrl';
|
||||||
import type { Multer } from 'multer';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class AttachmentsApplication {
|
export class AttachmentsApplication {
|
||||||
@@ -19,9 +17,6 @@ export class AttachmentsApplication {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private getDocumentService: GetAttachment;
|
private getDocumentService: GetAttachment;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uploadPipelineService: AttachmentUploadPipeline;
|
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private linkDocumentService: LinkAttachment;
|
private linkDocumentService: LinkAttachment;
|
||||||
|
|
||||||
@@ -31,14 +26,6 @@ export class AttachmentsApplication {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private getPresignedUrlService: getAttachmentPresignedUrl;
|
private getPresignedUrlService: getAttachmentPresignedUrl;
|
||||||
|
|
||||||
/**
|
|
||||||
* Express middleware for uploading attachments to an S3 bucket.
|
|
||||||
* @returns {Multer}
|
|
||||||
*/
|
|
||||||
get uploadPipeline(): Multer {
|
|
||||||
return this.uploadPipelineService.uploadPipeline();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the metadata of uploaded document to S3 on database.
|
* Saves the metadata of uploaded document to S3 on database.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
|
|||||||
@@ -1,12 +1,38 @@
|
|||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
import type { Multer } from 'multer'
|
import type { Multer } from 'multer';
|
||||||
import multerS3 from 'multer-s3';
|
import multerS3 from 'multer-s3';
|
||||||
import { s3 } from '@/lib/S3/S3';
|
import { s3 } from '@/lib/S3/S3';
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
|
import { NextFunction, Request, Response } from 'express';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class AttachmentUploadPipeline {
|
export class AttachmentUploadPipeline {
|
||||||
|
/**
|
||||||
|
* Middleware to ensure that S3 configuration is properly set before proceeding.
|
||||||
|
* This function checks if the necessary S3 configuration keys are present and throws an error if any are missing.
|
||||||
|
*
|
||||||
|
* @param req The HTTP request object.
|
||||||
|
* @param res The HTTP response object.
|
||||||
|
* @param next The callback to pass control to the next middleware function.
|
||||||
|
*/
|
||||||
|
public validateS3Configured(req: Request, res: Response, next: NextFunction) {
|
||||||
|
if (
|
||||||
|
!config.s3.region ||
|
||||||
|
!config.s3.accessKeyId ||
|
||||||
|
!config.s3.secretAccessKey
|
||||||
|
) {
|
||||||
|
const missingKeys = [];
|
||||||
|
if (!config.s3.region) missingKeys.push('region');
|
||||||
|
if (!config.s3.accessKeyId) missingKeys.push('accessKeyId');
|
||||||
|
if (!config.s3.secretAccessKey) missingKeys.push('secretAccessKey');
|
||||||
|
const missing = missingKeys.join(', ');
|
||||||
|
|
||||||
|
throw new Error(`S3 configuration error: Missing ${missing}`);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Express middleware for uploading attachments to an S3 bucket.
|
* Express middleware for uploading attachments to an S3 bucket.
|
||||||
* It utilizes the multer middleware for handling multipart/form-data, specifically for file uploads.
|
* It utilizes the multer middleware for handling multipart/form-data, specifically for file uploads.
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import { Inject, Service } from 'typedi';
|
|||||||
import bluebird from 'bluebird';
|
import bluebird from 'bluebird';
|
||||||
import { entries, groupBy } from 'lodash';
|
import { entries, groupBy } from 'lodash';
|
||||||
import { CreateAccount } from '@/services/Accounts/CreateAccount';
|
import { CreateAccount } from '@/services/Accounts/CreateAccount';
|
||||||
import { PlaidAccount, PlaidTransaction } from '@/interfaces';
|
import {
|
||||||
|
IAccountCreateDTO,
|
||||||
|
PlaidAccount,
|
||||||
|
PlaidTransaction,
|
||||||
|
} from '@/interfaces';
|
||||||
import {
|
import {
|
||||||
transformPlaidAccountToCreateAccount,
|
transformPlaidAccountToCreateAccount,
|
||||||
transformPlaidTrxsToCashflowCreate,
|
transformPlaidTrxsToCashflowCreate,
|
||||||
@@ -11,6 +15,7 @@ import {
|
|||||||
import { DeleteCashflowTransaction } from '@/services/Cashflow/DeleteCashflowTransactionService';
|
import { DeleteCashflowTransaction } from '@/services/Cashflow/DeleteCashflowTransactionService';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
||||||
|
import { Knex } from 'knex';
|
||||||
|
|
||||||
const CONCURRENCY_ASYNC = 10;
|
const CONCURRENCY_ASYNC = 10;
|
||||||
|
|
||||||
@@ -28,6 +33,35 @@ export class PlaidSyncDb {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private deleteCashflowTransactionService: DeleteCashflowTransaction;
|
private deleteCashflowTransactionService: DeleteCashflowTransaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syncs the Plaid bank account.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IAccountCreateDTO} createBankAccountDTO
|
||||||
|
* @param {Knex.Transaction} trx
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
public async syncBankAccount(
|
||||||
|
tenantId: number,
|
||||||
|
createBankAccountDTO: IAccountCreateDTO,
|
||||||
|
trx?: Knex.Transaction
|
||||||
|
) {
|
||||||
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
const plaidAccount = await Account.query().findOne(
|
||||||
|
'plaidAccountId',
|
||||||
|
createBankAccountDTO.plaidAccountId
|
||||||
|
);
|
||||||
|
// Can't continue if the Plaid account is already created.
|
||||||
|
if (plaidAccount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.createAccountService.createAccount(
|
||||||
|
tenantId,
|
||||||
|
createBankAccountDTO,
|
||||||
|
trx,
|
||||||
|
{ ignoreUniqueName: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs the plaid accounts to the system accounts.
|
* Syncs the plaid accounts to the system accounts.
|
||||||
* @param {number} tenantId Tenant ID.
|
* @param {number} tenantId Tenant ID.
|
||||||
@@ -37,7 +71,8 @@ export class PlaidSyncDb {
|
|||||||
public async syncBankAccounts(
|
public async syncBankAccounts(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidAccounts: PlaidAccount[],
|
plaidAccounts: PlaidAccount[],
|
||||||
institution: any
|
institution: any,
|
||||||
|
trx?: Knex.Transaction
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const transformToPlaidAccounts =
|
const transformToPlaidAccounts =
|
||||||
transformPlaidAccountToCreateAccount(institution);
|
transformPlaidAccountToCreateAccount(institution);
|
||||||
@@ -47,7 +82,7 @@ export class PlaidSyncDb {
|
|||||||
await bluebird.map(
|
await bluebird.map(
|
||||||
accountCreateDTOs,
|
accountCreateDTOs,
|
||||||
(createAccountDTO: any) =>
|
(createAccountDTO: any) =>
|
||||||
this.createAccountService.createAccount(tenantId, createAccountDTO),
|
this.syncBankAccount(tenantId, createAccountDTO, trx),
|
||||||
{ concurrency: CONCURRENCY_ASYNC }
|
{ concurrency: CONCURRENCY_ASYNC }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -61,15 +96,16 @@ export class PlaidSyncDb {
|
|||||||
public async syncAccountTranactions(
|
public async syncAccountTranactions(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidAccountId: number,
|
plaidAccountId: number,
|
||||||
plaidTranasctions: PlaidTransaction[]
|
plaidTranasctions: PlaidTransaction[],
|
||||||
|
trx?: Knex.Transaction
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const cashflowAccount = await Account.query()
|
const cashflowAccount = await Account.query(trx)
|
||||||
.findOne({ plaidAccountId })
|
.findOne({ plaidAccountId })
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
const openingEquityBalance = await Account.query().findOne(
|
const openingEquityBalance = await Account.query(trx).findOne(
|
||||||
'slug',
|
'slug',
|
||||||
'opening-balance-equity'
|
'opening-balance-equity'
|
||||||
);
|
);
|
||||||
@@ -87,7 +123,8 @@ export class PlaidSyncDb {
|
|||||||
(uncategoriedDTO) =>
|
(uncategoriedDTO) =>
|
||||||
this.cashflowApp.createUncategorizedTransaction(
|
this.cashflowApp.createUncategorizedTransaction(
|
||||||
tenantId,
|
tenantId,
|
||||||
uncategoriedDTO
|
uncategoriedDTO,
|
||||||
|
trx
|
||||||
),
|
),
|
||||||
{ concurrency: 1 }
|
{ concurrency: 1 }
|
||||||
);
|
);
|
||||||
@@ -100,7 +137,8 @@ export class PlaidSyncDb {
|
|||||||
*/
|
*/
|
||||||
public async syncAccountsTransactions(
|
public async syncAccountsTransactions(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidAccountsTransactions: PlaidTransaction[]
|
plaidAccountsTransactions: PlaidTransaction[],
|
||||||
|
trx?: Knex.Transaction
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const groupedTrnsxByAccountId = entries(
|
const groupedTrnsxByAccountId = entries(
|
||||||
groupBy(plaidAccountsTransactions, 'account_id')
|
groupBy(plaidAccountsTransactions, 'account_id')
|
||||||
@@ -111,7 +149,8 @@ export class PlaidSyncDb {
|
|||||||
return this.syncAccountTranactions(
|
return this.syncAccountTranactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
plaidAccountId,
|
plaidAccountId,
|
||||||
plaidTransactions
|
plaidTransactions,
|
||||||
|
trx
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{ concurrency: CONCURRENCY_ASYNC }
|
{ concurrency: CONCURRENCY_ASYNC }
|
||||||
@@ -124,11 +163,12 @@ export class PlaidSyncDb {
|
|||||||
*/
|
*/
|
||||||
public async syncRemoveTransactions(
|
public async syncRemoveTransactions(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidTransactionsIds: string[]
|
plaidTransactionsIds: string[],
|
||||||
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
const { CashflowTransaction } = this.tenancy.models(tenantId);
|
const { CashflowTransaction } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const cashflowTransactions = await CashflowTransaction.query().whereIn(
|
const cashflowTransactions = await CashflowTransaction.query(trx).whereIn(
|
||||||
'plaidTransactionId',
|
'plaidTransactionId',
|
||||||
plaidTransactionsIds
|
plaidTransactionsIds
|
||||||
);
|
);
|
||||||
@@ -140,7 +180,8 @@ export class PlaidSyncDb {
|
|||||||
(transactionId: number) =>
|
(transactionId: number) =>
|
||||||
this.deleteCashflowTransactionService.deleteCashflowTransaction(
|
this.deleteCashflowTransactionService.deleteCashflowTransaction(
|
||||||
tenantId,
|
tenantId,
|
||||||
transactionId
|
transactionId,
|
||||||
|
trx
|
||||||
),
|
),
|
||||||
{ concurrency: CONCURRENCY_ASYNC }
|
{ concurrency: CONCURRENCY_ASYNC }
|
||||||
);
|
);
|
||||||
@@ -155,11 +196,12 @@ export class PlaidSyncDb {
|
|||||||
public async syncTransactionsCursor(
|
public async syncTransactionsCursor(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidItemId: string,
|
plaidItemId: string,
|
||||||
lastCursor: string
|
lastCursor: string,
|
||||||
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
const { PlaidItem } = this.tenancy.models(tenantId);
|
const { PlaidItem } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
await PlaidItem.query().findOne({ plaidItemId }).patch({ lastCursor });
|
await PlaidItem.query(trx).findOne({ plaidItemId }).patch({ lastCursor });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,11 +211,14 @@ export class PlaidSyncDb {
|
|||||||
*/
|
*/
|
||||||
public async updateLastFeedsUpdatedAt(
|
public async updateLastFeedsUpdatedAt(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidAccountIds: string[]
|
plaidAccountIds: string[],
|
||||||
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
await Account.query().whereIn('plaid_account_id', plaidAccountIds).patch({
|
await Account.query(trx)
|
||||||
|
.whereIn('plaid_account_id', plaidAccountIds)
|
||||||
|
.patch({
|
||||||
lastFeedsUpdatedAt: new Date(),
|
lastFeedsUpdatedAt: new Date(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -187,11 +232,14 @@ export class PlaidSyncDb {
|
|||||||
public async updateAccountsFeedsActive(
|
public async updateAccountsFeedsActive(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidAccountIds: string[],
|
plaidAccountIds: string[],
|
||||||
isFeedsActive: boolean = true
|
isFeedsActive: boolean = true,
|
||||||
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
await Account.query().whereIn('plaid_account_id', plaidAccountIds).patch({
|
await Account.query(trx)
|
||||||
|
.whereIn('plaid_account_id', plaidAccountIds)
|
||||||
|
.patch({
|
||||||
isFeedsActive,
|
isFeedsActive,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { Inject, Service } from 'typedi';
|
|||||||
import { PlaidClientWrapper } from '@/lib/Plaid/Plaid';
|
import { PlaidClientWrapper } from '@/lib/Plaid/Plaid';
|
||||||
import { PlaidSyncDb } from './PlaidSyncDB';
|
import { PlaidSyncDb } from './PlaidSyncDB';
|
||||||
import { PlaidFetchedTransactionsUpdates } from '@/interfaces';
|
import { PlaidFetchedTransactionsUpdates } from '@/interfaces';
|
||||||
|
import UnitOfWork from '@/services/UnitOfWork';
|
||||||
|
import { Knex } from 'knex';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class PlaidUpdateTransactions {
|
export class PlaidUpdateTransactions {
|
||||||
@@ -12,12 +14,40 @@ export class PlaidUpdateTransactions {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private plaidSync: PlaidSyncDb;
|
private plaidSync: PlaidSyncDb;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private uow: UnitOfWork;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the fetching and storing of new, modified, or removed transactions
|
* Handles sync the Plaid item to Bigcaptial under UOW.
|
||||||
* @param {number} tenantId Tenant ID.
|
* @param {number} tenantId
|
||||||
* @param {string} plaidItemId the Plaid ID for the item.
|
* @param {number} plaidItemId
|
||||||
|
* @returns {Promise<{ addedCount: number; modifiedCount: number; removedCount: number; }>}
|
||||||
*/
|
*/
|
||||||
public async updateTransactions(tenantId: number, plaidItemId: string) {
|
public async updateTransactions(tenantId: number, plaidItemId: string) {
|
||||||
|
return this.uow.withTransaction(tenantId, (trx: Knex.Transaction) => {
|
||||||
|
return this.updateTransactionsWork(tenantId, plaidItemId, trx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the fetching and storing the following:
|
||||||
|
* - New, modified, or removed transactions.
|
||||||
|
* - New bank accounts.
|
||||||
|
* - Last accounts feeds updated at.
|
||||||
|
* - Turn on the accounts feed flag.
|
||||||
|
* @param {number} tenantId - Tenant ID.
|
||||||
|
* @param {string} plaidItemId - The Plaid ID for the item.
|
||||||
|
* @returns {Promise<{ addedCount: number; modifiedCount: number; removedCount: number; }>}
|
||||||
|
*/
|
||||||
|
public async updateTransactionsWork(
|
||||||
|
tenantId: number,
|
||||||
|
plaidItemId: string,
|
||||||
|
trx?: Knex.Transaction
|
||||||
|
): Promise<{
|
||||||
|
addedCount: number;
|
||||||
|
modifiedCount: number;
|
||||||
|
removedCount: number;
|
||||||
|
}> {
|
||||||
// Fetch new transactions from plaid api.
|
// Fetch new transactions from plaid api.
|
||||||
const { added, modified, removed, cursor, accessToken } =
|
const { added, modified, removed, cursor, accessToken } =
|
||||||
await this.fetchTransactionUpdates(tenantId, plaidItemId);
|
await this.fetchTransactionUpdates(tenantId, plaidItemId);
|
||||||
@@ -29,28 +59,42 @@ export class PlaidUpdateTransactions {
|
|||||||
} = await plaidInstance.accountsGet(request);
|
} = await plaidInstance.accountsGet(request);
|
||||||
|
|
||||||
const plaidAccountsIds = accounts.map((a) => a.account_id);
|
const plaidAccountsIds = accounts.map((a) => a.account_id);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { institution },
|
data: { institution },
|
||||||
} = await plaidInstance.institutionsGetById({
|
} = await plaidInstance.institutionsGetById({
|
||||||
institution_id: item.institution_id,
|
institution_id: item.institution_id,
|
||||||
country_codes: ['US', 'UK'],
|
country_codes: ['US', 'UK'],
|
||||||
});
|
});
|
||||||
// Update the DB.
|
// Sync bank accounts.
|
||||||
await this.plaidSync.syncBankAccounts(tenantId, accounts, institution);
|
await this.plaidSync.syncBankAccounts(tenantId, accounts, institution, trx);
|
||||||
|
// Sync bank account transactions.
|
||||||
await this.plaidSync.syncAccountsTransactions(
|
await this.plaidSync.syncAccountsTransactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
added.concat(modified)
|
added.concat(modified),
|
||||||
|
trx
|
||||||
|
);
|
||||||
|
// Sync removed transactions.
|
||||||
|
await this.plaidSync.syncRemoveTransactions(tenantId, removed, trx);
|
||||||
|
// Sync transactions cursor.
|
||||||
|
await this.plaidSync.syncTransactionsCursor(
|
||||||
|
tenantId,
|
||||||
|
plaidItemId,
|
||||||
|
cursor,
|
||||||
|
trx
|
||||||
);
|
);
|
||||||
await this.plaidSync.syncRemoveTransactions(tenantId, removed);
|
|
||||||
await this.plaidSync.syncTransactionsCursor(tenantId, plaidItemId, cursor);
|
|
||||||
|
|
||||||
// Update the last feeds updated at of the updated accounts.
|
// Update the last feeds updated at of the updated accounts.
|
||||||
await this.plaidSync.updateLastFeedsUpdatedAt(tenantId, plaidAccountsIds);
|
await this.plaidSync.updateLastFeedsUpdatedAt(
|
||||||
|
tenantId,
|
||||||
|
plaidAccountsIds,
|
||||||
|
trx
|
||||||
|
);
|
||||||
// Turn on the accounts feeds flag.
|
// Turn on the accounts feeds flag.
|
||||||
await this.plaidSync.updateAccountsFeedsActive(tenantId, plaidAccountsIds);
|
await this.plaidSync.updateAccountsFeedsActive(
|
||||||
|
tenantId,
|
||||||
|
plaidAccountsIds,
|
||||||
|
true,
|
||||||
|
trx
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
addedCount: added.length,
|
addedCount: added.length,
|
||||||
modifiedCount: modified.length,
|
modifiedCount: modified.length,
|
||||||
|
|||||||
@@ -42,7 +42,12 @@ export const transformPlaidTrxsToCashflowCreate = R.curry(
|
|||||||
): CreateUncategorizedTransactionDTO => {
|
): CreateUncategorizedTransactionDTO => {
|
||||||
return {
|
return {
|
||||||
date: plaidTranasction.date,
|
date: plaidTranasction.date,
|
||||||
amount: plaidTranasction.amount,
|
|
||||||
|
// Plaid: Positive values when money moves out of the account; negative values
|
||||||
|
// when money moves in. For example, debit card purchases are positive;
|
||||||
|
// credit card payments, direct deposits, and refunds are negative.
|
||||||
|
amount: -1 * plaidTranasction.amount,
|
||||||
|
|
||||||
description: plaidTranasction.name,
|
description: plaidTranasction.name,
|
||||||
payee: plaidTranasction.payment_meta?.payee,
|
payee: plaidTranasction.payment_meta?.payee,
|
||||||
currencyCode: plaidTranasction.iso_currency_code,
|
currencyCode: plaidTranasction.iso_currency_code,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Knex } from 'knex';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { DeleteCashflowTransaction } from './DeleteCashflowTransactionService';
|
import { DeleteCashflowTransaction } from './DeleteCashflowTransactionService';
|
||||||
import { UncategorizeCashflowTransaction } from './UncategorizeCashflowTransaction';
|
import { UncategorizeCashflowTransaction } from './UncategorizeCashflowTransaction';
|
||||||
@@ -119,11 +120,13 @@ export class CashflowApplication {
|
|||||||
*/
|
*/
|
||||||
public createUncategorizedTransaction(
|
public createUncategorizedTransaction(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO
|
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO,
|
||||||
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
return this.createUncategorizedTransactionService.create(
|
return this.createUncategorizedTransactionService.create(
|
||||||
tenantId,
|
tenantId,
|
||||||
createUncategorizedTransactionDTO
|
createUncategorizedTransactionDTO,
|
||||||
|
trx
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ export class DeleteCashflowTransaction {
|
|||||||
*/
|
*/
|
||||||
public deleteCashflowTransaction = async (
|
public deleteCashflowTransaction = async (
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
cashflowTransactionId: number
|
cashflowTransactionId: number,
|
||||||
|
trx?: Knex.Transaction
|
||||||
): Promise<{ oldCashflowTransaction: ICashflowTransaction }> => {
|
): Promise<{ oldCashflowTransaction: ICashflowTransaction }> => {
|
||||||
const { CashflowTransaction, CashflowTransactionLine } =
|
const { CashflowTransaction, CashflowTransactionLine } =
|
||||||
this.tenancy.models(tenantId);
|
this.tenancy.models(tenantId);
|
||||||
@@ -43,13 +44,18 @@ export class DeleteCashflowTransaction {
|
|||||||
this.throwErrorIfTransactionNotFound(oldCashflowTransaction);
|
this.throwErrorIfTransactionNotFound(oldCashflowTransaction);
|
||||||
|
|
||||||
// Starting database transaction.
|
// Starting database transaction.
|
||||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
return this.uow.withTransaction(
|
||||||
|
tenantId,
|
||||||
|
async (trx: Knex.Transaction) => {
|
||||||
// Triggers `onCashflowTransactionDelete` event.
|
// Triggers `onCashflowTransactionDelete` event.
|
||||||
await this.eventPublisher.emitAsync(events.cashflow.onTransactionDeleting, {
|
await this.eventPublisher.emitAsync(
|
||||||
|
events.cashflow.onTransactionDeleting,
|
||||||
|
{
|
||||||
trx,
|
trx,
|
||||||
tenantId,
|
tenantId,
|
||||||
oldCashflowTransaction,
|
oldCashflowTransaction,
|
||||||
} as ICommandCashflowDeletingPayload);
|
} as ICommandCashflowDeletingPayload
|
||||||
|
);
|
||||||
|
|
||||||
// Delete cashflow transaction associated lines first.
|
// Delete cashflow transaction associated lines first.
|
||||||
await CashflowTransactionLine.query(trx)
|
await CashflowTransactionLine.query(trx)
|
||||||
@@ -62,15 +68,20 @@ export class DeleteCashflowTransaction {
|
|||||||
.delete();
|
.delete();
|
||||||
|
|
||||||
// Triggers `onCashflowTransactionDeleted` event.
|
// Triggers `onCashflowTransactionDeleted` event.
|
||||||
await this.eventPublisher.emitAsync(events.cashflow.onTransactionDeleted, {
|
await this.eventPublisher.emitAsync(
|
||||||
|
events.cashflow.onTransactionDeleted,
|
||||||
|
{
|
||||||
trx,
|
trx,
|
||||||
tenantId,
|
tenantId,
|
||||||
cashflowTransactionId,
|
cashflowTransactionId,
|
||||||
oldCashflowTransaction,
|
oldCashflowTransaction,
|
||||||
} as ICommandCashflowDeletedPayload);
|
} as ICommandCashflowDeletedPayload
|
||||||
|
);
|
||||||
|
|
||||||
return { oldCashflowTransaction };
|
return { oldCashflowTransaction };
|
||||||
});
|
},
|
||||||
|
trx
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function SubscriptionPricing({
|
|||||||
useGetLemonSqueezyCheckout();
|
useGetLemonSqueezyCheckout();
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
getLemonCheckout({ variantId: '337977' })
|
getLemonCheckout({ variantId: '338516' })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const checkoutUrl = res.data.data.attributes.url;
|
const checkoutUrl = res.data.data.attributes.url;
|
||||||
window.LemonSqueezy.Url.Open(checkoutUrl);
|
window.LemonSqueezy.Url.Open(checkoutUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user