@tomei/finance 0.1.0 → 0.1.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.
Files changed (63) hide show
  1. package/dist/account/account.d.ts +4 -5
  2. package/dist/account/account.js +27 -30
  3. package/dist/account/account.js.map +1 -1
  4. package/dist/account/account.repository.d.ts +1 -1
  5. package/dist/account/account.repository.js +2 -2
  6. package/dist/account/account.repository.js.map +1 -1
  7. package/dist/account/entities/account.entity.d.ts +0 -6
  8. package/dist/account/entities/account.entity.js +0 -26
  9. package/dist/account/entities/account.entity.js.map +1 -1
  10. package/dist/account/interfaces/account-attr.interface.d.ts +3 -3
  11. package/dist/account/interfaces/account.repository.interface.d.ts +1 -1
  12. package/dist/base/account-system.interface.d.ts +5 -5
  13. package/dist/base/index.d.ts +3 -5
  14. package/dist/base/index.js +5 -5
  15. package/dist/base/index.js.map +1 -1
  16. package/dist/base/object/base.object.d.ts +7 -0
  17. package/dist/base/object/base.object.js +14 -0
  18. package/dist/base/object/base.object.js.map +1 -0
  19. package/dist/base/owner/base.owner.d.ts +22 -0
  20. package/dist/base/owner/base.owner.js +31 -0
  21. package/dist/base/owner/base.owner.js.map +1 -0
  22. package/dist/config.d.ts +33 -0
  23. package/dist/config.js +145 -0
  24. package/dist/config.js.map +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +3 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/quickbook-client/client.d.ts +10 -3
  29. package/dist/quickbook-client/client.js +29 -0
  30. package/dist/quickbook-client/client.js.map +1 -1
  31. package/dist/quickbook-client/index.d.ts +3 -4
  32. package/dist/quickbook-client/index.js +1 -5
  33. package/dist/quickbook-client/index.js.map +1 -1
  34. package/dist/quickbook-client/interfaces/quickbook-client-create-account-options.interface.d.ts +9 -0
  35. package/dist/quickbook-client/interfaces/quickbook-client-create-account-options.interface.js +3 -0
  36. package/dist/quickbook-client/interfaces/quickbook-client-create-account-options.interface.js.map +1 -0
  37. package/dist/quickbook-client/interfaces/quickbook-client-options.interface.d.ts +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +6 -3
  40. package/src/account/account.repository.ts +1 -1
  41. package/src/account/account.ts +39 -33
  42. package/src/account/entities/account.entity.ts +0 -32
  43. package/src/account/interfaces/account-attr.interface.ts +3 -3
  44. package/src/account/interfaces/account.repository.interface.ts +1 -1
  45. package/src/base/account-system.interface.ts +5 -5
  46. package/src/base/index.ts +3 -5
  47. package/src/base/object/base.object.ts +14 -0
  48. package/src/base/owner/base.owner.ts +55 -0
  49. package/src/config.ts +173 -0
  50. package/src/index.ts +1 -0
  51. package/src/quickbook-client/client.ts +34 -3
  52. package/src/quickbook-client/index.ts +4 -6
  53. package/src/quickbook-client/interfaces/quickbook-client-create-account-options.interface.ts +9 -0
  54. package/src/quickbook-client/interfaces/quickbook-client-options.interface.ts +1 -1
  55. package/src/base/base.repository.abstract.ts +0 -28
  56. package/src/base/base.repository.interface.ts +0 -9
  57. package/src/base/object/base.object.abstract.ts +0 -6
  58. package/src/base/object/object.interface.ts +0 -4
  59. package/src/base/owner/base.owner.abstract.ts +0 -21
  60. package/src/base/owner/owner.interface.ts +0 -20
  61. package/src/quickbook-client/constant.ts +0 -1
  62. package/src/quickbook-client/quickbook-client.module-definition.ts +0 -7
  63. package/src/quickbook-client/quickbook-client.module.ts +0 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,13 +34,13 @@
34
34
  "@nestjs/core": "^9.0.8",
