@tomei/finance 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.commitlintrc.json +22 -0
- package/.eslintrc.js +66 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc +4 -0
- package/CHANGELOG.md +1 -0
- package/CONTRIBUTING.md +31 -0
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/configs/config.js +83 -0
- package/dist/account/account.d.ts +23 -0
- package/dist/account/account.js +80 -0
- package/dist/account/account.js.map +1 -0
- package/dist/account/account.repository.d.ts +16 -0
- package/dist/account/account.repository.js +47 -0
- package/dist/account/account.repository.js.map +1 -0
- package/dist/account/entities/account.entity.d.ts +14 -0
- package/dist/account/entities/account.entity.js +122 -0
- package/dist/account/entities/account.entity.js.map +1 -0
- package/dist/account/index.d.ts +6 -0
- package/dist/account/index.js +10 -0
- package/dist/account/index.js.map +1 -0
- package/dist/account/interfaces/account-attr.interface.d.ts +25 -0
- package/dist/account/interfaces/account-attr.interface.js +3 -0
- package/dist/account/interfaces/account-attr.interface.js.map +1 -0
- package/dist/account/interfaces/account.repository.interface.d.ts +3 -0
- package/dist/account/interfaces/account.repository.interface.js +3 -0
- package/dist/account/interfaces/account.repository.interface.js.map +1 -0
- package/dist/base/account-system.interface.d.ts +7 -0
- package/dist/base/account-system.interface.js +3 -0
- package/dist/base/account-system.interface.js.map +1 -0
- package/dist/base/address.base.abstract.d.ts +4 -0
- package/dist/base/address.base.abstract.js +10 -0
- package/dist/base/address.base.abstract.js.map +1 -0
- package/dist/base/base.repository.abstract.d.ts +12 -0
- package/dist/base/base.repository.abstract.js +22 -0
- package/dist/base/base.repository.abstract.js.map +1 -0
- package/dist/base/base.repository.interface.d.ts +9 -0
- package/dist/base/base.repository.interface.js +3 -0
- package/dist/base/base.repository.interface.js.map +1 -0
- package/dist/base/index.d.ts +5 -0
- package/dist/base/index.js +10 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/object.base.abstract.d.ts +5 -0
- package/dist/base/object.base.abstract.js +11 -0
- package/dist/base/object.base.abstract.js.map +1 -0
- package/dist/base/person.base.abstract.d.ts +21 -0
- package/dist/base/person.base.abstract.js +17 -0
- package/dist/base/person.base.abstract.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +8 -0
- package/dist/test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/migrations/finance-account-migration.js +59 -0
- package/nest-cli.json +19 -0
- package/package.json +72 -0
- package/src/account/account.repository.ts +44 -0
- package/src/account/account.ts +124 -0
- package/src/account/entities/account.entity.ts +105 -0
- package/src/account/index.ts +19 -0
- package/src/account/interfaces/account-attr.interface.ts +28 -0
- package/src/account/interfaces/account.repository.interface.ts +4 -0
- package/src/base/account-system.interface.ts +7 -0
- package/src/base/address.base.abstract.ts +7 -0
- package/src/base/base.repository.abstract.ts +28 -0
- package/src/base/base.repository.interface.ts +9 -0
- package/src/base/index.ts +7 -0
- package/src/base/object.base.abstract.ts +8 -0
- package/src/base/person.base.abstract.ts +44 -0
- package/src/index.ts +5 -0
- package/src/test.ts +3 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +30 -0
- package/tslint.json +18 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ObjectBase } from 'src/base/object.base.abstract';
|
|
2
|
+
import { PersonBase } from 'src/base/person.base.abstract';
|
|
3
|
+
import {
|
|
4
|
+
IAccountOptions,
|
|
5
|
+
ICreateAccountAttr,
|
|
6
|
+
} from './interfaces/account-attr.interface';
|
|
7
|
+
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
8
|
+
import * as OAuthClient from 'intuit-oauth';
|
|
9
|
+
import config from '../../configs/config';
|
|
10
|
+
|
|
11
|
+
export class Account {
|
|
12
|
+
accountRepository: IAccountRepository;
|
|
13
|
+
intuitClient: any;
|
|
14
|
+
config: any;
|
|
15
|
+
|
|
16
|
+
OwnerId: string;
|
|
17
|
+
OwnerType: string;
|
|
18
|
+
RelatedObjectId: string;
|
|
19
|
+
RelatedObjectType: string;
|
|
20
|
+
AccSystemId: string;
|
|
21
|
+
parentAccount: Account;
|
|
22
|
+
|
|
23
|
+
Owner: PersonBase;
|
|
24
|
+
RelatedObject: ObjectBase;
|
|
25
|
+
|
|
26
|
+
isParamsInitialized: boolean;
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
accountRepository: IAccountRepository,
|
|
30
|
+
SysCode: string,
|
|
31
|
+
options?: IAccountOptions,
|
|
32
|
+
) {
|
|
33
|
+
this.accountRepository = accountRepository;
|
|
34
|
+
this.AccSystemId = SysCode;
|
|
35
|
+
this.config = config();
|
|
36
|
+
if (options) {
|
|
37
|
+
if (options.params) {
|
|
38
|
+
this.init(options.params);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (options.account) {
|
|
42
|
+
this.parentAccount = options.account;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!this.config) {
|
|
47
|
+
throw new Error('Environment variable required not found');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.intuitClient = new OAuthClient({
|
|
51
|
+
clientId: this.config.systemConfig[this.AccSystemId].API_Key,
|
|
52
|
+
clientSecret: this.config.systemConfig[this.AccSystemId].API_Secret,
|
|
53
|
+
environment: this.config.env !== 'production' ? 'sandbox' : 'production',
|
|
54
|
+
redirectUri: this.config.systemConfig[this.AccSystemId].redirectUrl,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
init(params: ICreateAccountAttr) {
|
|
59
|
+
this.Owner = params.Owner;
|
|
60
|
+
this.RelatedObject = params.RelatedObject;
|
|
61
|
+
|
|
62
|
+
const ownerData = this.Owner.getDetails();
|
|
63
|
+
|
|
64
|
+
if (!ownerData) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
'Please save owner information in the database before creating an account',
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let isFull = true;
|
|
71
|
+
for (const key in ownerData) {
|
|
72
|
+
if (ownerData.hasOwnProperty(key)) {
|
|
73
|
+
if (!ownerData[key]) {
|
|
74
|
+
isFull = false;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!isFull) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
'Please save owner information in the database before creating an account',
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.OwnerId = params.Owner.Id;
|
|
87
|
+
this.OwnerType = 'Owner';
|
|
88
|
+
this.RelatedObjectId = params.RelatedObject.Id;
|
|
89
|
+
this.RelatedObjectType = 'RelatedObject';
|
|
90
|
+
this.isParamsInitialized = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
connect(): string {
|
|
94
|
+
const authUri = this.intuitClient.authorizeUri({
|
|
95
|
+
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
|
96
|
+
state: 'testState',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return authUri;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async createToken(url: string) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await this.intuitClient.createToken(url);
|
|
105
|
+
return response;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async createAccount() {
|
|
112
|
+
if (!this.Owner || !this.RelatedObject) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
'Owner must be set before creating an account." or "RelatedObject must be set before creating an account.',
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!this.isParamsInitialized) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
'Account parameters must be initialized before creating an account.',
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreatedAt,
|
|
5
|
+
Model,
|
|
6
|
+
Table,
|
|
7
|
+
DataType,
|
|
8
|
+
UpdatedAt,
|
|
9
|
+
} from 'sequelize-typescript';
|
|
10
|
+
|
|
11
|
+
@Table({ tableName: 'finance_Account', createdAt: false, updatedAt: false })
|
|
12
|
+
export class AccountModel extends Model {
|
|
13
|
+
@ApiProperty({ type: String, description: 'AccountNo' })
|
|
14
|
+
@Column({
|
|
15
|
+
primaryKey: true,
|
|
16
|
+
allowNull: false,
|
|
17
|
+
type: DataType.STRING(30),
|
|
18
|
+
})
|
|
19
|
+
AccountNo: string;
|
|
20
|
+
|
|
21
|
+
@ApiProperty({
|
|
22
|
+
type: String,
|
|
23
|
+
description: 'System Code eg. "EZC", "CRM"',
|
|
24
|
+
})
|
|
25
|
+
@Column({
|
|
26
|
+
allowNull: false,
|
|
27
|
+
type: DataType.STRING(10),
|
|
28
|
+
})
|
|
29
|
+
SystemCode: string;
|
|
30
|
+
|
|
31
|
+
@ApiProperty({
|
|
32
|
+
type: String,
|
|
33
|
+
description: 'Name of the account',
|
|
34
|
+
})
|
|
35
|
+
@Column({
|
|
36
|
+
allowNull: true,
|
|
37
|
+
type: DataType.STRING(200),
|
|
38
|
+
})
|
|
39
|
+
Name: string;
|
|
40
|
+
|
|
41
|
+
@ApiProperty({
|
|
42
|
+
type: String,
|
|
43
|
+
description: 'Owner id of the account',
|
|
44
|
+
})
|
|
45
|
+
@Column({
|
|
46
|
+
allowNull: false,
|
|
47
|
+
type: DataType.STRING(30),
|
|
48
|
+
})
|
|
49
|
+
OwnerId: string;
|
|
50
|
+
|
|
51
|
+
@ApiProperty({
|
|
52
|
+
type: String,
|
|
53
|
+
description: 'Owner type',
|
|
54
|
+
})
|
|
55
|
+
@Column({
|
|
56
|
+
allowNull: false,
|
|
57
|
+
type: DataType.STRING(30),
|
|
58
|
+
})
|
|
59
|
+
OwnerType: string;
|
|
60
|
+
|
|
61
|
+
@ApiProperty({ type: String, description: 'Associated Object id' })
|
|
62
|
+
@Column({
|
|
63
|
+
allowNull: false,
|
|
64
|
+
type: DataType.STRING(30),
|
|
65
|
+
})
|
|
66
|
+
RelatedObjectId: string;
|
|
67
|
+
|
|
68
|
+
@ApiProperty({ type: String, description: 'Associated Object type' })
|
|
69
|
+
@Column({
|
|
70
|
+
allowNull: false,
|
|
71
|
+
type: DataType.STRING(200),
|
|
72
|
+
})
|
|
73
|
+
RelatedObjectType: string;
|
|
74
|
+
|
|
75
|
+
@ApiProperty({
|
|
76
|
+
example: new Date(),
|
|
77
|
+
description: 'Timestamp for data creation.',
|
|
78
|
+
})
|
|
79
|
+
@CreatedAt
|
|
80
|
+
CreatedAt: Date;
|
|
81
|
+
|
|
82
|
+
@ApiProperty({
|
|
83
|
+
example: '138140891dd211b288d34bc7b4312a49',
|
|
84
|
+
description: 'The CreatedById for Media.',
|
|
85
|
+
})
|
|
86
|
+
@Column({ allowNull: false, type: DataType.STRING(30) })
|
|
87
|
+
CreatedById: string;
|
|
88
|
+
|
|
89
|
+
@ApiProperty({
|
|
90
|
+
example: new Date(),
|
|
91
|
+
description: 'Timestamp for latest data modification',
|
|
92
|
+
})
|
|
93
|
+
@UpdatedAt
|
|
94
|
+
UpdatedAt: Date;
|
|
95
|
+
|
|
96
|
+
@ApiProperty({
|
|
97
|
+
example: '138140891dd211b288d34bc7b4312a49',
|
|
98
|
+
description: 'The UpdatedById for Media.',
|
|
99
|
+
})
|
|
100
|
+
@Column({ allowNull: false, type: DataType.STRING(30) })
|
|
101
|
+
UpdatedById: string;
|
|
102
|
+
|
|
103
|
+
// @BeforeCreate
|
|
104
|
+
// static register(instance: any) {}
|
|
105
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AccountModel } from './entities/account.entity';
|
|
2
|
+
import { Account } from './account';
|
|
3
|
+
import { AccountRepository } from './account.repository';
|
|
4
|
+
import {
|
|
5
|
+
IAccountOptions,
|
|
6
|
+
IAccountAttr,
|
|
7
|
+
ICreateAccountAttr,
|
|
8
|
+
} from './interfaces/account-attr.interface';
|
|
9
|
+
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
AccountModel,
|
|
13
|
+
Account,
|
|
14
|
+
AccountRepository,
|
|
15
|
+
IAccountOptions,
|
|
16
|
+
IAccountAttr,
|
|
17
|
+
ICreateAccountAttr,
|
|
18
|
+
IAccountRepository,
|
|
19
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ObjectBase } from 'src/base/object.base.abstract';
|
|
2
|
+
import { PersonBase } from 'src/base/person.base.abstract';
|
|
3
|
+
import { Account } from '../account';
|
|
4
|
+
|
|
5
|
+
export interface IAccountAttr {
|
|
6
|
+
AccountNo: string;
|
|
7
|
+
SystemCode: string;
|
|
8
|
+
Name: string;
|
|
9
|
+
OwnerId: string;
|
|
10
|
+
OwnerType: string;
|
|
11
|
+
RelatedObjectId: string;
|
|
12
|
+
RelatedObjectType: string;
|
|
13
|
+
CreatedAt: Date;
|
|
14
|
+
CreatedById: string;
|
|
15
|
+
UpdatedAt: Date;
|
|
16
|
+
UpdatedById: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ICreateAccountAttr {
|
|
20
|
+
Owner: PersonBase;
|
|
21
|
+
RelatedObject: ObjectBase;
|
|
22
|
+
AccSystemId: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IAccountOptions {
|
|
26
|
+
params?: ICreateAccountAttr;
|
|
27
|
+
account?: Account;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IBaseRepository } from './base.repository.interface';
|
|
2
|
+
|
|
3
|
+
export abstract class BaseRepository<T> implements IBaseRepository<T> {
|
|
4
|
+
private model: any;
|
|
5
|
+
// private id: string;
|
|
6
|
+
|
|
7
|
+
protected constructor(model: any) {
|
|
8
|
+
this.model = model;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public async create(data: any, options?: any): Promise<T> {
|
|
12
|
+
return this.model.create(data, options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async findAll(options: any): Promise<T[]> {
|
|
16
|
+
return this.model.findAll(options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async findAllWithPagination(
|
|
20
|
+
options: any,
|
|
21
|
+
): Promise<{ count: number; rows: T[] }> {
|
|
22
|
+
return this.model.findAndCountAll(options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async findOne(options: any): Promise<T> {
|
|
26
|
+
return this.model.findOne(options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// import all classes from this folder and export them
|
|
2
|
+
import { IAccountSystem } from './account-system.interface';
|
|
3
|
+
import { AddressBase } from './address.base.abstract';
|
|
4
|
+
import { ObjectBase } from './object.base.abstract';
|
|
5
|
+
import { PersonBase } from './person.base.abstract';
|
|
6
|
+
|
|
7
|
+
export { IAccountSystem, AddressBase, ObjectBase, PersonBase };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AddressBase } from './address.base.abstract';
|
|
2
|
+
import { ObjectBase } from './object.base.abstract';
|
|
3
|
+
|
|
4
|
+
export abstract class PersonBase extends ObjectBase {
|
|
5
|
+
Fullname: string;
|
|
6
|
+
IDNo: string;
|
|
7
|
+
IDType: string;
|
|
8
|
+
Email: string;
|
|
9
|
+
ContactNo: string;
|
|
10
|
+
Address: AddressBase;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
id: string,
|
|
14
|
+
name: string,
|
|
15
|
+
fullname: string,
|
|
16
|
+
idNo: string,
|
|
17
|
+
idType: string,
|
|
18
|
+
email: string,
|
|
19
|
+
contactNo: string,
|
|
20
|
+
address: AddressBase,
|
|
21
|
+
) {
|
|
22
|
+
super(id, name);
|
|
23
|
+
this.Fullname = fullname;
|
|
24
|
+
this.IDNo = idNo;
|
|
25
|
+
this.IDType = idType;
|
|
26
|
+
this.Email = email;
|
|
27
|
+
this.ContactNo = contactNo;
|
|
28
|
+
this.Address = address;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
abstract getDetails():
|
|
32
|
+
| {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
Fullname: string;
|
|
36
|
+
IDNo: string;
|
|
37
|
+
IDType: string;
|
|
38
|
+
Email: string;
|
|
39
|
+
ContactNo: string;
|
|
40
|
+
Address: AddressBase;
|
|
41
|
+
}
|
|
42
|
+
| null
|
|
43
|
+
| undefined;
|
|
44
|
+
}
|
package/src/index.ts
ADDED
package/src/test.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"target": "es2017",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"baseUrl": "./",
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"strictNullChecks": false,
|
|
17
|
+
"noImplicitAny": false,
|
|
18
|
+
"strictBindCallApply": false,
|
|
19
|
+
"forceConsistentCasingInFileNames": false,
|
|
20
|
+
"noFallthroughCasesInSwitch": false,
|
|
21
|
+
"paths": {
|
|
22
|
+
"@app/finance": [
|
|
23
|
+
"libs/finance/src"
|
|
24
|
+
],
|
|
25
|
+
"@app/finance/*": [
|
|
26
|
+
"libs/finance/src/*"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/tslint.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"defaultSeverity": "error",
|
|
3
|
+
"extends": ["tslint:recommended"],
|
|
4
|
+
"jsRules": {
|
|
5
|
+
"no-unused-expression": true
|
|
6
|
+
},
|
|
7
|
+
"rules": {
|
|
8
|
+
"quotemark": [true, "single"],
|
|
9
|
+
"member-access": [false],
|
|
10
|
+
"ordered-imports": [false],
|
|
11
|
+
"max-line-length": [true, 150],
|
|
12
|
+
"member-ordering": [false],
|
|
13
|
+
"interface-name": [false],
|
|
14
|
+
"arrow-parens": false,
|
|
15
|
+
"object-literal-sort-keys": false
|
|
16
|
+
},
|
|
17
|
+
"rulesDirectory": []
|
|
18
|
+
}
|