@accounter/server 0.0.8-alpha-20251021150615-800574fc6d416cd319de216c97b431643d8958a2 → 0.0.8-alpha-20251021225827-178e480c997a9811913e16f85cb94329041b096e
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/CHANGELOG.md +53 -4
- package/dist/green-invoice-graphql/src/mesh-artifacts/index.d.ts +1 -1
- package/dist/server/src/__generated__/types.d.ts +152 -4
- package/dist/server/src/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/app-providers/green-invoice-client.d.ts +1 -1
- package/dist/server/src/modules/contracts/__generated__/contracts.types.d.ts +145 -0
- package/dist/server/src/modules/contracts/__generated__/types.d.ts +20 -3
- package/dist/server/src/modules/contracts/__generated__/types.js +1 -0
- package/dist/server/src/modules/contracts/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/contracts/providers/contracts.provider.d.ts +10 -1
- package/dist/server/src/modules/contracts/providers/contracts.provider.js +141 -0
- package/dist/server/src/modules/contracts/providers/contracts.provider.js.map +1 -1
- package/dist/server/src/modules/contracts/resolvers/contracts.resolver.js +70 -1
- package/dist/server/src/modules/contracts/resolvers/contracts.resolver.js.map +1 -1
- package/dist/server/src/modules/contracts/typeDefs/contracts.graphql.js +40 -1
- package/dist/server/src/modules/contracts/typeDefs/contracts.graphql.js.map +1 -1
- package/dist/server/src/modules/documents/__generated__/documents.types.d.ts +32 -0
- package/dist/server/src/modules/documents/__generated__/types.d.ts +2 -1
- package/dist/server/src/modules/documents/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/documents/providers/documents.provider.d.ts +2 -0
- package/dist/server/src/modules/documents/providers/documents.provider.js +27 -1
- package/dist/server/src/modules/documents/providers/documents.provider.js.map +1 -1
- package/dist/server/src/modules/documents/resolvers/documents.resolver.js +10 -0
- package/dist/server/src/modules/documents/resolvers/documents.resolver.js.map +1 -1
- package/dist/server/src/modules/documents/typeDefs/documents.graphql.js +1 -0
- package/dist/server/src/modules/documents/typeDefs/documents.graphql.js.map +1 -1
- package/dist/server/src/modules/financial-entities/__generated__/clients.types.d.ts +2 -0
- package/dist/server/src/modules/financial-entities/__generated__/types.d.ts +25 -7
- package/dist/server/src/modules/financial-entities/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/financial-entities/providers/clients.provider.js +2 -2
- package/dist/server/src/modules/financial-entities/resolvers/businesses.resolver.js +0 -1
- package/dist/server/src/modules/financial-entities/resolvers/businesses.resolver.js.map +1 -1
- package/dist/server/src/modules/financial-entities/resolvers/clients.resolvers.js +60 -0
- package/dist/server/src/modules/financial-entities/resolvers/clients.resolvers.js.map +1 -1
- package/dist/server/src/modules/financial-entities/resolvers/common.js +3 -0
- package/dist/server/src/modules/financial-entities/resolvers/common.js.map +1 -1
- package/dist/server/src/modules/financial-entities/typeDefs/businesses.graphql.js +8 -0
- package/dist/server/src/modules/financial-entities/typeDefs/businesses.graphql.js.map +1 -1
- package/dist/server/src/modules/financial-entities/typeDefs/clients.graphql.js +32 -0
- package/dist/server/src/modules/financial-entities/typeDefs/clients.graphql.js.map +1 -1
- package/dist/server/src/modules/financial-entities/typeDefs/financial-entities.graphql.js +3 -0
- package/dist/server/src/modules/financial-entities/typeDefs/financial-entities.graphql.js.map +1 -1
- package/dist/server/src/modules/financial-entities/typeDefs/tax-categories.graphql.js +3 -0
- package/dist/server/src/modules/financial-entities/typeDefs/tax-categories.graphql.js.map +1 -1
- package/dist/server/src/modules/green-invoice/__generated__/types.d.ts +3 -2
- package/dist/server/src/modules/green-invoice/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +18 -0
- package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
- package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js +1 -0
- package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js.map +1 -1
- package/package.json +4 -4
- package/src/__generated__/types.ts +170 -4
- package/src/modules/contracts/__generated__/contracts.types.ts +161 -0
- package/src/modules/contracts/__generated__/types.ts +21 -3
- package/src/modules/contracts/providers/contracts.provider.ts +171 -1
- package/src/modules/contracts/resolvers/contracts.resolver.ts +67 -2
- package/src/modules/contracts/typeDefs/contracts.graphql.ts +40 -1
- package/src/modules/documents/__generated__/documents.types.ts +35 -0
- package/src/modules/documents/__generated__/types.ts +2 -1
- package/src/modules/documents/providers/documents.provider.ts +36 -1
- package/src/modules/documents/resolvers/documents.resolver.ts +12 -0
- package/src/modules/documents/typeDefs/documents.graphql.ts +1 -0
- package/src/modules/financial-entities/__generated__/clients.types.ts +2 -0
- package/src/modules/financial-entities/__generated__/types.ts +25 -7
- package/src/modules/financial-entities/providers/clients.provider.ts +2 -2
- package/src/modules/financial-entities/resolvers/businesses.resolver.ts +0 -1
- package/src/modules/financial-entities/resolvers/clients.resolvers.ts +66 -1
- package/src/modules/financial-entities/resolvers/common.ts +3 -0
- package/src/modules/financial-entities/typeDefs/businesses.graphql.ts +8 -0
- package/src/modules/financial-entities/typeDefs/clients.graphql.ts +32 -0
- package/src/modules/financial-entities/typeDefs/financial-entities.graphql.ts +3 -0
- package/src/modules/financial-entities/typeDefs/tax-categories.graphql.ts +3 -0
- package/src/modules/green-invoice/__generated__/types.ts +3 -2
- package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +19 -0
- package/src/modules/green-invoice/typeDefs/green-invoice.graphql.ts +1 -0
|
@@ -3,6 +3,8 @@ export type currency = 'AUD' | 'CAD' | 'ETH' | 'EUR' | 'GBP' | 'GRT' | 'ILS' | '
|
|
|
3
3
|
|
|
4
4
|
export type document_type = 'CREDIT_INVOICE' | 'INVOICE' | 'INVOICE_RECEIPT' | 'OTHER' | 'PROFORMA' | 'RECEIPT' | 'UNPROCESSED';
|
|
5
5
|
|
|
6
|
+
export type DateOrString = Date | string;
|
|
7
|
+
|
|
6
8
|
/** 'GetAllOpenContracts' parameters type */
|
|
7
9
|
export type IGetAllOpenContractsParams = void;
|
|
8
10
|
|
|
@@ -31,3 +33,162 @@ export interface IGetAllOpenContractsQuery {
|
|
|
31
33
|
result: IGetAllOpenContractsResult;
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
/** 'GetContractsByIds' parameters type */
|
|
37
|
+
export interface IGetContractsByIdsParams {
|
|
38
|
+
ids: readonly (string | null | void)[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 'GetContractsByIds' return type */
|
|
42
|
+
export interface IGetContractsByIdsResult {
|
|
43
|
+
amount: number;
|
|
44
|
+
billing_cycle: string;
|
|
45
|
+
client_id: string;
|
|
46
|
+
currency: currency;
|
|
47
|
+
document_type: document_type;
|
|
48
|
+
end_date: Date;
|
|
49
|
+
id: string;
|
|
50
|
+
is_active: boolean | null;
|
|
51
|
+
ms_cloud: string | null;
|
|
52
|
+
plan: string | null;
|
|
53
|
+
product: string | null;
|
|
54
|
+
purchase_order: string | null;
|
|
55
|
+
remarks: string | null;
|
|
56
|
+
signed_agreement: string | null;
|
|
57
|
+
start_date: Date;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 'GetContractsByIds' query type */
|
|
61
|
+
export interface IGetContractsByIdsQuery {
|
|
62
|
+
params: IGetContractsByIdsParams;
|
|
63
|
+
result: IGetContractsByIdsResult;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 'GetContractsByClientIds' parameters type */
|
|
67
|
+
export interface IGetContractsByClientIdsParams {
|
|
68
|
+
clientIds: readonly (string | null | void)[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 'GetContractsByClientIds' return type */
|
|
72
|
+
export interface IGetContractsByClientIdsResult {
|
|
73
|
+
amount: number;
|
|
74
|
+
billing_cycle: string;
|
|
75
|
+
client_id: string;
|
|
76
|
+
currency: currency;
|
|
77
|
+
document_type: document_type;
|
|
78
|
+
end_date: Date;
|
|
79
|
+
id: string;
|
|
80
|
+
is_active: boolean | null;
|
|
81
|
+
ms_cloud: string | null;
|
|
82
|
+
plan: string | null;
|
|
83
|
+
product: string | null;
|
|
84
|
+
purchase_order: string | null;
|
|
85
|
+
remarks: string | null;
|
|
86
|
+
signed_agreement: string | null;
|
|
87
|
+
start_date: Date;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 'GetContractsByClientIds' query type */
|
|
91
|
+
export interface IGetContractsByClientIdsQuery {
|
|
92
|
+
params: IGetContractsByClientIdsParams;
|
|
93
|
+
result: IGetContractsByClientIdsResult;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 'DeleteContract' parameters type */
|
|
97
|
+
export interface IDeleteContractParams {
|
|
98
|
+
id?: string | null | void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 'DeleteContract' return type */
|
|
102
|
+
export type IDeleteContractResult = void;
|
|
103
|
+
|
|
104
|
+
/** 'DeleteContract' query type */
|
|
105
|
+
export interface IDeleteContractQuery {
|
|
106
|
+
params: IDeleteContractParams;
|
|
107
|
+
result: IDeleteContractResult;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 'UpdateContract' parameters type */
|
|
111
|
+
export interface IUpdateContractParams {
|
|
112
|
+
amount?: number | null | void;
|
|
113
|
+
billing_cycle?: string | null | void;
|
|
114
|
+
client_id?: string | null | void;
|
|
115
|
+
contractId?: string | null | void;
|
|
116
|
+
currency?: currency | null | void;
|
|
117
|
+
document_type?: document_type | null | void;
|
|
118
|
+
end_date?: DateOrString | null | void;
|
|
119
|
+
is_active?: boolean | null | void;
|
|
120
|
+
ms_cloud?: string | null | void;
|
|
121
|
+
plan?: string | null | void;
|
|
122
|
+
product?: string | null | void;
|
|
123
|
+
purchase_order?: string | null | void;
|
|
124
|
+
remarks?: string | null | void;
|
|
125
|
+
start_date?: DateOrString | null | void;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 'UpdateContract' return type */
|
|
129
|
+
export interface IUpdateContractResult {
|
|
130
|
+
amount: number;
|
|
131
|
+
billing_cycle: string;
|
|
132
|
+
client_id: string;
|
|
133
|
+
currency: currency;
|
|
134
|
+
document_type: document_type;
|
|
135
|
+
end_date: Date;
|
|
136
|
+
id: string;
|
|
137
|
+
is_active: boolean | null;
|
|
138
|
+
ms_cloud: string | null;
|
|
139
|
+
plan: string | null;
|
|
140
|
+
product: string | null;
|
|
141
|
+
purchase_order: string | null;
|
|
142
|
+
remarks: string | null;
|
|
143
|
+
signed_agreement: string | null;
|
|
144
|
+
start_date: Date;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 'UpdateContract' query type */
|
|
148
|
+
export interface IUpdateContractQuery {
|
|
149
|
+
params: IUpdateContractParams;
|
|
150
|
+
result: IUpdateContractResult;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 'InsertContract' parameters type */
|
|
154
|
+
export interface IInsertContractParams {
|
|
155
|
+
amount?: number | null | void;
|
|
156
|
+
billingCycle?: string | null | void;
|
|
157
|
+
clientId?: string | null | void;
|
|
158
|
+
currency?: currency | null | void;
|
|
159
|
+
documentType?: document_type | null | void;
|
|
160
|
+
endDate?: DateOrString | null | void;
|
|
161
|
+
isActive?: boolean | null | void;
|
|
162
|
+
msCloud?: string | null | void;
|
|
163
|
+
plan?: string | null | void;
|
|
164
|
+
product?: string | null | void;
|
|
165
|
+
purchaseOrder?: string | null | void;
|
|
166
|
+
remarks?: string | null | void;
|
|
167
|
+
startDate?: DateOrString | null | void;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 'InsertContract' return type */
|
|
171
|
+
export interface IInsertContractResult {
|
|
172
|
+
amount: number;
|
|
173
|
+
billing_cycle: string;
|
|
174
|
+
client_id: string;
|
|
175
|
+
currency: currency;
|
|
176
|
+
document_type: document_type;
|
|
177
|
+
end_date: Date;
|
|
178
|
+
id: string;
|
|
179
|
+
is_active: boolean | null;
|
|
180
|
+
ms_cloud: string | null;
|
|
181
|
+
plan: string | null;
|
|
182
|
+
product: string | null;
|
|
183
|
+
purchase_order: string | null;
|
|
184
|
+
remarks: string | null;
|
|
185
|
+
signed_agreement: string | null;
|
|
186
|
+
start_date: Date;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 'InsertContract' query type */
|
|
190
|
+
export interface IInsertContractQuery {
|
|
191
|
+
params: IInsertContractParams;
|
|
192
|
+
result: IInsertContractResult;
|
|
193
|
+
}
|
|
194
|
+
|
|
@@ -2,8 +2,9 @@ import * as Types from "../../../__generated__/types.js";
|
|
|
2
2
|
import * as gm from "graphql-modules";
|
|
3
3
|
export namespace ContractsModule {
|
|
4
4
|
interface DefinedFields {
|
|
5
|
-
Query: 'allOpenContracts';
|
|
6
|
-
|
|
5
|
+
Query: 'allOpenContracts' | 'contractsByClient';
|
|
6
|
+
Mutation: 'updateContract' | 'deleteContract' | 'createContract';
|
|
7
|
+
Contract: 'id' | 'client' | 'purchaseOrder' | 'startDate' | 'endDate' | 'remarks' | 'amount' | 'documentType' | 'billingCycle' | 'isActive' | 'product' | 'plan' | 'msCloud';
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
interface DefinedEnumValues {
|
|
@@ -12,9 +13,17 @@ export namespace ContractsModule {
|
|
|
12
13
|
SubscriptionPlan: 'ENTERPRISE' | 'PRO';
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
interface DefinedInputFields {
|
|
17
|
+
CreateContractInput: 'clientId' | 'purchaseOrder' | 'startDate' | 'endDate' | 'remarks' | 'amount' | 'documentType' | 'billingCycle' | 'product' | 'plan' | 'msCloud' | 'isActive';
|
|
18
|
+
UpdateContractInput: 'clientId' | 'purchaseOrder' | 'startDate' | 'endDate' | 'remarks' | 'amount' | 'documentType' | 'billingCycle' | 'product' | 'plan' | 'msCloud' | 'isActive';
|
|
19
|
+
};
|
|
20
|
+
|
|
15
21
|
export type Query = Pick<Types.Query, DefinedFields['Query']>;
|
|
16
22
|
export type Contract = Pick<Types.Contract, DefinedFields['Contract']>;
|
|
17
23
|
export type UUID = Types.Uuid;
|
|
24
|
+
export type Mutation = Pick<Types.Mutation, DefinedFields['Mutation']>;
|
|
25
|
+
export type UpdateContractInput = Pick<Types.UpdateContractInput, DefinedInputFields['UpdateContractInput']>;
|
|
26
|
+
export type CreateContractInput = Pick<Types.CreateContractInput, DefinedInputFields['CreateContractInput']>;
|
|
18
27
|
export type Client = Types.Client;
|
|
19
28
|
export type TimelessDate = Types.TimelessDate;
|
|
20
29
|
export type FinancialAmount = Types.FinancialAmount;
|
|
@@ -23,12 +32,15 @@ export namespace ContractsModule {
|
|
|
23
32
|
export type Product = DefinedEnumValues['Product'];
|
|
24
33
|
export type SubscriptionPlan = DefinedEnumValues['SubscriptionPlan'];
|
|
25
34
|
export type URL = Types.Url;
|
|
35
|
+
export type FinancialAmountInput = Types.FinancialAmountInput;
|
|
26
36
|
|
|
27
37
|
export type QueryResolvers = Pick<Types.QueryResolvers, DefinedFields['Query']>;
|
|
38
|
+
export type MutationResolvers = Pick<Types.MutationResolvers, DefinedFields['Mutation']>;
|
|
28
39
|
export type ContractResolvers = Pick<Types.ContractResolvers, DefinedFields['Contract'] | '__isTypeOf'>;
|
|
29
40
|
|
|
30
41
|
export interface Resolvers {
|
|
31
42
|
Query?: QueryResolvers;
|
|
43
|
+
Mutation?: MutationResolvers;
|
|
32
44
|
Contract?: ContractResolvers;
|
|
33
45
|
};
|
|
34
46
|
|
|
@@ -39,6 +51,13 @@ export namespace ContractsModule {
|
|
|
39
51
|
Query?: {
|
|
40
52
|
'*'?: gm.Middleware[];
|
|
41
53
|
allOpenContracts?: gm.Middleware[];
|
|
54
|
+
contractsByClient?: gm.Middleware[];
|
|
55
|
+
};
|
|
56
|
+
Mutation?: {
|
|
57
|
+
'*'?: gm.Middleware[];
|
|
58
|
+
updateContract?: gm.Middleware[];
|
|
59
|
+
deleteContract?: gm.Middleware[];
|
|
60
|
+
createContract?: gm.Middleware[];
|
|
42
61
|
};
|
|
43
62
|
Contract?: {
|
|
44
63
|
'*'?: gm.Middleware[];
|
|
@@ -54,7 +73,6 @@ export namespace ContractsModule {
|
|
|
54
73
|
isActive?: gm.Middleware[];
|
|
55
74
|
product?: gm.Middleware[];
|
|
56
75
|
plan?: gm.Middleware[];
|
|
57
|
-
signedAgreement?: gm.Middleware[];
|
|
58
76
|
msCloud?: gm.Middleware[];
|
|
59
77
|
};
|
|
60
78
|
};
|
|
@@ -1,14 +1,130 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
1
2
|
import { Injectable, Scope } from 'graphql-modules';
|
|
2
3
|
import { DBProvider } from '@modules/app-providers/db.provider.js';
|
|
3
4
|
import { sql } from '@pgtyped/runtime';
|
|
4
5
|
import { getCacheInstance } from '@shared/helpers';
|
|
5
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
IDeleteContractQuery,
|
|
8
|
+
IGetAllOpenContractsQuery,
|
|
9
|
+
IGetAllOpenContractsResult,
|
|
10
|
+
IGetContractsByClientIdsQuery,
|
|
11
|
+
IGetContractsByIdsQuery,
|
|
12
|
+
IInsertContractParams,
|
|
13
|
+
IInsertContractQuery,
|
|
14
|
+
IUpdateContractParams,
|
|
15
|
+
IUpdateContractQuery,
|
|
16
|
+
} from '../types.js';
|
|
6
17
|
|
|
7
18
|
const getAllOpenContracts = sql<IGetAllOpenContractsQuery>`
|
|
8
19
|
SELECT *
|
|
9
20
|
FROM accounter_schema.clients_contracts
|
|
10
21
|
WHERE is_active IS TRUE;`;
|
|
11
22
|
|
|
23
|
+
const getContractsByIds = sql<IGetContractsByIdsQuery>`
|
|
24
|
+
SELECT *
|
|
25
|
+
FROM accounter_schema.clients_contracts
|
|
26
|
+
WHERE id In $$ids;`;
|
|
27
|
+
|
|
28
|
+
const getContractsByClientIds = sql<IGetContractsByClientIdsQuery>`
|
|
29
|
+
SELECT *
|
|
30
|
+
FROM accounter_schema.clients_contracts
|
|
31
|
+
WHERE client_id IN $$clientIds;`;
|
|
32
|
+
|
|
33
|
+
const deleteContract = sql<IDeleteContractQuery>`
|
|
34
|
+
DELETE FROM accounter_schema.clients_contracts
|
|
35
|
+
WHERE id = $id;`;
|
|
36
|
+
|
|
37
|
+
const updateContract = sql<IUpdateContractQuery>`
|
|
38
|
+
UPDATE accounter_schema.clients_contracts
|
|
39
|
+
SET
|
|
40
|
+
client_id = COALESCE(
|
|
41
|
+
$client_id,
|
|
42
|
+
client_id
|
|
43
|
+
),
|
|
44
|
+
purchase_order = COALESCE(
|
|
45
|
+
$purchase_order,
|
|
46
|
+
purchase_order
|
|
47
|
+
),
|
|
48
|
+
start_date = COALESCE(
|
|
49
|
+
$start_date,
|
|
50
|
+
start_date
|
|
51
|
+
),
|
|
52
|
+
end_date = COALESCE(
|
|
53
|
+
$end_date,
|
|
54
|
+
end_date
|
|
55
|
+
),
|
|
56
|
+
remarks = COALESCE(
|
|
57
|
+
$remarks,
|
|
58
|
+
remarks
|
|
59
|
+
),
|
|
60
|
+
document_type = COALESCE(
|
|
61
|
+
$document_type,
|
|
62
|
+
document_type
|
|
63
|
+
),
|
|
64
|
+
amount = COALESCE(
|
|
65
|
+
$amount,
|
|
66
|
+
amount
|
|
67
|
+
),
|
|
68
|
+
currency = COALESCE(
|
|
69
|
+
$currency,
|
|
70
|
+
currency
|
|
71
|
+
),
|
|
72
|
+
billing_cycle = COALESCE(
|
|
73
|
+
$billing_cycle,
|
|
74
|
+
billing_cycle
|
|
75
|
+
),
|
|
76
|
+
product = COALESCE(
|
|
77
|
+
$product,
|
|
78
|
+
product
|
|
79
|
+
),
|
|
80
|
+
plan = COALESCE(
|
|
81
|
+
$plan,
|
|
82
|
+
plan
|
|
83
|
+
),
|
|
84
|
+
is_active = COALESCE(
|
|
85
|
+
$is_active,
|
|
86
|
+
is_active
|
|
87
|
+
),
|
|
88
|
+
ms_cloud = COALESCE(
|
|
89
|
+
$ms_cloud,
|
|
90
|
+
ms_cloud
|
|
91
|
+
)
|
|
92
|
+
WHERE
|
|
93
|
+
id = $contractId
|
|
94
|
+
RETURNING *;
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
const insertContract = sql<IInsertContractQuery>`
|
|
98
|
+
INSERT INTO accounter_schema.clients_contracts (
|
|
99
|
+
client_id,
|
|
100
|
+
purchase_order,
|
|
101
|
+
start_date,
|
|
102
|
+
end_date,
|
|
103
|
+
remarks,
|
|
104
|
+
document_type,
|
|
105
|
+
amount,
|
|
106
|
+
currency,
|
|
107
|
+
billing_cycle,
|
|
108
|
+
product,
|
|
109
|
+
plan,
|
|
110
|
+
is_active,
|
|
111
|
+
ms_cloud
|
|
112
|
+
)
|
|
113
|
+
VALUES ($clientId,
|
|
114
|
+
$purchaseOrder,
|
|
115
|
+
$startDate,
|
|
116
|
+
$endDate,
|
|
117
|
+
$remarks,
|
|
118
|
+
$documentType,
|
|
119
|
+
$amount,
|
|
120
|
+
$currency,
|
|
121
|
+
$billingCycle,
|
|
122
|
+
$product,
|
|
123
|
+
$plan,
|
|
124
|
+
$isActive,
|
|
125
|
+
$msCloud)
|
|
126
|
+
RETURNING *;`;
|
|
127
|
+
|
|
12
128
|
@Injectable({
|
|
13
129
|
scope: Scope.Singleton,
|
|
14
130
|
global: true,
|
|
@@ -36,6 +152,60 @@ export class ContractsProvider {
|
|
|
36
152
|
});
|
|
37
153
|
}
|
|
38
154
|
|
|
155
|
+
private async contractsByIds(ids: readonly string[]) {
|
|
156
|
+
const contracts = await getContractsByIds.run({ ids }, this.dbProvider);
|
|
157
|
+
return ids.map(id => contracts.find(contract => contract.id === id));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getContractsByIdLoader = new DataLoader(
|
|
161
|
+
(ids: readonly string[]) => this.contractsByIds(ids),
|
|
162
|
+
{
|
|
163
|
+
cacheKeyFn: id => `contract-${id}`,
|
|
164
|
+
cacheMap: this.cache,
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
private async contractsByClients(clientIds: readonly string[]) {
|
|
169
|
+
const contracts = await getContractsByClientIds.run({ clientIds }, this.dbProvider);
|
|
170
|
+
return clientIds.map(clientId => contracts.filter(contract => contract.client_id === clientId));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public getContractsByClientIdLoader = new DataLoader(
|
|
174
|
+
(ids: readonly string[]) => this.contractsByClients(ids),
|
|
175
|
+
{
|
|
176
|
+
cacheKeyFn: id => `client-contracts-${id}`,
|
|
177
|
+
cacheMap: this.cache,
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
public async createContract(params: IInsertContractParams) {
|
|
182
|
+
this.clearCache();
|
|
183
|
+
const [newContract] = await insertContract.run(params, this.dbProvider);
|
|
184
|
+
this.cache.set(`contract-${newContract.id}`, newContract);
|
|
185
|
+
return newContract;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public async updateContract(params: IUpdateContractParams) {
|
|
189
|
+
this.clearCache();
|
|
190
|
+
const [updatedContract] = await updateContract.run(params, this.dbProvider);
|
|
191
|
+
this.cache.set(`contract-${updatedContract.id}`, updatedContract);
|
|
192
|
+
return updatedContract;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public async deleteContract(contractId: string) {
|
|
196
|
+
await deleteContract.run({ id: contractId }, this.dbProvider);
|
|
197
|
+
this.clearCache();
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public async invalidateCacheForContract(contractId: string) {
|
|
202
|
+
const contract = await this.getContractsByIdLoader.load(contractId);
|
|
203
|
+
if (contract) {
|
|
204
|
+
this.cache.delete(`client-contracts-${contract.client_id}`);
|
|
205
|
+
}
|
|
206
|
+
this.cache.delete(`contract-${contractId}`);
|
|
207
|
+
}
|
|
208
|
+
|
|
39
209
|
public clearCache() {
|
|
40
210
|
this.cache.clear();
|
|
41
211
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
normalizeSubscriptionPlan,
|
|
9
9
|
} from '../helpers/contracts.helper.js';
|
|
10
10
|
import { ContractsProvider } from '../providers/contracts.provider.js';
|
|
11
|
-
import type { ContractsModule } from '../types.js';
|
|
11
|
+
import type { ContractsModule, IInsertContractParams, IUpdateContractParams } from '../types.js';
|
|
12
12
|
|
|
13
13
|
export const contractsResolvers: ContractsModule.Resolvers = {
|
|
14
14
|
Query: {
|
|
@@ -20,6 +20,72 @@ export const contractsResolvers: ContractsModule.Resolvers = {
|
|
|
20
20
|
throw new GraphQLError('Error fetching countries');
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
+
contractsByClient: async (_, { clientId }, { injector }) => {
|
|
24
|
+
try {
|
|
25
|
+
return injector.get(ContractsProvider).getContractsByClientIdLoader.load(clientId);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
const message = 'Error fetching contracts by client';
|
|
28
|
+
console.error(message, e);
|
|
29
|
+
throw new GraphQLError(message);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
Mutation: {
|
|
34
|
+
createContract: async (_, { input }, { injector }) => {
|
|
35
|
+
try {
|
|
36
|
+
const params: IInsertContractParams = {
|
|
37
|
+
amount: input.amount.raw,
|
|
38
|
+
billingCycle: input.billingCycle,
|
|
39
|
+
clientId: input.clientId,
|
|
40
|
+
currency: input.amount.currency,
|
|
41
|
+
documentType: input.documentType,
|
|
42
|
+
endDate: input.endDate,
|
|
43
|
+
isActive: input.isActive,
|
|
44
|
+
msCloud: input.msCloud?.toString(),
|
|
45
|
+
plan: input.plan,
|
|
46
|
+
product: input.product,
|
|
47
|
+
purchaseOrder: input.purchaseOrder,
|
|
48
|
+
remarks: input.remarks,
|
|
49
|
+
startDate: input.startDate,
|
|
50
|
+
};
|
|
51
|
+
return injector.get(ContractsProvider).createContract(params);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error('Error creating contract', e);
|
|
54
|
+
throw new GraphQLError('Error creating contract');
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
updateContract: async (_, { contractId, input }, { injector }) => {
|
|
58
|
+
try {
|
|
59
|
+
const params: IUpdateContractParams = {
|
|
60
|
+
contractId,
|
|
61
|
+
amount: input.amount?.raw,
|
|
62
|
+
billing_cycle: input.billingCycle,
|
|
63
|
+
client_id: input.clientId,
|
|
64
|
+
currency: input.amount?.currency,
|
|
65
|
+
document_type: input.documentType,
|
|
66
|
+
end_date: input.endDate,
|
|
67
|
+
is_active: input.isActive,
|
|
68
|
+
ms_cloud: input.msCloud?.toString(),
|
|
69
|
+
plan: input.plan,
|
|
70
|
+
product: input.product,
|
|
71
|
+
purchase_order: input.purchaseOrder,
|
|
72
|
+
remarks: input.remarks,
|
|
73
|
+
start_date: input.startDate,
|
|
74
|
+
};
|
|
75
|
+
return injector.get(ContractsProvider).updateContract(params);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.error('Error updating contract', e);
|
|
78
|
+
throw new GraphQLError('Error updating contract');
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
deleteContract: async (_, { id }, { injector }) => {
|
|
82
|
+
try {
|
|
83
|
+
return injector.get(ContractsProvider).deleteContract(id);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error('Error deleting contract', e);
|
|
86
|
+
throw new GraphQLError('Error deleting contract');
|
|
87
|
+
}
|
|
88
|
+
},
|
|
23
89
|
},
|
|
24
90
|
Contract: {
|
|
25
91
|
id: dbContract => dbContract.id,
|
|
@@ -46,7 +112,6 @@ export const contractsResolvers: ContractsModule.Resolvers = {
|
|
|
46
112
|
isActive: dbContract => dbContract.is_active ?? false, //Boolean!
|
|
47
113
|
product: dbContract => normalizeProduct(dbContract.product), //Product!
|
|
48
114
|
plan: dbContract => normalizeSubscriptionPlan(dbContract.plan), //SubscriptionPlan!
|
|
49
|
-
signedAgreement: dbContract => dbContract.signed_agreement, //URL
|
|
50
115
|
msCloud: dbContract => dbContract.ms_cloud, //URL
|
|
51
116
|
},
|
|
52
117
|
};
|
|
@@ -3,6 +3,14 @@ import { gql } from 'graphql-modules';
|
|
|
3
3
|
export default gql`
|
|
4
4
|
extend type Query {
|
|
5
5
|
allOpenContracts: [Contract!]! @auth(role: ACCOUNTANT)
|
|
6
|
+
contractsByClient(clientId: UUID!): [Contract!]! @auth(role: ACCOUNTANT)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
extend type Mutation {
|
|
10
|
+
updateContract(contractId: UUID!, input: UpdateContractInput!): Contract!
|
|
11
|
+
@auth(role: ACCOUNTANT)
|
|
12
|
+
deleteContract(id: UUID!): Boolean! @auth(role: ACCOUNTANT)
|
|
13
|
+
createContract(input: CreateContractInput!): Contract! @auth(role: ACCOUNTANT)
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
" a client contract "
|
|
@@ -19,7 +27,6 @@ export default gql`
|
|
|
19
27
|
isActive: Boolean!
|
|
20
28
|
product: Product
|
|
21
29
|
plan: SubscriptionPlan
|
|
22
|
-
signedAgreement: URL
|
|
23
30
|
msCloud: URL
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -40,4 +47,36 @@ export default gql`
|
|
|
40
47
|
ENTERPRISE
|
|
41
48
|
PRO
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
" input for creating a new contract "
|
|
52
|
+
input CreateContractInput {
|
|
53
|
+
clientId: UUID!
|
|
54
|
+
purchaseOrder: String
|
|
55
|
+
startDate: TimelessDate!
|
|
56
|
+
endDate: TimelessDate!
|
|
57
|
+
remarks: String
|
|
58
|
+
amount: FinancialAmountInput!
|
|
59
|
+
documentType: DocumentType!
|
|
60
|
+
billingCycle: BillingCycle!
|
|
61
|
+
product: Product
|
|
62
|
+
plan: SubscriptionPlan
|
|
63
|
+
msCloud: URL
|
|
64
|
+
isActive: Boolean!
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
" input for updating a contract "
|
|
68
|
+
input UpdateContractInput {
|
|
69
|
+
clientId: UUID
|
|
70
|
+
purchaseOrder: String
|
|
71
|
+
startDate: TimelessDate
|
|
72
|
+
endDate: TimelessDate
|
|
73
|
+
remarks: String
|
|
74
|
+
amount: FinancialAmountInput
|
|
75
|
+
documentType: DocumentType
|
|
76
|
+
billingCycle: BillingCycle
|
|
77
|
+
product: Product
|
|
78
|
+
plan: SubscriptionPlan
|
|
79
|
+
msCloud: URL
|
|
80
|
+
isActive: Boolean
|
|
81
|
+
}
|
|
43
82
|
`;
|
|
@@ -110,6 +110,41 @@ export interface IGetDocumentsByIdsQuery {
|
|
|
110
110
|
result: IGetDocumentsByIdsResult;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/** 'GetDocumentsByBusinessIds' parameters type */
|
|
114
|
+
export interface IGetDocumentsByBusinessIdsParams {
|
|
115
|
+
Ids: readonly (string | null | void)[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** 'GetDocumentsByBusinessIds' return type */
|
|
119
|
+
export interface IGetDocumentsByBusinessIdsResult {
|
|
120
|
+
allocation_number: string | null;
|
|
121
|
+
charge_id: string | null;
|
|
122
|
+
created_at: Date;
|
|
123
|
+
creditor_id: string | null;
|
|
124
|
+
currency_code: currency | null;
|
|
125
|
+
date: Date | null;
|
|
126
|
+
debtor_id: string | null;
|
|
127
|
+
exchange_rate_override: string | null;
|
|
128
|
+
file_hash: string | null;
|
|
129
|
+
file_url: string | null;
|
|
130
|
+
id: string;
|
|
131
|
+
image_url: string | null;
|
|
132
|
+
is_reviewed: boolean;
|
|
133
|
+
modified_at: Date;
|
|
134
|
+
no_vat_amount: string | null;
|
|
135
|
+
serial_number: string | null;
|
|
136
|
+
total_amount: number | null;
|
|
137
|
+
type: document_type;
|
|
138
|
+
vat_amount: number | null;
|
|
139
|
+
vat_report_date_override: Date | null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** 'GetDocumentsByBusinessIds' query type */
|
|
143
|
+
export interface IGetDocumentsByBusinessIdsQuery {
|
|
144
|
+
params: IGetDocumentsByBusinessIdsParams;
|
|
145
|
+
result: IGetDocumentsByBusinessIdsResult;
|
|
146
|
+
}
|
|
147
|
+
|
|
113
148
|
/** 'GetDocumentsByHashes' parameters type */
|
|
114
149
|
export interface IGetDocumentsByHashesParams {
|
|
115
150
|
hashes: readonly (string | null | void)[];
|
|
@@ -3,7 +3,7 @@ import * as gm from "graphql-modules";
|
|
|
3
3
|
export namespace DocumentsModule {
|
|
4
4
|
interface DefinedFields {
|
|
5
5
|
DocumentSuggestions: 'owner' | 'counterparty' | 'amount' | 'isIncome';
|
|
6
|
-
Query: 'documents' | 'documentsByFilters' | 'documentById' | 'recentDocumentsByClient' | 'recentIssuedDocumentsByType';
|
|
6
|
+
Query: 'documents' | 'documentsByFilters' | 'documentById' | 'recentDocumentsByBusiness' | 'recentDocumentsByClient' | 'recentIssuedDocumentsByType';
|
|
7
7
|
Mutation: 'insertDocument' | 'updateDocument' | 'deleteDocument' | 'uploadDocument' | 'batchUploadDocuments' | 'batchUploadDocumentsFromGoogleDrive' | 'closeDocument';
|
|
8
8
|
Unprocessed: 'id' | 'image' | 'file' | 'documentType' | 'isReviewed';
|
|
9
9
|
OtherDocument: 'id' | 'image' | 'file' | 'documentType' | 'isReviewed';
|
|
@@ -254,6 +254,7 @@ export namespace DocumentsModule {
|
|
|
254
254
|
documents?: gm.Middleware[];
|
|
255
255
|
documentsByFilters?: gm.Middleware[];
|
|
256
256
|
documentById?: gm.Middleware[];
|
|
257
|
+
recentDocumentsByBusiness?: gm.Middleware[];
|
|
257
258
|
recentDocumentsByClient?: gm.Middleware[];
|
|
258
259
|
recentIssuedDocumentsByType?: gm.Middleware[];
|
|
259
260
|
};
|