35
35
  "@nestjs/platform-express": "^9.0.8",
36
36
  "@nestjs/sequelize": "^9.0.0",
37
+ "axios": "^1.1.3",
37
38
  "class-transformer": "^0.5.1",
38
39
  "class-validator": "^0.13.2",
39
40
  "dotenv": "^16.0.3",
40
41
  "intuit-oauth": "^4.0.0",
41
42
  "sequelize-typescript": "^2.1.3",
42
- "uniqid": "^5.4.0",
43
- "axios": "^1.1.3"
43
+ "uniqid": "^5.4.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@nestjs/swagger": "^6.0.4",
@@ -68,5 +68,8 @@
68
68
  "npm run build",
69
69
  "git add ."
70
70
  ]
71
+ },
72
+ "dependencies": {
73
+ "@tomei/general": "^0.0.3"
71
74
  }
72
75
  }
@@ -1,7 +1,7 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { InjectModel } from '@nestjs/sequelize';
3
- import { BaseRepository } from '../base/base.repository.abstract';
4
3
  import { AccountModel } from './entities/account.entity';
4
+ import { BaseRepository } from '@tomei/general';
5
5
  import {
6
6
  IAccountAttr,
7
7
  ICreateAccountAttr,
@@ -1,8 +1,10 @@
1
- import { ObjectBase, OwnerBase } from 'src/base';
1
+ import { IAccountSystem, RelatedObject, Owner } from 'src/base';
2
2
  import { ICreateAccountAttr } from './interfaces/account-attr.interface';
3
3
  import { IAccountRepository } from './interfaces/account.repository.interface';
4
- import { QuickBookClient } from '../quickbook-client';
5
4
  import * as uniqid from 'uniqid';
5
+ import { AccountModel } from './entities/account.entity';
6
+ import axios from 'axios';
7
+ import { getConfig } from 'src/config';
6
8
  export class Account {
7
9
  accountRepository: IAccountRepository;
8
10
 
@@ -13,8 +15,8 @@ export class Account {
13
15
  private AccSystemId: string;
14
16
 
15
17
  ParentAccountNo: string;
16
- Owner: OwnerBase;
17
- RelatedObject: ObjectBase;
18
+ Owner: Owner;
19
+ RelatedObject: RelatedObject;
18
20
  AccountType: string;
19
21
  AccountSubType: string;
20
22
 
@@ -28,7 +30,7 @@ export class Account {
28
30
  params?: ICreateAccountAttr,
29
31
  ) {
30
32
  this.accountRepository = accountRepository;
31
- this.AccSystemId = SysCode;
33
+ this.AccSystemId = getConfig().systemConfig[SysCode].accountingSystem;
32
34
  if (params) {
33
35
  this.init(params);
34
36
  }
@@ -43,10 +45,15 @@ export class Account {
43
45
  if (params.ParentAccountNo) {
44
46
  this.ParentAccountNo = params.ParentAccountNo;
45
47
  }
48
+
49
+ this.OwnerId = params.Owner.Id;
50
+ this.OwnerType = typeof params.Owner;
51
+ this.RelatedObjectId = params.RelatedObject.Id;
52
+ this.RelatedObjectType = typeof params.RelatedObject;
46
53
  this.isParamsInitialized = true;
47
54
  }
48
55
 
49
- async create(userId: string, client: QuickBookClient, dbOptions: any) {
56
+ async create(userId: string, client: IAccountSystem, dbOptions: any) {
50
57
  try {
51
58
  if (!this.Owner || !this.RelatedObject) {
52
59
  throw new Error(
@@ -83,51 +90,33 @@ export class Account {
83
90
  );
84
91
  }
85
92
 
86
- const companyId = client.getCompanyId();
87
- const createAccountPayload = {
93
+ let createAccountPayload: any = {
88
94
  Name: this.Owner.FullName,
89
95
  AcctNum: uniqid(),
90
96
  AccountType: this.AccountType,
91
97
  AccountSubType: this.AccountSubType,
92
98
  };
93
- const response = await client.callApi({
94
- endpoint: `/v3/company/${companyId}/account`,
95
- method: 'POST',
96
- headers: {
97
- 'Content-Type': 'application/json',
98
- },
99
- body: JSON.stringify(createAccountPayload),
100
- });
101
-
102
- const data = response.json.Account;
103
99
 
104
100
  if (this.ParentAccountNo) {
105
- const createChildAccountPayload = {
106
- Id: data.Id,
101
+ createAccountPayload = {
102
+ ...createAccountPayload,
107
103
  CurrencyRef: 'MYR',
108
104
  ParentRef: this.ParentAccountNo,
109
105
  SubAccount: true,
110
106
  };
111
-
112
- await client.callApi({
113
- endpoint: `/v3/company/${companyId}/account`,
114
- method: 'PUT',
115
- headers: {
116
- 'Content-Type': 'application/json',
117
- },
118
- body: JSON.stringify(createChildAccountPayload),
119
- });
120
107
  }
121
108
 
109
+ const data = await client.createAccount(createAccountPayload);
110
+
122
111
  const account = await this.accountRepository.create(
123
112
  {
124
113
  AccountNo: data.Id,
125
114
  SystemCode: this.AccSystemId,
126
115
  Name: data.AcctNum,
127
- OwnerId: this.Owner.Id,
128
- OwnerType: this.Owner.Type,
129
- RelatedObjectId: this.RelatedObject.Id,
130
- RelatedObjectType: this.RelatedObject.Type,
116
+ OwnerId: this.OwnerId,
117
+ OwnerType: this.OwnerType,
118
+ RelatedObjectId: this.RelatedObjectId,
119
+ RelatedObjectType: this.RelatedObjectType,
131
120
  CreatedAt: new Date(),
132
121
  CreatedById: userId,
133
122
  UpdatedAt: new Date(),
@@ -136,6 +125,23 @@ export class Account {
136
125
  dbOptions,
137
126
  );
138
127
 
128
+ const payload = {
129
+ Action: 'Create',
130
+ Activity: 'Account Created',
131
+ Description: `Account (ID: ${account.AccountNo}) has been created`,
132
+ EntityType: typeof AccountModel,
133
+ EntityValueBefore: JSON.stringify({}),
134
+ EntityValueAfter: JSON.stringify(account),
135
+ PerformedById: account.CreatedById,
136
+ PerformedAt: new Date(),
137
+ EntityId: account.AccountNo,
138
+ };
139
+
140
+ await axios.post(
141
+ `${process.env.COMMON_API_URL}/activity-histories`,
142
+ payload,
143
+ );
144
+
139
145
  return account;
140
146
  } catch (error) {
141
147
  throw error;
@@ -6,11 +6,7 @@ import {
6
6
  Table,
7
7
  DataType,
8
8
  UpdatedAt,
9
- AfterCreate,
10
9
  } from 'sequelize-typescript';
11
- import { ObjectBase, OwnerBase } from '../../base';
12
- import { QuickBookClient } from '../../quickbook-client';
13
- import axios from 'axios';
14
10
 
15
11
  @Table({ tableName: 'finance_Account', createdAt: false, updatedAt: false })
16
12
  export class AccountModel extends Model {
@@ -103,32 +99,4 @@ export class AccountModel extends Model {
103
99
  })
104
100
  @Column({ allowNull: false, type: DataType.STRING(30) })
105
101
  UpdatedById: string;
106
-
107
- Owner: OwnerBase;
108
- RelatedObject: ObjectBase;
109
- QuickbookClient: QuickBookClient;
110
-
111
- @AfterCreate
112
- static async createActivityHistory(instance) {
113
- const payload = {
114
- Action: 'Create',
115
- Activity: 'Account Created',
116
- Description: `Account (ID: ${instance.AccountNo}) has been created`,
117
- EntityType: typeof instance,
118
- EntityValueBefore: JSON.stringify({}),
119
- EntityValueAfter: JSON.stringify(instance),
120
- PerformedById: instance.CreatedById,
121
- PerformedAt: new Date(),
122
- EntityId: instance.AccountNo,
123
- };
124
-
125
- try {
126
- await axios.post(
127
- `${process.env.COMMON_API_URL}/activity-histories`,
128
- payload,
129
- );
130
- } catch (error) {
131
- throw error;
132
- }
133
- }
134
102
  }
@@ -1,4 +1,4 @@
1
- import { ObjectBase, OwnerBase } from '../../base';
1
+ import { Owner, RelatedObject } from 'src/base';
2
2
 
3
3
  export interface IAccountAttr {
4
4
  AccountNo: string;
@@ -15,8 +15,8 @@ export interface IAccountAttr {
15
15
  }
16
16
 
17
17
  export interface ICreateAccountAttr {
18
- Owner: OwnerBase;
19
- RelatedObject: ObjectBase;
18
+ Owner: Owner;
19
+ RelatedObject: RelatedObject;
20
20
  AccountType: string;
21
21
  AccountSubType: string;
22
22
  ParentAccountNo?: string;
@@ -1,4 +1,4 @@
1
- import { IBaseRepository } from '../../base/base.repository.interface';
1
+ import { IBaseRepository } from '@tomei/general';
2
2
  import { AccountModel } from '../entities/account.entity';
3
3
 
4
4
  export type IAccountRepository = IBaseRepository<AccountModel>;
@@ -1,7 +1,7 @@
1
1
  export interface IAccountSystem {
2
- createAccount(): any;
3
- createInvoice(): any;
4
- createDebitNote(): any;
5
- createCreditNote(): any;
6
- postTransaction(): any;
2
+ createAccount(payload: any): Promise<any>;
3
+ createInvoice(payload: any): Promise<any>;
4
+ createDebitNote(payload: any): Promise<any>;
5
+ createCreditNote(payload: any): Promise<any>;
6
+ postTransaction(payload: any): Promise<any>;
7
7
  }
package/src/base/index.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { IAccountSystem } from './account-system.interface';
2
- import { IOwner } from './owner/owner.interface';
3
- import { OwnerBase } from './owner/base.owner.abstract';
4
- import { IObject } from './object/object.interface';
5
- import { ObjectBase } from './object/base.object.abstract';
2
+ import { RelatedObject } from '../base/object/base.object';
3
+ import { Owner } from '../base/owner/base.owner';
6
4
 
7
- export { IAccountSystem, ObjectBase, OwnerBase, IObject, IOwner };
5
+ export { IAccountSystem, RelatedObject, Owner };
@@ -0,0 +1,14 @@
1
+ import { ObjectBase } from '@tomei/general';
2
+
3
+ export class RelatedObject extends ObjectBase {
4
+ Id: string;
5
+ Name: string;
6
+ Type: string;
7
+
8
+ constructor(id: string, name: string) {
9
+ super();
10
+ this.Id = id;
11
+ this.Name = name;
12
+ this.Type = 'RelatedObject';
13
+ }
14
+ }
@@ -0,0 +1,55 @@
1
+ import { PersonBase, AddressBase } from '@tomei/general';
2
+
3
+ export class Owner extends PersonBase {
4
+ FullName: string;
5
+ IDNo: string;
6
+ IDType: string;
7
+ Email: string;
8
+ ContactNo: string;
9
+ Address: AddressBase;
10
+ Id: string;
11
+ Name: string;
12
+
13
+ constructor(
14
+ fullName: string,
15
+ idNo: string,
16
+ idType: string,
17
+ email: string,
18
+ contactNo: string,
19
+ address: AddressBase,
20
+ id: string,
21
+ name: string,
22
+ ) {
23
+ super();
24
+ this.FullName = fullName;
25
+ this.IDNo = idNo;
26
+ this.IDType = idType;
27
+ this.Email = email;
28
+ this.ContactNo = contactNo;
29
+ this.Address = address;
30
+ this.Id = id;
31
+ this.Name = name;
32
+ }
33
+
34
+ getDetails(): {
35
+ FullName: string;
36
+ IDNo: string;
37
+ IDType: string;
38
+ Email: string;
39
+ ContactNo: string;
40
+ Address: AddressBase;
41
+ Id: string;
42
+ Name: string;
43
+ } {
44
+ return {
45
+ FullName: this.FullName,
46
+ IDNo: this.IDNo,
47
+ IDType: this.IDType,
48
+ Email: this.Email,
49
+ ContactNo: this.ContactNo,
50
+ Address: this.Address,
51
+ Id: this.Id,
52
+ Name: this.Name,
53
+ };
54
+ }
55
+ }
package/src/config.ts ADDED
@@ -0,0 +1,173 @@
1
+ const config = {
2
+ development: {
3
+ commonApiUrl: process.env.COMMON_API_URL,
4
+ accountingSystem: {
5
+ quickbooks: {
6
+ packageName: process.env.PACKAGE_NAME,
7
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
8
+ API_Url: process.env.API_URL,
9
+ },
10
+ xero: {
11
+ packageName: process.env.PACKAGE_NAME,
12
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
13
+ API_Url: process.env.API_URL,
14
+ },
15
+ },
16
+ systemConfig: {
17
+ EZC: {
18
+ accountingSystem: 'quickbooks',
19
+ companyName: process.env.COMPANY_NAME,
20
+ API_Key: process.env.QUICKBOOK_API_KEY,
21
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
22
+ redirectUrl: process.env.EZCASH_REDIRECT_URL,
23
+ },
24
+ EZG: {
25
+ accountingSystem: 'xero',
26
+ companyName: process.env.COMPANY_NAME,
27
+ API_Key: process.env.QUICKBOOK_API_KEY,
28
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
29
+ redirectUrl: process.env.EZGOLD_REDIRECT_URL,
30
+ },
31
+ },
32
+ },
33
+ test: {
34
+ commonApiUrl: process.env.COMMON_API_URL,
35
+ accountingSystem: {
36
+ quickbooks: {
37
+ packageName: process.env.PACKAGE_NAME,
38
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
39
+ API_Url: process.env.API_URL,
40
+ },
41
+ xero: {
42
+ packageName: process.env.PACKAGE_NAME,
43
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
44
+ API_Url: process.env.API_URL,
45
+ },
46
+ },
47
+ systemConfig: {
48
+ EZC: {
49
+ accountingSystem: 'quickbooks',
50
+ companyName: process.env.COMPANY_NAME,
51
+ API_Key: process.env.QUICKBOOK_API_KEY,
52
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
53
+ redirectUrl: process.env.EZCASH_REDIRECT_URL,
54
+ },
55
+ EZG: {
56
+ accountingSystem: 'xero',
57
+ companyName: process.env.COMPANY_NAME,
58
+ API_Key: process.env.QUICKBOOK_API_KEY,
59
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
60
+ redirectUrl: process.env.EZGOLD_REDIRECT_URL,
61
+ },
62
+ },
63
+ },
64
+ staging: {
65
+ commonApiUrl: process.env.COMMON_API_URL,
66
+ accountingSystem: {
67
+ quickbooks: {
68
+ packageName: process.env.PACKAGE_NAME,
69
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
70
+ API_Url: process.env.API_URL,
71
+ },
72
+ xero: {
73
+ packageName: process.env.PACKAGE_NAME,
74
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
75
+ API_Url: process.env.API_URL,
76
+ },
77
+ },
78
+ systemConfig: {
79
+ EZC: {
80
+ accountingSystem: 'quickbooks',
81
+ companyName: process.env.COMPANY_NAME,
82
+ API_Key: process.env.QUICKBOOK_API_KEY,
83
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
84
+ redirectUrl: process.env.EZCASH_REDIRECT_URL,
85
+ },
86
+ EZG: {
87
+ accountingSystem: 'xero',
88
+ companyName: process.env.COMPANY_NAME,
89
+ API_Key: process.env.QUICKBOOK_API_KEY,
90
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
91
+ redirectUrl: process.env.EZGOLD_REDIRECT_URL,
92
+ },
93
+ },
94
+ },
95
+ production: {
96
+ commonApiUrl: process.env.COMMON_API_URL,
97
+ accountingSystem: {
98
+ quickbooks: {
99
+ packageName: process.env.PACKAGE_NAME,
100
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
101
+ API_Url: process.env.API_URL,
102
+ },
103
+ xero: {
104
+ packageName: process.env.PACKAGE_NAME,
105
+ accountSystemClass: process.env.ACCOUNT_SYSTEM_CLASS,
106
+ API_Url: process.env.API_URL,
107
+ },
108
+ },
109
+ systemConfig: {
110
+ EZC: {
111
+ accountingSystem: 'quickbooks',
112
+ companyName: process.env.COMPANY_NAME,
113
+ API_Key: process.env.QUICKBOOK_API_KEY,
114
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
115
+ redirectUrl: process.env.EZCASH_REDIRECT_URL,
116
+ },
117
+ EZG: {
118
+ accountingSystem: 'xero',
119
+ companyName: process.env.COMPANY_NAME,
120
+ API_Key: process.env.QUICKBOOK_API_KEY,
121
+ API_Secret: process.env.QUICKBOOK_API_SECRET,
122
+ redirectUrl: process.env.EZGOLD_REDIRECT_URL,
123
+ },
124
+ },
125
+ },
126
+ };
127
+
128
+ type Config = {
129
+ commonApiUrl: string;
130
+ accountingSystem: {
131
+ quickbooks: {
132
+ packageName: string;
133
+ accountSystemClass: string;
134
+ API_Url: string;
135
+ };
136
+ xero: {
137
+ packageName: string;
138
+ accountSystemClass: string;
139
+ API_Url: string;
140
+ };
141
+ };
142
+ systemConfig: {
143
+ EZC: {
144
+ accountingSystem: string;
145
+ companyName: string;
146
+ API_Key: string;
147
+ API_Secret: string;
148
+ redirectUrl: string;
149
+ };
150
+ EZG: {
151
+ accountingSystem: string;
152
+ companyName: string;
153
+ API_Key: string;
154
+ API_Secret: string;
155
+ redirectUrl: string;
156
+ };
157
+ };
158
+ };
159
+
160
+ export const getConfig = (): Config => {
161
+ switch (process.env.NODE_ENV) {
162
+ case 'development':
163
+ return config['development'];
164
+ case 'test':
165
+ return config['test'];
166
+ case 'staging':
167
+ return config['staging'];
168
+ case 'production':
169
+ return config['production'];
170
+ default:
171
+ break;
172
+ }
173
+ };
package/src/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from './base';
2
2
  export * from './account';
3
3
  export * from './quickbook-client';
4
4
  export * from './enum';
5
+ export { getConfig } from './config';
@@ -1,13 +1,15 @@
1
1
  import * as OAuthClient from 'intuit-oauth';
2
+ import { IAccountSystem } from 'src/base';
2
3
  import { ClientScopes } from 'src/enum/quick-book-client-scopes.enum';
3
4
  import { IQuickBookAPICallOptions } from './interfaces/quickbook-client-call-options.interface';
4
- import { IQuickBookClientModuleOptions } from './interfaces/quickbook-client-options.interface';
5
+ import { IQuickBookCreateAccountOptions } from './interfaces/quickbook-client-create-account-options.interface';
6
+ import { IQuickBookClientOptions } from './interfaces/quickbook-client-options.interface';
5
7
 
6
- export class QuickBookClient {
8
+ export class QuickBookClient implements IAccountSystem {
7
9
  client: OAuthClient;
8
10
  apiUrl: string;
9
11
 
10
- constructor(options: IQuickBookClientModuleOptions) {
12
+ constructor(options: IQuickBookClientOptions) {
11
13
  this.client = new OAuthClient({
12
14
  clientId: options.clientId,
13
15
  clientSecret: options.clientSecret,
@@ -18,6 +20,35 @@ export class QuickBookClient {
18
20
  this.apiUrl = options.apiUrl;
19
21
  }
20
22
 
23
+ async createAccount(payload: IQuickBookCreateAccountOptions) {
24
+ try {
25
+ const companyId = this.getCompanyId();
26
+ const response = await this.callApi({
27
+ endpoint: `/v3/company/${companyId}/account`,
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ },
32
+ body: JSON.stringify(payload),
33
+ });
34
+ return response.json.Account;
35
+ } catch (error) {
36
+ throw error;
37
+ }
38
+ }
39
+ async createInvoice() {
40
+ throw new Error('Method not implemented.');
41
+ }
42
+ async createDebitNote() {
43
+ throw new Error('Method not implemented.');
44
+ }
45
+ async createCreditNote() {
46
+ throw new Error('Method not implemented.');
47
+ }
48
+ async postTransaction() {
49
+ throw new Error('Method not implemented.');
50
+ }
51
+
21
52
  connect(scopes: ClientScopes[]): string {
22
53
  try {
23
54
  const authUrl = this.client.authorizeUri({
@@ -1,11 +1,9 @@
1
- import { QuickBookClientModule } from './quickbook-client.module';
2
- import { IQuickBookClientModuleOptions } from './interfaces/quickbook-client-options.interface';
3
- import { QUICKBOOK_CLIENT } from './constant';
4
1
  import { QuickBookClient } from './client';
2
+ import { IQuickBookCreateAccountOptions } from './interfaces/quickbook-client-create-account-options.interface';
3
+ import { IQuickBookClientOptions } from './interfaces/quickbook-client-options.interface';
5
4
 
6
5
  export {
7
- QuickBookClientModule,
8
- IQuickBookClientModuleOptions,
9
- QUICKBOOK_CLIENT,
10
6
  QuickBookClient,
7
+ IQuickBookCreateAccountOptions,
8
+ IQuickBookClientOptions,
11
9
  };
@@ -0,0 +1,9 @@
1
+ export interface IQuickBookCreateAccountOptions {
2
+ Name: string;
3
+ AcctNum: string;
4
+ AccountType: string;
5
+ AccountSubType: string;
6
+ CurrencyRef?: string;
7
+ ParentRef?: string;
8
+ SubAccount?: boolean;
9
+ }
@@ -1,4 +1,4 @@
1
- export interface IQuickBookClientModuleOptions {
1
+ export interface IQuickBookClientOptions {
2
2
  clientId: string;
3
3
  clientSecret: string;
4
4
  redirectUri: string;
@@ -1,28 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
1
- export interface IBaseRepository<T> {
2
- create(data: any | any, options?: any): Promise<T>;
3
-
4
- findAll(options: any): Promise<T[]>;
5
-
6
- findAllWithPagination(options: any): Promise<{ count: number; rows: T[] }>;
7
-
8
- findOne(options: any): Promise<T>;
9
- }
@@ -1,6 +0,0 @@
1
- import { IObject } from './object.interface';
2
-
3
- export abstract class ObjectBase implements IObject {
4
- abstract Id: string;
5
- abstract Type: string;
6
- }
@@ -1,4 +0,0 @@
1
- export interface IObject {
2
- Id: string;
3
- Type: string;
4
- }
@@ -1,21 +0,0 @@
1
- import { ObjectBase } from '../object/base.object.abstract';
2
- import { IOwner } from './owner.interface';
3
-
4
- export abstract class OwnerBase extends ObjectBase implements IOwner {
5
- abstract FullName: string;
6
- abstract IDNo: string;
7
- abstract IDType: string;
8
- abstract Email: string;
9
- abstract ContactNo: string;
10
- abstract Address: string;
11
- abstract getDetails(): {
12
- FullName: string;
13
- IDNo: string;
14
- IDType: string;
15
- Email: string;
16
- ContactNo: string;
17
- Address: string;
18
- Id: string;
19
- Type: string;
20
- };
21
- }