@accounter/server 0.0.8-alpha-20251021150615-800574fc6d416cd319de216c97b431643d8958a2 → 0.0.8-alpha-20251021163440-2ab1a9ffaec95fd99fac5495c3a392b97429ce77
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/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
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
IGetAllDocumentsParams,
|
|
11
11
|
IGetAllDocumentsQuery,
|
|
12
12
|
IGetAllDocumentsResult,
|
|
13
|
+
IGetDocumentsByBusinessIdsQuery,
|
|
13
14
|
IGetDocumentsByChargeIdQuery,
|
|
14
15
|
IGetDocumentsByExtendedFiltersParams,
|
|
15
16
|
IGetDocumentsByExtendedFiltersQuery,
|
|
@@ -45,6 +46,12 @@ const getDocumentsByIds = sql<IGetDocumentsByIdsQuery>`
|
|
|
45
46
|
WHERE id IN $$Ids;
|
|
46
47
|
`;
|
|
47
48
|
|
|
49
|
+
const getDocumentsByBusinessIds = sql<IGetDocumentsByBusinessIdsQuery>`
|
|
50
|
+
SELECT *
|
|
51
|
+
FROM accounter_schema.documents
|
|
52
|
+
WHERE debtor_id IN $$Ids OR creditor_id IN $$Ids;
|
|
53
|
+
`;
|
|
54
|
+
|
|
48
55
|
const getDocumentsByHashes = sql<IGetDocumentsByHashesQuery>`
|
|
49
56
|
SELECT *
|
|
50
57
|
FROM accounter_schema.documents
|
|
@@ -369,6 +376,28 @@ export class DocumentsProvider {
|
|
|
369
376
|
},
|
|
370
377
|
);
|
|
371
378
|
|
|
379
|
+
private async batchDocumentsByBusinessIds(businessIds: readonly string[]) {
|
|
380
|
+
const uniqueIDs = [...new Set(businessIds)];
|
|
381
|
+
try {
|
|
382
|
+
const docs = await getDocumentsByBusinessIds.run({ Ids: uniqueIDs }, this.dbProvider);
|
|
383
|
+
|
|
384
|
+
return businessIds.map(id =>
|
|
385
|
+
docs.filter(doc => doc.creditor_id === id || doc.debtor_id === id),
|
|
386
|
+
);
|
|
387
|
+
} catch (e) {
|
|
388
|
+
console.error(e);
|
|
389
|
+
return businessIds.map(() => null);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
public getDocumentsByBusinessIdLoader = new DataLoader(
|
|
394
|
+
(businessIds: readonly string[]) => this.batchDocumentsByBusinessIds(businessIds),
|
|
395
|
+
{
|
|
396
|
+
cacheKeyFn: key => `documents-by-business-${key}`,
|
|
397
|
+
cacheMap: this.cache,
|
|
398
|
+
},
|
|
399
|
+
);
|
|
400
|
+
|
|
372
401
|
private async batchDocumentsByHash(hashes: readonly number[]) {
|
|
373
402
|
const uniqueHashes = [...new Set(hashes)];
|
|
374
403
|
try {
|
|
@@ -442,6 +471,8 @@ export class DocumentsProvider {
|
|
|
442
471
|
if (document) {
|
|
443
472
|
this.cache.delete(`document-by-charge-${document.charge_id}`);
|
|
444
473
|
this.cache.delete(`document-hash-${document.file_hash}`);
|
|
474
|
+
this.cache.delete(`documents-by-business-${document.debtor_id}`);
|
|
475
|
+
this.cache.delete(`documents-by-business-${document.creditor_id}`);
|
|
445
476
|
}
|
|
446
477
|
this.cache.delete(`document-${id}`);
|
|
447
478
|
this.cache.delete('all-documents');
|
|
@@ -449,7 +480,11 @@ export class DocumentsProvider {
|
|
|
449
480
|
|
|
450
481
|
public async invalidateByChargeId(chargeId: string) {
|
|
451
482
|
const documents = await this.getDocumentsByChargeIdLoader.load(chargeId);
|
|
452
|
-
documents.map(doc =>
|
|
483
|
+
documents.map(doc => {
|
|
484
|
+
this.cache.delete(`document-${doc.id}`);
|
|
485
|
+
this.cache.delete(`documents-by-business-${doc.debtor_id}`);
|
|
486
|
+
this.cache.delete(`documents-by-business-${doc.creditor_id}`);
|
|
487
|
+
});
|
|
453
488
|
this.cache.delete(`document-by-charge-${chargeId}`);
|
|
454
489
|
this.cache.delete('all-documents');
|
|
455
490
|
}
|
|
@@ -43,6 +43,18 @@ export const documentsResolvers: DocumentsModule.Resolvers &
|
|
|
43
43
|
const doc = await injector.get(DocumentsProvider).getDocumentsByIdLoader.load(documentId);
|
|
44
44
|
return doc ?? null;
|
|
45
45
|
},
|
|
46
|
+
recentDocumentsByBusiness: async (_, { businessId, limit }, { injector }) => {
|
|
47
|
+
const businessDocs = await injector
|
|
48
|
+
.get(DocumentsProvider)
|
|
49
|
+
.getDocumentsByBusinessIdLoader.load(businessId);
|
|
50
|
+
if (!businessDocs?.length) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
const sortedDocs = [...businessDocs].sort(
|
|
54
|
+
(a, b) => (b.date ?? b.created_at).getTime() - (a.date ?? a.created_at).getTime(),
|
|
55
|
+
);
|
|
56
|
+
return sortedDocs.slice(0, limit ?? 7);
|
|
57
|
+
},
|
|
46
58
|
recentDocumentsByClient: async (_, { clientId, limit }, { injector }) => {
|
|
47
59
|
const clientDocs = await injector
|
|
48
60
|
.get(IssuedDocumentsProvider)
|
|
@@ -5,6 +5,7 @@ export default gql`
|
|
|
5
5
|
documents: [Document!]! @auth(role: ACCOUNTANT)
|
|
6
6
|
documentsByFilters(filters: DocumentsFilters!): [Document!]! @auth(role: ACCOUNTANT)
|
|
7
7
|
documentById(documentId: UUID!): Document @auth(role: ACCOUNTANT)
|
|
8
|
+
recentDocumentsByBusiness(businessId: UUID!, limit: Int): [Document!]! @auth(role: ACCOUNTANT)
|
|
8
9
|
recentDocumentsByClient(clientId: UUID!, limit: Int): [Document!]! @auth(role: ACCOUNTANT)
|
|
9
10
|
recentIssuedDocumentsByType(documentType: DocumentType!, limit: Int): [Document!]!
|
|
10
11
|
@auth(role: ACCOUNTANT)
|
|
@@ -107,6 +107,8 @@ export interface IDeleteClientQuery {
|
|
|
107
107
|
|
|
108
108
|
/** 'InsertClient' parameters type */
|
|
109
109
|
export interface IInsertClientParams {
|
|
110
|
+
businessId?: string | null | void;
|
|
111
|
+
emails?: stringArray | null | void;
|
|
110
112
|
greenInvoiceId?: string | null | void;
|
|
111
113
|
hiveId?: string | null | void;
|
|
112
114
|
}
|
|
@@ -10,14 +10,14 @@ export namespace FinancialEntitiesModule {
|
|
|
10
10
|
BusinessTransactionsFromLedgerRecordsSuccessfulResult: 'businessTransactions';
|
|
11
11
|
BusinessTransaction: 'amount' | 'business' | 'foreignAmount' | 'invoiceDate' | 'reference' | 'details' | 'counterAccount' | 'chargeId';
|
|
12
12
|
PaginatedBusinesses: 'nodes' | 'pageInfo';
|
|
13
|
-
LtdFinancialEntity: 'id' | 'country' | 'governmentId' | 'name' | 'address' | 'hebrewName' | 'email' | 'website' | 'phoneNumber' | 'exemptDealer' | 'optionalVAT' | 'suggestions' | 'pcn874RecordType' | 'irsCode' | 'isActive' | 'isReceiptEnough' | 'isDocumentsOptional' | 'taxCategory';
|
|
13
|
+
LtdFinancialEntity: 'id' | 'country' | 'governmentId' | 'name' | 'address' | 'hebrewName' | 'email' | 'website' | 'phoneNumber' | 'exemptDealer' | 'optionalVAT' | 'suggestions' | 'pcn874RecordType' | 'irsCode' | 'isActive' | 'isReceiptEnough' | 'isDocumentsOptional' | 'createdAt' | 'updatedAt' | 'clientInfo' | 'taxCategory';
|
|
14
14
|
Suggestions: 'phrases' | 'tags' | 'description' | 'emails' | 'emailListener' | 'priority';
|
|
15
15
|
SuggestionsEmailListenerConfig: 'internalEmailLinks' | 'emailBody' | 'attachments';
|
|
16
|
-
PersonalFinancialEntity: 'id' | 'name' | 'email' | 'pcn874RecordType' | 'irsCode';
|
|
17
|
-
Mutation: 'updateBusiness' | 'insertNewBusiness' | 'mergeBusinesses' | 'batchGenerateBusinessesOutOfTransactions' | 'updateTaxCategory' | 'insertTaxCategory';
|
|
18
|
-
Client: 'id' | 'originalBusiness' | 'greenInvoiceId' | 'emails' | 'generatedDocumentType' | 'greenInvoiceInfo';
|
|
16
|
+
PersonalFinancialEntity: 'id' | 'name' | 'email' | 'pcn874RecordType' | 'irsCode' | 'isActive' | 'createdAt' | 'updatedAt';
|
|
17
|
+
Mutation: 'updateBusiness' | 'insertNewBusiness' | 'mergeBusinesses' | 'batchGenerateBusinessesOutOfTransactions' | 'updateClient' | 'insertClient' | 'updateTaxCategory' | 'insertTaxCategory';
|
|
18
|
+
Client: 'id' | 'originalBusiness' | 'greenInvoiceId' | 'hiveId' | 'emails' | 'generatedDocumentType' | 'greenInvoiceInfo';
|
|
19
19
|
PaginatedFinancialEntities: 'nodes' | 'pageInfo';
|
|
20
|
-
TaxCategory: 'id' | 'name' | 'irsCode';
|
|
20
|
+
TaxCategory: 'id' | 'name' | 'irsCode' | 'createdAt' | 'updatedAt' | 'isActive';
|
|
21
21
|
CommonCharge: 'owner' | 'counterparty' | 'taxCategory';
|
|
22
22
|
FinancialCharge: 'owner' | 'counterparty' | 'taxCategory';
|
|
23
23
|
ConversionCharge: 'owner' | 'counterparty' | 'taxCategory';
|
|
@@ -37,8 +37,8 @@ export namespace FinancialEntitiesModule {
|
|
|
37
37
|
InvoiceReceipt: 'creditor' | 'debtor';
|
|
38
38
|
CreditInvoice: 'creditor' | 'debtor';
|
|
39
39
|
LedgerRecord: 'debitAccount1' | 'debitAccount2' | 'creditAccount1' | 'creditAccount2';
|
|
40
|
-
Business: 'id' | 'name' | 'pcn874RecordType' | 'irsCode';
|
|
41
|
-
FinancialEntity: 'id' | 'name' | 'irsCode';
|
|
40
|
+
Business: 'id' | 'name' | 'pcn874RecordType' | 'irsCode' | 'isActive' | 'createdAt' | 'updatedAt';
|
|
41
|
+
FinancialEntity: 'id' | 'name' | 'irsCode' | 'createdAt' | 'updatedAt' | 'isActive';
|
|
42
42
|
Charge: 'owner' | 'counterparty' | 'taxCategory';
|
|
43
43
|
Transaction: 'counterparty';
|
|
44
44
|
FinancialDocument: 'creditor' | 'debtor';
|
|
@@ -55,6 +55,8 @@ export namespace FinancialEntitiesModule {
|
|
|
55
55
|
InsertNewBusinessInput: 'name' | 'sortCode' | 'country' | 'hebrewName' | 'address' | 'email' | 'website' | 'phoneNumber' | 'governmentId' | 'taxCategory' | 'exemptDealer' | 'suggestions' | 'optionalVAT' | 'isReceiptEnough' | 'isDocumentsOptional' | 'pcn874RecordType' | 'irsCode' | 'isActive';
|
|
56
56
|
SuggestionsInput: 'phrases' | 'tags' | 'description' | 'emails' | 'emailListener' | 'priority';
|
|
57
57
|
SuggestionsEmailListenerConfigInput: 'internalEmailLinks' | 'emailBody' | 'attachments';
|
|
58
|
+
ClientInsertInput: 'businessId' | 'greenInvoiceId' | 'hiveId' | 'emails' | 'generatedDocumentType';
|
|
59
|
+
ClientUpdateInput: 'greenInvoiceId' | 'hiveId' | 'emails' | 'generatedDocumentType' | 'newBusinessId';
|
|
58
60
|
UpdateTaxCategoryInput: 'name' | 'sortCode' | 'irsCode' | 'isActive' | 'hashavshevetName' | 'taxExcluded';
|
|
59
61
|
InsertTaxCategoryInput: 'name' | 'sortCode' | 'irsCode' | 'hashavshevetName' | 'taxExcluded' | 'isActive';
|
|
60
62
|
UpdateChargeInput: 'counterpartyId' | 'ownerId';
|
|
@@ -81,6 +83,7 @@ export namespace FinancialEntitiesModule {
|
|
|
81
83
|
export type Business = Pick<Types.Business, DefinedFields['Business']>;
|
|
82
84
|
export type PaginatedBusinesses = Pick<Types.PaginatedBusinesses, DefinedFields['PaginatedBusinesses']>;
|
|
83
85
|
export type Pcn874RecordType = Types.Pcn874RecordType;
|
|
86
|
+
export type DateTime = Types.DateTime;
|
|
84
87
|
export type PageInfo = Types.PageInfo;
|
|
85
88
|
export type Suggestions = Pick<Types.Suggestions, DefinedFields['Suggestions']>;
|
|
86
89
|
export type Tag = Types.Tag;
|
|
@@ -107,6 +110,9 @@ export namespace FinancialEntitiesModule {
|
|
|
107
110
|
export type ForeignSecuritiesCharge = Types.ForeignSecuritiesCharge;
|
|
108
111
|
export type CreditcardBankCharge = Types.CreditcardBankCharge;
|
|
109
112
|
export type Client = Pick<Types.Client, DefinedFields['Client']>;
|
|
113
|
+
export type UpdateClientResponse = Types.UpdateClientResponse;
|
|
114
|
+
export type ClientUpdateInput = Pick<Types.ClientUpdateInput, DefinedInputFields['ClientUpdateInput']>;
|
|
115
|
+
export type ClientInsertInput = Pick<Types.ClientInsertInput, DefinedInputFields['ClientInsertInput']>;
|
|
110
116
|
export type DocumentType = Types.DocumentType;
|
|
111
117
|
export type GreenInvoiceClient = Types.GreenInvoiceClient;
|
|
112
118
|
export type PaginatedFinancialEntities = Pick<Types.PaginatedFinancialEntities, DefinedFields['PaginatedFinancialEntities']>;
|
|
@@ -291,6 +297,9 @@ export namespace FinancialEntitiesModule {
|
|
|
291
297
|
isActive?: gm.Middleware[];
|
|
292
298
|
isReceiptEnough?: gm.Middleware[];
|
|
293
299
|
isDocumentsOptional?: gm.Middleware[];
|
|
300
|
+
createdAt?: gm.Middleware[];
|
|
301
|
+
updatedAt?: gm.Middleware[];
|
|
302
|
+
clientInfo?: gm.Middleware[];
|
|
294
303
|
taxCategory?: gm.Middleware[];
|
|
295
304
|
};
|
|
296
305
|
Suggestions?: {
|
|
@@ -315,6 +324,9 @@ export namespace FinancialEntitiesModule {
|
|
|
315
324
|
email?: gm.Middleware[];
|
|
316
325
|
pcn874RecordType?: gm.Middleware[];
|
|
317
326
|
irsCode?: gm.Middleware[];
|
|
327
|
+
isActive?: gm.Middleware[];
|
|
328
|
+
createdAt?: gm.Middleware[];
|
|
329
|
+
updatedAt?: gm.Middleware[];
|
|
318
330
|
};
|
|
319
331
|
Mutation?: {
|
|
320
332
|
'*'?: gm.Middleware[];
|
|
@@ -322,6 +334,8 @@ export namespace FinancialEntitiesModule {
|
|
|
322
334
|
insertNewBusiness?: gm.Middleware[];
|
|
323
335
|
mergeBusinesses?: gm.Middleware[];
|
|
324
336
|
batchGenerateBusinessesOutOfTransactions?: gm.Middleware[];
|
|
337
|
+
updateClient?: gm.Middleware[];
|
|
338
|
+
insertClient?: gm.Middleware[];
|
|
325
339
|
updateTaxCategory?: gm.Middleware[];
|
|
326
340
|
insertTaxCategory?: gm.Middleware[];
|
|
327
341
|
};
|
|
@@ -396,6 +410,7 @@ export namespace FinancialEntitiesModule {
|
|
|
396
410
|
id?: gm.Middleware[];
|
|
397
411
|
originalBusiness?: gm.Middleware[];
|
|
398
412
|
greenInvoiceId?: gm.Middleware[];
|
|
413
|
+
hiveId?: gm.Middleware[];
|
|
399
414
|
emails?: gm.Middleware[];
|
|
400
415
|
generatedDocumentType?: gm.Middleware[];
|
|
401
416
|
greenInvoiceInfo?: gm.Middleware[];
|
|
@@ -450,6 +465,9 @@ export namespace FinancialEntitiesModule {
|
|
|
450
465
|
id?: gm.Middleware[];
|
|
451
466
|
name?: gm.Middleware[];
|
|
452
467
|
irsCode?: gm.Middleware[];
|
|
468
|
+
createdAt?: gm.Middleware[];
|
|
469
|
+
updatedAt?: gm.Middleware[];
|
|
470
|
+
isActive?: gm.Middleware[];
|
|
453
471
|
};
|
|
454
472
|
};
|
|
455
473
|
}
|
|
@@ -67,8 +67,8 @@ const deleteClient = sql<IDeleteClientQuery>`
|
|
|
67
67
|
`;
|
|
68
68
|
|
|
69
69
|
const insertClient = sql<IInsertClientQuery>`
|
|
70
|
-
INSERT INTO accounter_schema.clients (green_invoice_id, hive_id)
|
|
71
|
-
VALUES ($greenInvoiceId, $hiveId)
|
|
70
|
+
INSERT INTO accounter_schema.clients (business_id, green_invoice_id, hive_id, emails)
|
|
71
|
+
VALUES ($businessId, $greenInvoiceId, $hiveId, $emails)
|
|
72
72
|
RETURNING *;`;
|
|
73
73
|
|
|
74
74
|
@Injectable({
|
|
@@ -572,7 +572,6 @@ export const businessesResolvers: FinancialEntitiesModule.Resolvers &
|
|
|
572
572
|
},
|
|
573
573
|
optionalVAT: DbBusiness => DbBusiness.optional_vat,
|
|
574
574
|
pcn874RecordType: DbBusiness => DbBusiness.pcn874_record_type_override,
|
|
575
|
-
isActive: DbBusiness => !!DbBusiness.is_active,
|
|
576
575
|
isReceiptEnough: DbBusiness => DbBusiness.can_settle_with_receipt,
|
|
577
576
|
isDocumentsOptional: DbBusiness => DbBusiness.no_invoices_required,
|
|
578
577
|
},
|
|
@@ -2,7 +2,11 @@ import { GraphQLError } from 'graphql';
|
|
|
2
2
|
import { GreenInvoiceClientProvider } from '@modules/app-providers/green-invoice-client.js';
|
|
3
3
|
import { BusinessesProvider } from '@modules/financial-entities/providers/businesses.provider.js';
|
|
4
4
|
import { ClientsProvider } from '../providers/clients.provider.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
FinancialEntitiesModule,
|
|
7
|
+
IInsertClientParams,
|
|
8
|
+
IUpdateClientParams,
|
|
9
|
+
} from '../types.js';
|
|
6
10
|
|
|
7
11
|
export const clientsResolvers: FinancialEntitiesModule.Resolvers = {
|
|
8
12
|
Query: {
|
|
@@ -33,6 +37,59 @@ export const clientsResolvers: FinancialEntitiesModule.Resolvers = {
|
|
|
33
37
|
}
|
|
34
38
|
},
|
|
35
39
|
},
|
|
40
|
+
Mutation: {
|
|
41
|
+
updateClient: async (_, { businessId, fields }, { injector }) => {
|
|
42
|
+
const adjustedFields: IUpdateClientParams = {
|
|
43
|
+
businessId,
|
|
44
|
+
emails: fields.emails ? [...fields.emails] : undefined,
|
|
45
|
+
greenInvoiceId: fields.greenInvoiceId,
|
|
46
|
+
hiveId: fields.hiveId,
|
|
47
|
+
newBusinessId: fields.newBusinessId,
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const [updatedClient] = await injector
|
|
51
|
+
.get(ClientsProvider)
|
|
52
|
+
.updateClient({ ...adjustedFields, businessId })
|
|
53
|
+
.catch((e: Error) => {
|
|
54
|
+
const message = `Error updating client ID="${businessId}"`;
|
|
55
|
+
console.error(`${message}: ${e}`);
|
|
56
|
+
if (e instanceof GraphQLError) {
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(message);
|
|
60
|
+
});
|
|
61
|
+
return updatedClient;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return {
|
|
64
|
+
__typename: 'CommonError',
|
|
65
|
+
message: `Failed to update client ID="${businessId}": ${(e as Error).message}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
insertClient: async (_, { fields }, { injector }) => {
|
|
70
|
+
try {
|
|
71
|
+
const newClient: IInsertClientParams = {
|
|
72
|
+
businessId: fields.businessId,
|
|
73
|
+
emails: fields.emails ? [...fields.emails] : [],
|
|
74
|
+
greenInvoiceId: fields.greenInvoiceId,
|
|
75
|
+
hiveId: fields.hiveId,
|
|
76
|
+
};
|
|
77
|
+
const [insertClient] = await injector.get(ClientsProvider).insertClient(newClient);
|
|
78
|
+
|
|
79
|
+
if (!insertClient) {
|
|
80
|
+
throw new Error(`No client returned after insertion`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return insertClient;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error(e);
|
|
86
|
+
return {
|
|
87
|
+
__typename: 'CommonError',
|
|
88
|
+
message: `Failed to create Client`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
36
93
|
Client: {
|
|
37
94
|
id: business => business.green_invoice_id,
|
|
38
95
|
originalBusiness: async (business, _, { injector }) => {
|
|
@@ -47,6 +104,7 @@ export const clientsResolvers: FinancialEntitiesModule.Resolvers = {
|
|
|
47
104
|
return businessMatch;
|
|
48
105
|
},
|
|
49
106
|
greenInvoiceId: business => business.green_invoice_id,
|
|
107
|
+
hiveId: business => business.hive_id,
|
|
50
108
|
emails: business => business.emails ?? [],
|
|
51
109
|
greenInvoiceInfo: async (business, _, { injector }) => {
|
|
52
110
|
const client = await injector
|
|
@@ -65,4 +123,11 @@ export const clientsResolvers: FinancialEntitiesModule.Resolvers = {
|
|
|
65
123
|
};
|
|
66
124
|
},
|
|
67
125
|
},
|
|
126
|
+
LtdFinancialEntity: {
|
|
127
|
+
clientInfo: async (business, _, { injector }) => {
|
|
128
|
+
const client = await injector.get(ClientsProvider).getClientByIdLoader.load(business.id);
|
|
129
|
+
|
|
130
|
+
return client || null;
|
|
131
|
+
},
|
|
132
|
+
},
|
|
68
133
|
};
|
|
@@ -12,6 +12,9 @@ export const commonFinancialEntityFields:
|
|
|
12
12
|
id: dbFinancialEntity => dbFinancialEntity.id,
|
|
13
13
|
name: dbFinancialEntity => dbFinancialEntity.name,
|
|
14
14
|
irsCode: dbFinancialEntity => dbFinancialEntity.irs_code,
|
|
15
|
+
isActive: dbFinancialEntity => !!dbFinancialEntity.is_active,
|
|
16
|
+
createdAt: dbFinancialEntity => dbFinancialEntity.created_at,
|
|
17
|
+
updatedAt: dbFinancialEntity => dbFinancialEntity.updated_at,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
export const commonTaxChargeFields: FinancialEntitiesModule.ChargeResolvers = {
|
|
@@ -14,6 +14,9 @@ export default gql`
|
|
|
14
14
|
|
|
15
15
|
pcn874RecordType: Pcn874RecordType
|
|
16
16
|
irsCode: Int
|
|
17
|
+
isActive: Boolean!
|
|
18
|
+
createdAt: DateTime!
|
|
19
|
+
updatedAt: DateTime!
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
" response for paginated Financial Entities "
|
|
@@ -44,6 +47,8 @@ export default gql`
|
|
|
44
47
|
isActive: Boolean!
|
|
45
48
|
isReceiptEnough: Boolean
|
|
46
49
|
isDocumentsOptional: Boolean
|
|
50
|
+
createdAt: DateTime!
|
|
51
|
+
updatedAt: DateTime!
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
" input for business suggestions "
|
|
@@ -77,6 +82,9 @@ export default gql`
|
|
|
77
82
|
|
|
78
83
|
pcn874RecordType: Pcn874RecordType
|
|
79
84
|
irsCode: Int
|
|
85
|
+
isActive: Boolean!
|
|
86
|
+
createdAt: DateTime!
|
|
87
|
+
updatedAt: DateTime!
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
extend type Mutation {
|
|
@@ -6,13 +6,45 @@ export default gql`
|
|
|
6
6
|
allClients: [Client!]! @auth(role: ACCOUNTANT)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
extend type Mutation {
|
|
10
|
+
updateClient(businessId: UUID!, fields: ClientUpdateInput!): UpdateClientResponse!
|
|
11
|
+
@auth(role: ACCOUNTANT)
|
|
12
|
+
insertClient(fields: ClientInsertInput!): UpdateClientResponse! @auth(role: ACCOUNTANT)
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
" business extended with green invoice data "
|
|
10
16
|
type Client {
|
|
11
17
|
id: UUID!
|
|
12
18
|
originalBusiness: LtdFinancialEntity!
|
|
13
19
|
greenInvoiceId: UUID!
|
|
20
|
+
hiveId: String
|
|
14
21
|
emails: [String!]!
|
|
15
22
|
generatedDocumentType: DocumentType!
|
|
16
23
|
greenInvoiceInfo: GreenInvoiceClient!
|
|
17
24
|
}
|
|
25
|
+
|
|
26
|
+
" fields for inserting a new client "
|
|
27
|
+
input ClientInsertInput {
|
|
28
|
+
businessId: UUID!
|
|
29
|
+
greenInvoiceId: UUID!
|
|
30
|
+
hiveId: String
|
|
31
|
+
emails: [String!]
|
|
32
|
+
generatedDocumentType: DocumentType!
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
" fields for updating an existing client "
|
|
36
|
+
input ClientUpdateInput {
|
|
37
|
+
greenInvoiceId: UUID
|
|
38
|
+
hiveId: String
|
|
39
|
+
emails: [String!]
|
|
40
|
+
generatedDocumentType: DocumentType
|
|
41
|
+
newBusinessId: UUID
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
" result type for updateClient "
|
|
45
|
+
union UpdateClientResponse = Client | CommonError
|
|
46
|
+
|
|
47
|
+
extend type LtdFinancialEntity {
|
|
48
|
+
clientInfo: Client
|
|
49
|
+
}
|
|
18
50
|
`;
|
|
@@ -2,7 +2,7 @@ import * as Types from "../../../__generated__/types.js";
|
|
|
2
2
|
import * as gm from "graphql-modules";
|
|
3
3
|
export namespace GreenInvoiceModule {
|
|
4
4
|
interface DefinedFields {
|
|
5
|
-
Query: 'newDocumentInfoDraftByCharge' | 'newDocumentInfoDraftByDocument' | 'clientMonthlyChargesDrafts' | 'clientMonthlyChargeDraft';
|
|
5
|
+
Query: 'newDocumentInfoDraftByCharge' | 'newDocumentInfoDraftByDocument' | 'clientMonthlyChargesDrafts' | 'clientMonthlyChargeDraft' | 'greenInvoiceClient';
|
|
6
6
|
Mutation: 'fetchIncomeDocuments' | 'issueGreenInvoiceDocuments' | 'previewGreenInvoiceDocument' | 'issueGreenInvoiceDocument';
|
|
7
7
|
GenerateMonthlyClientDocumentsResult: 'success' | 'errors';
|
|
8
8
|
NewDocumentInfo: 'description' | 'remarks' | 'footer' | 'type' | 'date' | 'dueDate' | 'lang' | 'currency' | 'vatType' | 'discount' | 'rounding' | 'signed' | 'maxPayments' | 'client' | 'income' | 'payment' | 'linkedDocumentIds' | 'linkedPaymentId' | 'linkType';
|
|
@@ -38,6 +38,7 @@ export namespace GreenInvoiceModule {
|
|
|
38
38
|
export type NewDocumentInfo = Pick<Types.NewDocumentInfo, DefinedFields['NewDocumentInfo']>;
|
|
39
39
|
export type UUID = Types.Uuid;
|
|
40
40
|
export type TimelessDate = Types.TimelessDate;
|
|
41
|
+
export type GreenInvoiceClient = Pick<Types.GreenInvoiceClient, DefinedFields['GreenInvoiceClient']>;
|
|
41
42
|
export type Mutation = Pick<Types.Mutation, DefinedFields['Mutation']>;
|
|
42
43
|
export type Document = Types.Document;
|
|
43
44
|
export type GenerateMonthlyClientDocumentsResult = Pick<Types.GenerateMonthlyClientDocumentsResult, DefinedFields['GenerateMonthlyClientDocumentsResult']>;
|
|
@@ -50,7 +51,6 @@ export namespace GreenInvoiceModule {
|
|
|
50
51
|
export type Currency = Types.Currency;
|
|
51
52
|
export type GreenInvoiceVatType = DefinedEnumValues['GreenInvoiceVatType'];
|
|
52
53
|
export type GreenInvoiceDiscount = Pick<Types.GreenInvoiceDiscount, DefinedFields['GreenInvoiceDiscount']>;
|
|
53
|
-
export type GreenInvoiceClient = Pick<Types.GreenInvoiceClient, DefinedFields['GreenInvoiceClient']>;
|
|
54
54
|
export type GreenInvoiceIncome = Pick<Types.GreenInvoiceIncome, DefinedFields['GreenInvoiceIncome']>;
|
|
55
55
|
export type GreenInvoicePayment = Pick<Types.GreenInvoicePayment, DefinedFields['GreenInvoicePayment']>;
|
|
56
56
|
export type GreenInvoiceLinkType = DefinedEnumValues['GreenInvoiceLinkType'];
|
|
@@ -98,6 +98,7 @@ export namespace GreenInvoiceModule {
|
|
|
98
98
|
newDocumentInfoDraftByDocument?: gm.Middleware[];
|
|
99
99
|
clientMonthlyChargesDrafts?: gm.Middleware[];
|
|
100
100
|
clientMonthlyChargeDraft?: gm.Middleware[];
|
|
101
|
+
greenInvoiceClient?: gm.Middleware[];
|
|
101
102
|
};
|
|
102
103
|
Mutation?: {
|
|
103
104
|
'*'?: gm.Middleware[];
|
|
@@ -495,6 +495,25 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
495
495
|
|
|
496
496
|
return draft;
|
|
497
497
|
},
|
|
498
|
+
greenInvoiceClient: async (_, { clientId }, { injector }) => {
|
|
499
|
+
try {
|
|
500
|
+
const client = await injector.get(ClientsProvider).getClientByIdLoader.load(clientId);
|
|
501
|
+
if (!client) {
|
|
502
|
+
throw new GraphQLError(`Client not found for ID="${clientId}"`);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const greenInvoiceClient = await getClientFromGreenInvoiceClient(injector, clientId);
|
|
506
|
+
if (!greenInvoiceClient) {
|
|
507
|
+
throw new GraphQLError(`Green invoice match not found for client ID="${clientId}"`);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return greenInvoiceClient;
|
|
511
|
+
} catch (error) {
|
|
512
|
+
const message = 'Failed to fetch Green Invoice client';
|
|
513
|
+
console.error(message, error);
|
|
514
|
+
throw new GraphQLError(message);
|
|
515
|
+
}
|
|
516
|
+
},
|
|
498
517
|
},
|
|
499
518
|
Mutation: {
|
|
500
519
|
fetchIncomeDocuments: async (
|
|
@@ -8,6 +8,7 @@ export default gql`
|
|
|
8
8
|
@auth(role: ACCOUNTANT)
|
|
9
9
|
clientMonthlyChargeDraft(clientId: UUID!, issueMonth: TimelessDate!): NewDocumentInfo!
|
|
10
10
|
@auth(role: ACCOUNTANT)
|
|
11
|
+
greenInvoiceClient(clientId: UUID!): GreenInvoiceClient! @auth(role: ACCOUNTANT)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
extend type Mutation {
|