@develit-services/bank 5.4.2 → 5.5.0
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/dist/base.cjs +137 -137
- package/dist/base.d.cts +4 -4
- package/dist/base.d.mts +4 -4
- package/dist/base.d.ts +4 -4
- package/dist/base.mjs +2 -2
- package/dist/database/schema.d.cts +1 -1
- package/dist/database/schema.d.mts +1 -1
- package/dist/database/schema.d.ts +1 -1
- package/dist/export/workflows.cjs +32 -32
- package/dist/export/workflows.mjs +5 -5
- package/dist/shared/bank.B04qoHtD.cjs +360 -0
- package/dist/shared/{bank.o3KC69CF.d.mts → bank.BuwSQL_7.d.mts} +1 -1
- package/dist/shared/{bank.BrBu52ls.d.ts → bank.CdkOsZE8.d.cts} +1 -1
- package/dist/shared/{bank.BrBu52ls.d.cts → bank.CdkOsZE8.d.mts} +1 -1
- package/dist/shared/{bank.BrBu52ls.d.mts → bank.CdkOsZE8.d.ts} +1 -1
- package/dist/shared/{bank.BqLdCHnj.mjs → bank.D0iIfh-X.mjs} +52 -245
- package/dist/shared/{bank.3A2oRRgQ.cjs → bank.DMrkshJa.cjs} +52 -245
- package/dist/shared/{bank.Dzk9ABBs.d.cts → bank.D__RVhfE.d.cts} +1 -1
- package/dist/shared/{bank.Cfz0frnc.d.ts → bank.IAc8kIC-.d.ts} +1 -1
- package/dist/shared/bank._VynZSqn.mjs +348 -0
- package/dist/types.cjs +37 -37
- package/dist/types.d.cts +4 -4
- package/dist/types.d.mts +4 -4
- package/dist/types.d.ts +4 -4
- package/dist/types.mjs +2 -2
- package/package.json +1 -1
- package/dist/shared/bank.C_IudwLH.cjs +0 -160
- package/dist/shared/bank.CtxJ_SOF.mjs +0 -149
package/dist/base.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
4
|
-
const
|
|
4
|
+
const paymentDirection = require('./shared/bank.DMrkshJa.cjs');
|
|
5
5
|
const drizzleOrm = require('drizzle-orm');
|
|
6
6
|
const cloudflare_workers = require('cloudflare:workers');
|
|
7
7
|
const d1 = require('drizzle-orm/d1');
|
|
8
8
|
require('jose');
|
|
9
|
+
const bank = require('./shared/bank.B04qoHtD.cjs');
|
|
9
10
|
const zod = require('zod');
|
|
10
11
|
const database_schema = require('./shared/bank.9Yw4KHyl.cjs');
|
|
11
12
|
const generalCodes = require('@develit-io/general-codes');
|
|
12
13
|
require('date-fns');
|
|
13
14
|
require('node:crypto');
|
|
14
|
-
const credentialsResolver = require('./shared/bank.C_IudwLH.cjs');
|
|
15
15
|
require('drizzle-orm/zod');
|
|
16
16
|
require('drizzle-orm/sqlite-core');
|
|
17
17
|
|
|
@@ -76,8 +76,8 @@ async function heartbeatSyncWorkflows({
|
|
|
76
76
|
const upsertAccountCommand = (db, { account }) => {
|
|
77
77
|
const id = account.id || backendSdk.uuidv4();
|
|
78
78
|
const { id: _id, ...accountWithoutId } = account;
|
|
79
|
-
const command = db.insert(
|
|
80
|
-
target:
|
|
79
|
+
const command = db.insert(paymentDirection.tables.account).values({ ...account, id }).onConflictDoUpdate({
|
|
80
|
+
target: paymentDirection.tables.account.iban,
|
|
81
81
|
set: accountWithoutId
|
|
82
82
|
// preserve existing id on re-auth
|
|
83
83
|
}).returning();
|
|
@@ -94,7 +94,7 @@ const createOneTimeTokenCommand = (db, {
|
|
|
94
94
|
}) => {
|
|
95
95
|
const id = backendSdk.uuidv4();
|
|
96
96
|
const expiresAt = new Date(Date.now() + 1e3 * 60 * 60) ;
|
|
97
|
-
const command = db.insert(
|
|
97
|
+
const command = db.insert(paymentDirection.tables.ott).values({
|
|
98
98
|
id,
|
|
99
99
|
oneTimeToken: ott,
|
|
100
100
|
tokenType,
|
|
@@ -106,7 +106,7 @@ const createOneTimeTokenCommand = (db, {
|
|
|
106
106
|
|
|
107
107
|
const updateAccountCommand = (db, { account }) => {
|
|
108
108
|
return {
|
|
109
|
-
command: db.update(
|
|
109
|
+
command: db.update(paymentDirection.tables.account).set({ ...account }).where(drizzleOrm.eq(paymentDirection.tables.account.id, account.id)).returning()
|
|
110
110
|
};
|
|
111
111
|
};
|
|
112
112
|
|
|
@@ -114,16 +114,16 @@ const expireOneTimeTokenCommand = (db, {
|
|
|
114
114
|
ott
|
|
115
115
|
}) => {
|
|
116
116
|
return {
|
|
117
|
-
command: db.update(
|
|
117
|
+
command: db.update(paymentDirection.tables.ott).set({
|
|
118
118
|
expiresAt: /* @__PURE__ */ new Date()
|
|
119
|
-
}).where(drizzleOrm.eq(
|
|
119
|
+
}).where(drizzleOrm.eq(paymentDirection.tables.ott.oneTimeToken, ott))
|
|
120
120
|
};
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
const createAccountCredentialsCommand = async (db, encryptionKey, { credentials }) => {
|
|
124
124
|
const id = credentials.id || backendSdk.uuidv4();
|
|
125
|
-
const encryptedValue = await
|
|
126
|
-
const command = db.insert(
|
|
125
|
+
const encryptedValue = await bank.encrypt(credentials.value, encryptionKey);
|
|
126
|
+
const command = db.insert(paymentDirection.tables.accountCredentials).values({
|
|
127
127
|
...credentials,
|
|
128
128
|
id,
|
|
129
129
|
value: encryptedValue
|
|
@@ -135,16 +135,16 @@ const createAccountCredentialsCommand = async (db, encryptionKey, { credentials
|
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
const deleteAccountCredentialsCommand = (db, { accountId }) => {
|
|
138
|
-
const command = db.delete(
|
|
138
|
+
const command = db.delete(paymentDirection.tables.accountCredentials).where(drizzleOrm.eq(paymentDirection.tables.accountCredentials.accountId, accountId));
|
|
139
139
|
return {
|
|
140
140
|
command
|
|
141
141
|
};
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
145
|
-
const command = db.update(
|
|
145
|
+
const command = db.update(paymentDirection.tables.payment).set({
|
|
146
146
|
deletedAt: /* @__PURE__ */ new Date()
|
|
147
|
-
}).where(drizzleOrm.eq(
|
|
147
|
+
}).where(drizzleOrm.eq(paymentDirection.tables.payment.accountId, accountId));
|
|
148
148
|
return {
|
|
149
149
|
command
|
|
150
150
|
};
|
|
@@ -152,7 +152,7 @@ const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
|
152
152
|
|
|
153
153
|
const createPaymentRequestCommand = (db, { paymentRequest }) => {
|
|
154
154
|
return {
|
|
155
|
-
command: db.insert(
|
|
155
|
+
command: db.insert(paymentDirection.tables.paymentRequest).values({
|
|
156
156
|
...paymentRequest,
|
|
157
157
|
creditorIban: paymentRequest.creditor.iban,
|
|
158
158
|
debtorIban: paymentRequest.debtor.iban
|
|
@@ -163,16 +163,16 @@ const createPaymentRequestCommand = (db, { paymentRequest }) => {
|
|
|
163
163
|
const getAccountBatchCountsQuery = async (db, { accountId }) => {
|
|
164
164
|
const result = await db.select({
|
|
165
165
|
totalCount: drizzleOrm.sql`COUNT(*)`.as("totalCount"),
|
|
166
|
-
processingCount: drizzleOrm.sql`SUM(CASE WHEN ${
|
|
166
|
+
processingCount: drizzleOrm.sql`SUM(CASE WHEN ${paymentDirection.tables.batch.status} = 'PROCESSING' THEN 1 ELSE 0 END)`.as(
|
|
167
167
|
"processingCount"
|
|
168
168
|
),
|
|
169
|
-
readyToSignCount: drizzleOrm.sql`SUM(CASE WHEN ${
|
|
169
|
+
readyToSignCount: drizzleOrm.sql`SUM(CASE WHEN ${paymentDirection.tables.batch.status} = 'READY_TO_SIGN' THEN 1 ELSE 0 END)`.as(
|
|
170
170
|
"readyToSignCount"
|
|
171
171
|
),
|
|
172
|
-
failedCount: drizzleOrm.sql`SUM(CASE WHEN ${
|
|
172
|
+
failedCount: drizzleOrm.sql`SUM(CASE WHEN ${paymentDirection.tables.batch.status} = 'FAILED' THEN 1 ELSE 0 END)`.as(
|
|
173
173
|
"failedCount"
|
|
174
174
|
)
|
|
175
|
-
}).from(
|
|
175
|
+
}).from(paymentDirection.tables.batch).where(drizzleOrm.eq(paymentDirection.tables.batch.accountId, accountId)).then(backendSdk.first);
|
|
176
176
|
return result || {
|
|
177
177
|
totalCount: 0,
|
|
178
178
|
processingCount: 0,
|
|
@@ -182,18 +182,18 @@ const getAccountBatchCountsQuery = async (db, { accountId }) => {
|
|
|
182
182
|
};
|
|
183
183
|
|
|
184
184
|
const getAccountByIbanQuery = async (db, { iban }) => {
|
|
185
|
-
return await db.select().from(
|
|
185
|
+
return await db.select().from(paymentDirection.tables.account).where(drizzleOrm.eq(paymentDirection.tables.account.iban, iban)).get();
|
|
186
186
|
};
|
|
187
187
|
|
|
188
188
|
const getAllAccountsQuery = async (db, filters) => {
|
|
189
189
|
const whereConditions = drizzleOrm.and(
|
|
190
|
-
backendSdk.buildMultiFilterConditions(
|
|
190
|
+
backendSdk.buildMultiFilterConditions(paymentDirection.tables.account.iban, filters?.filterIbans),
|
|
191
191
|
backendSdk.buildMultiFilterConditions(
|
|
192
|
-
|
|
192
|
+
paymentDirection.tables.account.currency,
|
|
193
193
|
filters?.filterCurrencies
|
|
194
194
|
),
|
|
195
195
|
backendSdk.buildMultiFilterConditions(
|
|
196
|
-
|
|
196
|
+
paymentDirection.tables.account.bankRefId,
|
|
197
197
|
filters?.filterBankRefIds
|
|
198
198
|
)
|
|
199
199
|
);
|
|
@@ -201,11 +201,11 @@ const getAllAccountsQuery = async (db, filters) => {
|
|
|
201
201
|
const limit = filters?.limit ?? 20;
|
|
202
202
|
const offset = (page - 1) * limit;
|
|
203
203
|
const [accountsWithExpiration, countResult] = await Promise.all([
|
|
204
|
-
db.select().from(
|
|
205
|
-
|
|
206
|
-
drizzleOrm.eq(
|
|
204
|
+
db.select().from(paymentDirection.tables.account).leftJoin(
|
|
205
|
+
paymentDirection.tables.accountCredentials,
|
|
206
|
+
drizzleOrm.eq(paymentDirection.tables.accountCredentials.accountId, paymentDirection.tables.account.id)
|
|
207
207
|
).where(whereConditions).limit(limit).offset(offset),
|
|
208
|
-
db.select({ count: drizzleOrm.sql`count(*)` }).from(
|
|
208
|
+
db.select({ count: drizzleOrm.sql`count(*)` }).from(paymentDirection.tables.account).where(whereConditions)
|
|
209
209
|
]);
|
|
210
210
|
return {
|
|
211
211
|
accounts: accountsWithExpiration.map(
|
|
@@ -267,42 +267,42 @@ const getPaymentsWithPaginationQuery = async (db, {
|
|
|
267
267
|
}) => {
|
|
268
268
|
const whereConditions = drizzleOrm.and(
|
|
269
269
|
buildMultiFilterConditions(
|
|
270
|
-
|
|
270
|
+
paymentDirection.tables.payment.accountId,
|
|
271
271
|
filterPaymentAccountId
|
|
272
272
|
),
|
|
273
|
-
buildMultiFilterConditions(
|
|
274
|
-
buildMultiFilterConditions(
|
|
273
|
+
buildMultiFilterConditions(paymentDirection.tables.payment.amount, filterPaymentAmount),
|
|
274
|
+
buildMultiFilterConditions(paymentDirection.tables.payment.currency, filterPaymentCurrency),
|
|
275
275
|
buildRangeFilterConditions(
|
|
276
|
-
|
|
276
|
+
paymentDirection.tables.payment.createdAt,
|
|
277
277
|
filterPaymentDateFrom,
|
|
278
278
|
filterPaymentDateTo
|
|
279
279
|
),
|
|
280
|
-
buildMultiFilterConditions(
|
|
280
|
+
buildMultiFilterConditions(paymentDirection.tables.payment.status, filterPaymentStatus),
|
|
281
281
|
buildMultiFilterConditions(
|
|
282
|
-
|
|
282
|
+
paymentDirection.tables.payment.direction,
|
|
283
283
|
filterPaymentDirection
|
|
284
284
|
),
|
|
285
|
-
buildMultiFilterConditions(
|
|
286
|
-
buildMultiFilterConditions(
|
|
285
|
+
buildMultiFilterConditions(paymentDirection.tables.payment.id, ids),
|
|
286
|
+
buildMultiFilterConditions(paymentDirection.tables.payment.paymentType, filterPaymentType),
|
|
287
287
|
buildRangeFilterConditions(
|
|
288
|
-
|
|
288
|
+
paymentDirection.tables.payment.amount,
|
|
289
289
|
filterPaymentMinAmount,
|
|
290
290
|
filterPaymentMaxAmount
|
|
291
291
|
),
|
|
292
|
-
filterPaymentVariableSymbol !== void 0 ? drizzleOrm.eq(
|
|
293
|
-
filterPaymentSpecificSymbol !== void 0 ? drizzleOrm.eq(
|
|
294
|
-
filterPaymentConstantSymbol !== void 0 ? drizzleOrm.eq(
|
|
295
|
-
filterPaymentMessage !== void 0 ? drizzleOrm.like(
|
|
296
|
-
filterPaymentCreditorIban !== void 0 ? drizzleOrm.eq(
|
|
297
|
-
filterPaymentDebtorIban !== void 0 ? drizzleOrm.eq(
|
|
298
|
-
filterPaymentBatchId !== void 0 ? drizzleOrm.eq(
|
|
299
|
-
filterPaymentBankRefId !== void 0 ? drizzleOrm.eq(
|
|
292
|
+
filterPaymentVariableSymbol !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.vs, filterPaymentVariableSymbol) : void 0,
|
|
293
|
+
filterPaymentSpecificSymbol !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.ss, filterPaymentSpecificSymbol) : void 0,
|
|
294
|
+
filterPaymentConstantSymbol !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.ks, filterPaymentConstantSymbol) : void 0,
|
|
295
|
+
filterPaymentMessage !== void 0 ? drizzleOrm.like(paymentDirection.tables.payment.message, `%${filterPaymentMessage}%`) : void 0,
|
|
296
|
+
filterPaymentCreditorIban !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.creditorIban, filterPaymentCreditorIban) : void 0,
|
|
297
|
+
filterPaymentDebtorIban !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.debtorIban, filterPaymentDebtorIban) : void 0,
|
|
298
|
+
filterPaymentBatchId !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.batchId, filterPaymentBatchId) : void 0,
|
|
299
|
+
filterPaymentBankRefId !== void 0 ? drizzleOrm.eq(paymentDirection.tables.payment.bankRefId, filterPaymentBankRefId) : void 0
|
|
300
300
|
);
|
|
301
|
-
const sortColumn = resolveColumn(
|
|
301
|
+
const sortColumn = resolveColumn(paymentDirection.tables.payment, sort.column);
|
|
302
302
|
const [{ totalCount }] = await db.select({
|
|
303
303
|
totalCount: drizzleOrm.sql`count(*)`
|
|
304
|
-
}).from(
|
|
305
|
-
const payments = await db.select().from(
|
|
304
|
+
}).from(paymentDirection.tables.payment).where(whereConditions);
|
|
305
|
+
const payments = await db.select().from(paymentDirection.tables.payment).where(whereConditions).limit(limit).offset((page - 1) * limit).orderBy(sort.direction === "asc" ? drizzleOrm.asc(sortColumn) : drizzleOrm.desc(sortColumn));
|
|
306
306
|
return {
|
|
307
307
|
payments,
|
|
308
308
|
totalCount
|
|
@@ -317,20 +317,20 @@ const getBatchesQuery = async (db, {
|
|
|
317
317
|
filterBatchStatus
|
|
318
318
|
}) => {
|
|
319
319
|
const whereConditions = drizzleOrm.and(
|
|
320
|
-
drizzleOrm.isNull(
|
|
321
|
-
buildMultiFilterConditions(
|
|
322
|
-
buildMultiFilterConditions(
|
|
320
|
+
drizzleOrm.isNull(paymentDirection.tables.batch.deletedAt),
|
|
321
|
+
buildMultiFilterConditions(paymentDirection.tables.batch.accountId, filterBatchAccountId),
|
|
322
|
+
buildMultiFilterConditions(paymentDirection.tables.batch.status, filterBatchStatus)
|
|
323
323
|
);
|
|
324
|
-
const sortColumn = resolveColumn(
|
|
324
|
+
const sortColumn = resolveColumn(paymentDirection.tables.batch, sort.column);
|
|
325
325
|
const [{ totalCount }] = await db.select({
|
|
326
326
|
totalCount: drizzleOrm.sql`count(*)`
|
|
327
|
-
}).from(
|
|
328
|
-
const batches = await db.select().from(
|
|
327
|
+
}).from(paymentDirection.tables.batch).where(whereConditions);
|
|
328
|
+
const batches = await db.select().from(paymentDirection.tables.batch).where(whereConditions).limit(limit).offset((page - 1) * limit).orderBy(sort.direction === "asc" ? drizzleOrm.asc(sortColumn) : drizzleOrm.desc(sortColumn));
|
|
329
329
|
const batchIds = batches.map((b) => b.id);
|
|
330
|
-
const paymentRequests = batchIds.length > 0 ? await db.select().from(
|
|
330
|
+
const paymentRequests = batchIds.length > 0 ? await db.select().from(paymentDirection.tables.paymentRequest).where(
|
|
331
331
|
drizzleOrm.and(
|
|
332
|
-
drizzleOrm.inArray(
|
|
333
|
-
drizzleOrm.isNull(
|
|
332
|
+
drizzleOrm.inArray(paymentDirection.tables.paymentRequest.batchId, batchIds),
|
|
333
|
+
drizzleOrm.isNull(paymentDirection.tables.paymentRequest.deletedAt)
|
|
334
334
|
)
|
|
335
335
|
) : [];
|
|
336
336
|
const paymentRequestsByBatchId = Map.groupBy(
|
|
@@ -348,7 +348,7 @@ const getBatchesQuery = async (db, {
|
|
|
348
348
|
};
|
|
349
349
|
|
|
350
350
|
const getOttQuery = async (db, { ott }) => {
|
|
351
|
-
return await db.select().from(
|
|
351
|
+
return await db.select().from(paymentDirection.tables.ott).where(drizzleOrm.eq(paymentDirection.tables.ott.oneTimeToken, ott)).get();
|
|
352
352
|
};
|
|
353
353
|
|
|
354
354
|
const CHUNK_SIZE = 90;
|
|
@@ -358,15 +358,15 @@ const getPaymentsByPaymentRequestIdsQuery = async (db, { paymentRequestIds }) =>
|
|
|
358
358
|
for (let i = 0; i < paymentRequestIds.length; i += CHUNK_SIZE) {
|
|
359
359
|
const chunkIds = paymentRequestIds.slice(i, i + CHUNK_SIZE);
|
|
360
360
|
const rows = await db.select({
|
|
361
|
-
id:
|
|
362
|
-
correlationId:
|
|
363
|
-
status:
|
|
364
|
-
amount:
|
|
365
|
-
currency:
|
|
366
|
-
creditor:
|
|
367
|
-
createdAt:
|
|
368
|
-
updatedAt:
|
|
369
|
-
}).from(
|
|
361
|
+
id: paymentDirection.tables.paymentRequest.id,
|
|
362
|
+
correlationId: paymentDirection.tables.paymentRequest.correlationId,
|
|
363
|
+
status: paymentDirection.tables.paymentRequest.status,
|
|
364
|
+
amount: paymentDirection.tables.paymentRequest.amount,
|
|
365
|
+
currency: paymentDirection.tables.paymentRequest.currency,
|
|
366
|
+
creditor: paymentDirection.tables.paymentRequest.creditor,
|
|
367
|
+
createdAt: paymentDirection.tables.paymentRequest.createdAt,
|
|
368
|
+
updatedAt: paymentDirection.tables.paymentRequest.updatedAt
|
|
369
|
+
}).from(paymentDirection.tables.paymentRequest).where(drizzleOrm.inArray(paymentDirection.tables.paymentRequest.id, chunkIds));
|
|
370
370
|
paymentRequests.push(...rows);
|
|
371
371
|
}
|
|
372
372
|
return paymentRequests.map((pr) => {
|
|
@@ -388,10 +388,10 @@ const getPaymentsByPaymentRequestIdsQuery = async (db, { paymentRequestIds }) =>
|
|
|
388
388
|
};
|
|
389
389
|
|
|
390
390
|
const getPaymentRequestByIdQuery = async (db, { paymentRequestId }) => {
|
|
391
|
-
const result = await db.select().from(
|
|
391
|
+
const result = await db.select().from(paymentDirection.tables.paymentRequest).where(
|
|
392
392
|
drizzleOrm.and(
|
|
393
|
-
drizzleOrm.eq(
|
|
394
|
-
drizzleOrm.isNull(
|
|
393
|
+
drizzleOrm.eq(paymentDirection.tables.paymentRequest.id, paymentRequestId),
|
|
394
|
+
drizzleOrm.isNull(paymentDirection.tables.paymentRequest.deletedAt)
|
|
395
395
|
)
|
|
396
396
|
).limit(1);
|
|
397
397
|
return backendSdk.first(result);
|
|
@@ -401,30 +401,30 @@ const getPaymentRequestsQuery = async (db, params) => {
|
|
|
401
401
|
const limit = params.limit;
|
|
402
402
|
const offset = (params.page - 1) * params.limit;
|
|
403
403
|
const orderDir = params.sort.direction === "asc" ? drizzleOrm.asc : drizzleOrm.desc;
|
|
404
|
-
const orderCol = params.sort.column === "amount" ?
|
|
404
|
+
const orderCol = params.sort.column === "amount" ? paymentDirection.tables.paymentRequest.amount : params.sort.column === "updatedAt" ? paymentDirection.tables.paymentRequest.updatedAt : paymentDirection.tables.paymentRequest.createdAt;
|
|
405
405
|
const where = drizzleOrm.and(
|
|
406
|
-
drizzleOrm.isNull(
|
|
407
|
-
params.filterAccountId ? Array.isArray(params.filterAccountId) ? drizzleOrm.inArray(
|
|
408
|
-
params.filterStatus ? Array.isArray(params.filterStatus) ? drizzleOrm.inArray(
|
|
409
|
-
params.filterPaymentType ? Array.isArray(params.filterPaymentType) ? drizzleOrm.inArray(
|
|
410
|
-
params.filterCurrency ? Array.isArray(params.filterCurrency) ? drizzleOrm.inArray(
|
|
411
|
-
params.filterBatchId ? drizzleOrm.eq(
|
|
412
|
-
params.filterDateFrom ? drizzleOrm.gte(
|
|
413
|
-
params.filterDateTo ? drizzleOrm.lte(
|
|
414
|
-
params.filterMinAmount !== void 0 ? drizzleOrm.gte(
|
|
415
|
-
params.filterMaxAmount !== void 0 ? drizzleOrm.lte(
|
|
416
|
-
params.filterVariableSymbol ? drizzleOrm.eq(
|
|
417
|
-
params.filterSpecificSymbol ? drizzleOrm.eq(
|
|
418
|
-
params.filterConstantSymbol ? drizzleOrm.eq(
|
|
419
|
-
params.filterMessage ? drizzleOrm.like(
|
|
420
|
-
params.filterBankRefId ? drizzleOrm.eq(
|
|
421
|
-
params.filterCreditorIban ? drizzleOrm.eq(
|
|
422
|
-
params.filterDebtorIban ? drizzleOrm.eq(
|
|
423
|
-
params.ids?.length ? drizzleOrm.inArray(
|
|
406
|
+
drizzleOrm.isNull(paymentDirection.tables.paymentRequest.deletedAt),
|
|
407
|
+
params.filterAccountId ? Array.isArray(params.filterAccountId) ? drizzleOrm.inArray(paymentDirection.tables.paymentRequest.accountId, params.filterAccountId) : drizzleOrm.eq(paymentDirection.tables.paymentRequest.accountId, params.filterAccountId) : void 0,
|
|
408
|
+
params.filterStatus ? Array.isArray(params.filterStatus) ? drizzleOrm.inArray(paymentDirection.tables.paymentRequest.status, params.filterStatus) : drizzleOrm.eq(paymentDirection.tables.paymentRequest.status, params.filterStatus) : void 0,
|
|
409
|
+
params.filterPaymentType ? Array.isArray(params.filterPaymentType) ? drizzleOrm.inArray(paymentDirection.tables.paymentRequest.paymentType, params.filterPaymentType) : drizzleOrm.eq(paymentDirection.tables.paymentRequest.paymentType, params.filterPaymentType) : void 0,
|
|
410
|
+
params.filterCurrency ? Array.isArray(params.filterCurrency) ? drizzleOrm.inArray(paymentDirection.tables.paymentRequest.currency, params.filterCurrency) : drizzleOrm.eq(paymentDirection.tables.paymentRequest.currency, params.filterCurrency) : void 0,
|
|
411
|
+
params.filterBatchId ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.batchId, params.filterBatchId) : void 0,
|
|
412
|
+
params.filterDateFrom ? drizzleOrm.gte(paymentDirection.tables.paymentRequest.createdAt, params.filterDateFrom) : void 0,
|
|
413
|
+
params.filterDateTo ? drizzleOrm.lte(paymentDirection.tables.paymentRequest.createdAt, params.filterDateTo) : void 0,
|
|
414
|
+
params.filterMinAmount !== void 0 ? drizzleOrm.gte(paymentDirection.tables.paymentRequest.amount, params.filterMinAmount) : void 0,
|
|
415
|
+
params.filterMaxAmount !== void 0 ? drizzleOrm.lte(paymentDirection.tables.paymentRequest.amount, params.filterMaxAmount) : void 0,
|
|
416
|
+
params.filterVariableSymbol ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.vs, params.filterVariableSymbol) : void 0,
|
|
417
|
+
params.filterSpecificSymbol ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.ss, params.filterSpecificSymbol) : void 0,
|
|
418
|
+
params.filterConstantSymbol ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.ks, params.filterConstantSymbol) : void 0,
|
|
419
|
+
params.filterMessage ? drizzleOrm.like(paymentDirection.tables.paymentRequest.message, `%${params.filterMessage}%`) : void 0,
|
|
420
|
+
params.filterBankRefId ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.bankRefId, params.filterBankRefId) : void 0,
|
|
421
|
+
params.filterCreditorIban ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.creditorIban, params.filterCreditorIban) : void 0,
|
|
422
|
+
params.filterDebtorIban ? drizzleOrm.eq(paymentDirection.tables.paymentRequest.debtorIban, params.filterDebtorIban) : void 0,
|
|
423
|
+
params.ids?.length ? drizzleOrm.inArray(paymentDirection.tables.paymentRequest.id, params.ids) : void 0
|
|
424
424
|
);
|
|
425
425
|
const [paymentRequests, [{ value: totalCount }]] = await Promise.all([
|
|
426
|
-
db.select().from(
|
|
427
|
-
db.select({ value: drizzleOrm.count() }).from(
|
|
426
|
+
db.select().from(paymentDirection.tables.paymentRequest).where(where).orderBy(orderDir(orderCol)).limit(limit).offset(offset),
|
|
427
|
+
db.select({ value: drizzleOrm.count() }).from(paymentDirection.tables.paymentRequest).where(where)
|
|
428
428
|
]);
|
|
429
429
|
return { paymentRequests, totalCount };
|
|
430
430
|
};
|
|
@@ -659,7 +659,7 @@ zod.z.object({
|
|
|
659
659
|
});
|
|
660
660
|
|
|
661
661
|
const updateAccountInputSchema = zod.z.object({
|
|
662
|
-
account:
|
|
662
|
+
account: paymentDirection.accountInsertSchema
|
|
663
663
|
});
|
|
664
664
|
|
|
665
665
|
const getBankAccountsInputSchema = zod.z.object({
|
|
@@ -735,7 +735,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
735
735
|
// 14 days
|
|
736
736
|
this.COMPLETED_POLLING_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
737
737
|
this.allowedProviders = config.allowedProviders;
|
|
738
|
-
this.db = d1.drizzle(this.env.BANK_D1, { schema:
|
|
738
|
+
this.db = d1.drizzle(this.env.BANK_D1, { schema: paymentDirection.tables, relations: paymentDirection.relations });
|
|
739
739
|
}
|
|
740
740
|
async _getAccounts(filters) {
|
|
741
741
|
return await getAllAccountsQuery(this.db, filters);
|
|
@@ -769,7 +769,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
769
769
|
bankRefId: acc.bankRefId,
|
|
770
770
|
config: acc.connectorConfig
|
|
771
771
|
}));
|
|
772
|
-
resolveCredentials = await
|
|
772
|
+
resolveCredentials = await bank.createCredentialsResolver(this.db, this.env);
|
|
773
773
|
}
|
|
774
774
|
return bank.initiateConnector({
|
|
775
775
|
bank: connectorKey,
|
|
@@ -943,10 +943,10 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
943
943
|
oldStatus: pr.status,
|
|
944
944
|
newStatus
|
|
945
945
|
});
|
|
946
|
-
await
|
|
946
|
+
await bank.updatePaymentRequestStatusCommand(this.db, {
|
|
947
947
|
id: pr.id,
|
|
948
948
|
status: newStatus,
|
|
949
|
-
processedAt:
|
|
949
|
+
processedAt: paymentDirection.isProcessedStatus(newStatus) ? /* @__PURE__ */ new Date() : void 0
|
|
950
950
|
}).command.execute();
|
|
951
951
|
statusChanged++;
|
|
952
952
|
eventsToEmit.push(
|
|
@@ -1024,26 +1024,26 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1024
1024
|
*/
|
|
1025
1025
|
async _deriveBatchStatus(batchId) {
|
|
1026
1026
|
const [allPRs, batch] = await Promise.all([
|
|
1027
|
-
|
|
1028
|
-
|
|
1027
|
+
bank.getPaymentRequestsByBatchIdQuery(this.db, { batchId }),
|
|
1028
|
+
bank.getBatchByIdQuery(this.db, { batchId })
|
|
1029
1029
|
]);
|
|
1030
1030
|
if (!batch || batch.status === "COMPLETED" || batch.status === "FAILED")
|
|
1031
1031
|
return;
|
|
1032
1032
|
if (allPRs.length === 0) return;
|
|
1033
1033
|
const connectorKey = allPRs[0]?.connectorKey;
|
|
1034
1034
|
const allTerminal = allPRs.every(
|
|
1035
|
-
(pr) =>
|
|
1035
|
+
(pr) => paymentDirection.isTerminalStatus(pr.status, connectorKey)
|
|
1036
1036
|
);
|
|
1037
1037
|
const allAuthorizedOrHigher = allPRs.every((pr) => pr.status !== "OPENED");
|
|
1038
1038
|
if (allTerminal) {
|
|
1039
1039
|
const hasFailed = allPRs.some(
|
|
1040
1040
|
(pr) => pr.status === "REJECTED" || pr.status === "CLOSED"
|
|
1041
1041
|
);
|
|
1042
|
-
await
|
|
1042
|
+
await bank.upsertBatchCommand(this.db, {
|
|
1043
1043
|
batch: { ...batch, status: hasFailed ? "FAILED" : "COMPLETED" }
|
|
1044
1044
|
}).command.execute();
|
|
1045
1045
|
} else if (allAuthorizedOrHigher && batch.status !== "AUTHORIZED") {
|
|
1046
|
-
await
|
|
1046
|
+
await bank.upsertBatchCommand(this.db, {
|
|
1047
1047
|
batch: { ...batch, status: "AUTHORIZED" }
|
|
1048
1048
|
}).command.execute();
|
|
1049
1049
|
}
|
|
@@ -1057,7 +1057,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1057
1057
|
console.log("[updatePaymentRequestStatuses] Starting", {
|
|
1058
1058
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1059
1059
|
});
|
|
1060
|
-
const nonTerminalPRs = await
|
|
1060
|
+
const nonTerminalPRs = await paymentDirection.getNonTerminalPaymentRequestsQuery(this.db);
|
|
1061
1061
|
if (nonTerminalPRs.length === 0) {
|
|
1062
1062
|
console.log(
|
|
1063
1063
|
"[updatePaymentRequestStatuses] No non-terminal PRs found",
|
|
@@ -1080,7 +1080,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1080
1080
|
const pollableIds = [];
|
|
1081
1081
|
for (const pr of nonTerminalPRs) {
|
|
1082
1082
|
const status = pr.status;
|
|
1083
|
-
if (
|
|
1083
|
+
if (paymentDirection.isTerminalStatus(status, pr.connectorKey)) {
|
|
1084
1084
|
continue;
|
|
1085
1085
|
}
|
|
1086
1086
|
if (status === "OPENED" || status === "AUTHORIZED") {
|
|
@@ -1096,7 +1096,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1096
1096
|
age: `${Math.floor((now - pr.createdAt.getTime()) / (24 * 60 * 60 * 1e3))} days`
|
|
1097
1097
|
}
|
|
1098
1098
|
);
|
|
1099
|
-
await
|
|
1099
|
+
await bank.updatePaymentRequestStatusCommand(this.db, {
|
|
1100
1100
|
id: pr.id,
|
|
1101
1101
|
status: "CLOSED",
|
|
1102
1102
|
statusReason: "Polling timeout: no final status received after 14 days",
|
|
@@ -1135,9 +1135,9 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1135
1135
|
}
|
|
1136
1136
|
async heartbeatSyncWorkflows() {
|
|
1137
1137
|
const accounts = await this.db.select({
|
|
1138
|
-
id:
|
|
1139
|
-
lastSyncMetadata:
|
|
1140
|
-
}).from(
|
|
1138
|
+
id: paymentDirection.tables.account.id,
|
|
1139
|
+
lastSyncMetadata: paymentDirection.tables.account.lastSyncMetadata
|
|
1140
|
+
}).from(paymentDirection.tables.account).where(drizzleOrm.eq(paymentDirection.tables.account.status, "AUTHORIZED")).all();
|
|
1141
1141
|
const resetAfterIterations = Number(
|
|
1142
1142
|
this.env.SYNC_WORKFLOW_RESET_AFTER_ITERATIONS
|
|
1143
1143
|
);
|
|
@@ -1182,7 +1182,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1182
1182
|
});
|
|
1183
1183
|
if (pr) connectorKey = pr.connectorKey;
|
|
1184
1184
|
} else if (batchId) {
|
|
1185
|
-
const batchPrs = await
|
|
1185
|
+
const batchPrs = await bank.getPaymentRequestsByBatchIdQuery(this.db, {
|
|
1186
1186
|
batchId
|
|
1187
1187
|
});
|
|
1188
1188
|
if (batchPrs.length > 0) connectorKey = batchPrs[0].connectorKey;
|
|
@@ -1211,7 +1211,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1211
1211
|
prIds.push(result.paymentRequestId);
|
|
1212
1212
|
}
|
|
1213
1213
|
if (result.type === "batch") {
|
|
1214
|
-
const batchPayments = await
|
|
1214
|
+
const batchPayments = await bank.getPaymentRequestsByBatchIdQuery(
|
|
1215
1215
|
this.db,
|
|
1216
1216
|
{ batchId: result.batchId }
|
|
1217
1217
|
);
|
|
@@ -1362,7 +1362,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1362
1362
|
accountId: acc.id
|
|
1363
1363
|
}).command
|
|
1364
1364
|
);
|
|
1365
|
-
const encryptionKey = await
|
|
1365
|
+
const encryptionKey = await bank.importAesKey(
|
|
1366
1366
|
(await this.env.SECRETS_STORE.get({
|
|
1367
1367
|
secretName: "BANK_SERVICE_ENCRYPTION_KEY"
|
|
1368
1368
|
})).data?.secretValue || ""
|
|
@@ -1473,7 +1473,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1473
1473
|
debtor,
|
|
1474
1474
|
debtorIban: debtor.iban
|
|
1475
1475
|
};
|
|
1476
|
-
const { command } =
|
|
1476
|
+
const { command } = bank.createPaymentCommand(this.db, { payment });
|
|
1477
1477
|
const createdPayment = await command.execute().then(backendSdk.first);
|
|
1478
1478
|
this.logQueuePush({ payment, isPaymentExecuted: true });
|
|
1479
1479
|
await this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
|
|
@@ -1495,7 +1495,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1495
1495
|
{ data: input, schema: sendPaymentInputSchema },
|
|
1496
1496
|
{ successMessage: "Payment initiated successfully" },
|
|
1497
1497
|
async (data) => {
|
|
1498
|
-
const incomingPayment =
|
|
1498
|
+
const incomingPayment = paymentDirection.toIncomingPayment(data);
|
|
1499
1499
|
this._validatePaymentTypeAndCurrency(
|
|
1500
1500
|
data.paymentType,
|
|
1501
1501
|
data.currency,
|
|
@@ -1503,7 +1503,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1503
1503
|
);
|
|
1504
1504
|
if (data.creditor.bankCode?.length === 4 && !data.creditor.iban && data.creditor.number) {
|
|
1505
1505
|
try {
|
|
1506
|
-
data.creditor.iban =
|
|
1506
|
+
data.creditor.iban = paymentDirection.calculateCzechIban(
|
|
1507
1507
|
data.creditor.number,
|
|
1508
1508
|
data.creditor.bankCode
|
|
1509
1509
|
);
|
|
@@ -1545,11 +1545,11 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1545
1545
|
status: 422
|
|
1546
1546
|
});
|
|
1547
1547
|
}
|
|
1548
|
-
const accountAssigned =
|
|
1549
|
-
const batchedPayment =
|
|
1548
|
+
const accountAssigned = paymentDirection.assignAccount(incomingPayment, account);
|
|
1549
|
+
const batchedPayment = paymentDirection.toBatchedPayment(accountAssigned);
|
|
1550
1550
|
const { command: insertPaymentRequest } = createPaymentRequestCommand(
|
|
1551
1551
|
this.db,
|
|
1552
|
-
{ paymentRequest:
|
|
1552
|
+
{ paymentRequest: paymentDirection.toPaymentRequestInsert(accountAssigned, null) }
|
|
1553
1553
|
);
|
|
1554
1554
|
await insertPaymentRequest.execute();
|
|
1555
1555
|
const initiate = () => {
|
|
@@ -1572,19 +1572,19 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1572
1572
|
try {
|
|
1573
1573
|
initiated = await initiate();
|
|
1574
1574
|
} catch (err) {
|
|
1575
|
-
await
|
|
1575
|
+
await bank.updatePaymentRequestStatusCommand(this.db, {
|
|
1576
1576
|
id: incomingPayment.id,
|
|
1577
1577
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1578
1578
|
}).command.execute();
|
|
1579
1579
|
throw err;
|
|
1580
1580
|
}
|
|
1581
|
-
await
|
|
1581
|
+
await bank.updatePaymentRequestStatusCommand(this.db, {
|
|
1582
1582
|
id: incomingPayment.id,
|
|
1583
1583
|
status: initiated.payment.status,
|
|
1584
1584
|
bankRefId: initiated.payment.bankRefId,
|
|
1585
1585
|
initiatedAt: initiated.payment.initiatedAt,
|
|
1586
1586
|
authorizationUrl: initiated.authorizationUrl,
|
|
1587
|
-
processedAt:
|
|
1587
|
+
processedAt: paymentDirection.isProcessedStatus(initiated.payment.status) ? /* @__PURE__ */ new Date() : void 0
|
|
1588
1588
|
}).command.execute();
|
|
1589
1589
|
const paymentRequest = await getPaymentRequestByIdQuery(this.db, {
|
|
1590
1590
|
paymentRequestId: incomingPayment.id
|
|
@@ -1690,13 +1690,13 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1690
1690
|
status: 422
|
|
1691
1691
|
});
|
|
1692
1692
|
}
|
|
1693
|
-
const incomingPayments = paymentInputs.map(
|
|
1693
|
+
const incomingPayments = paymentInputs.map(paymentDirection.toIncomingPayment);
|
|
1694
1694
|
const batchedPayments = incomingPayments.map(
|
|
1695
|
-
(p) =>
|
|
1695
|
+
(p) => paymentDirection.toBatchedPayment(paymentDirection.assignAccount(p, account))
|
|
1696
1696
|
);
|
|
1697
1697
|
const batchId = backendSdk.uuidv4();
|
|
1698
1698
|
const batchMode = connector.supportsBatch(paymentType) ? "NATIVE" : "SINGLE";
|
|
1699
|
-
const batchCmd =
|
|
1699
|
+
const batchCmd = bank.upsertBatchCommand(this.db, {
|
|
1700
1700
|
batch: {
|
|
1701
1701
|
id: batchId,
|
|
1702
1702
|
authorizationUrls: [],
|
|
@@ -1709,8 +1709,8 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1709
1709
|
}).command;
|
|
1710
1710
|
const prCmds = incomingPayments.map(
|
|
1711
1711
|
(p) => createPaymentRequestCommand(this.db, {
|
|
1712
|
-
paymentRequest:
|
|
1713
|
-
|
|
1712
|
+
paymentRequest: paymentDirection.toPaymentRequestInsert(
|
|
1713
|
+
paymentDirection.assignAccount(p, account),
|
|
1714
1714
|
batchId
|
|
1715
1715
|
)
|
|
1716
1716
|
}).command
|
|
@@ -1733,12 +1733,12 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1733
1733
|
result = await initiateBatch();
|
|
1734
1734
|
} catch (err) {
|
|
1735
1735
|
const deletePrCmds = incomingPayments.map(
|
|
1736
|
-
(p) =>
|
|
1736
|
+
(p) => bank.updatePaymentRequestStatusCommand(this.db, {
|
|
1737
1737
|
id: p.id,
|
|
1738
1738
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1739
1739
|
}).command
|
|
1740
1740
|
);
|
|
1741
|
-
const deleteBatchCmd =
|
|
1741
|
+
const deleteBatchCmd = bank.upsertBatchCommand(this.db, {
|
|
1742
1742
|
batch: {
|
|
1743
1743
|
id: batchId,
|
|
1744
1744
|
accountId: account.id,
|
|
@@ -1753,16 +1753,16 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1753
1753
|
const { authorizationUrls, payments: preparedPayments } = result;
|
|
1754
1754
|
const isPerPaymentFallback = authorizationUrls.length === preparedPayments.length;
|
|
1755
1755
|
const updatePrCmds = preparedPayments.map(
|
|
1756
|
-
(pp, i) =>
|
|
1756
|
+
(pp, i) => bank.updatePaymentRequestStatusCommand(this.db, {
|
|
1757
1757
|
id: pp.id,
|
|
1758
1758
|
status: pp.status,
|
|
1759
1759
|
bankRefId: pp.bankRefId,
|
|
1760
1760
|
initiatedAt: pp.initiatedAt,
|
|
1761
1761
|
authorizationUrl: isPerPaymentFallback ? authorizationUrls[i] : authorizationUrls[0],
|
|
1762
|
-
processedAt:
|
|
1762
|
+
processedAt: paymentDirection.isProcessedStatus(pp.status) ? /* @__PURE__ */ new Date() : void 0
|
|
1763
1763
|
}).command
|
|
1764
1764
|
);
|
|
1765
|
-
const updateBatchCmd =
|
|
1765
|
+
const updateBatchCmd = bank.upsertBatchCommand(this.db, {
|
|
1766
1766
|
batch: {
|
|
1767
1767
|
id: batchId,
|
|
1768
1768
|
accountId: account.id,
|
|
@@ -1775,8 +1775,8 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1775
1775
|
}).command;
|
|
1776
1776
|
await this.db.batch([updateBatchCmd, ...updatePrCmds]);
|
|
1777
1777
|
const [updatedBatch, paymentRequests] = await Promise.all([
|
|
1778
|
-
|
|
1779
|
-
|
|
1778
|
+
bank.getBatchByIdQuery(this.db, { batchId }),
|
|
1779
|
+
bank.getPaymentRequestsByBatchIdQuery(this.db, { batchId })
|
|
1780
1780
|
]);
|
|
1781
1781
|
if (!updatedBatch) {
|
|
1782
1782
|
throw backendSdk.createInternalError(null, {
|
|
@@ -1848,11 +1848,11 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1848
1848
|
if (includePendingPaymentRequestCount) {
|
|
1849
1849
|
const [row] = await this.db.select({
|
|
1850
1850
|
count: drizzleOrm.sql`count(*)`
|
|
1851
|
-
}).from(
|
|
1851
|
+
}).from(paymentDirection.tables.paymentRequest).where(
|
|
1852
1852
|
drizzleOrm.and(
|
|
1853
|
-
drizzleOrm.eq(
|
|
1854
|
-
drizzleOrm.eq(
|
|
1855
|
-
drizzleOrm.isNull(
|
|
1853
|
+
drizzleOrm.eq(paymentDirection.tables.paymentRequest.accountId, a.id),
|
|
1854
|
+
drizzleOrm.eq(paymentDirection.tables.paymentRequest.status, "OPENED"),
|
|
1855
|
+
drizzleOrm.isNull(paymentDirection.tables.paymentRequest.deletedAt)
|
|
1856
1856
|
)
|
|
1857
1857
|
);
|
|
1858
1858
|
result.pendingPaymentRequestCount = row?.count ?? 0;
|
|
@@ -1872,7 +1872,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1872
1872
|
{ data: input, schema: getAccountBalanceInputSchema },
|
|
1873
1873
|
{ successMessage: "Account balance retrieved successfully" },
|
|
1874
1874
|
async (data) => {
|
|
1875
|
-
const account = await
|
|
1875
|
+
const account = await bank.getAccountByIdQuery(this.db, {
|
|
1876
1876
|
accountId: data.accountId
|
|
1877
1877
|
});
|
|
1878
1878
|
if (!account) {
|
|
@@ -1924,7 +1924,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1924
1924
|
{ data: input, schema: disconnectAccountInputSchema },
|
|
1925
1925
|
{ successMessage: "Account disconnected successfully" },
|
|
1926
1926
|
async ({ accountId }) => {
|
|
1927
|
-
const account = await
|
|
1927
|
+
const account = await bank.getAccountByIdQuery(this.db, { accountId });
|
|
1928
1928
|
if (!account) {
|
|
1929
1929
|
throw backendSdk.createInternalError(null, {
|
|
1930
1930
|
message: "Account not found",
|
|
@@ -2043,14 +2043,14 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
2043
2043
|
const privateKeyPem = (await this.env.SECRETS_STORE.get({
|
|
2044
2044
|
secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
|
|
2045
2045
|
})).data?.secretValue || "";
|
|
2046
|
-
const client = new
|
|
2046
|
+
const client = new paymentDirection.FinbricksClient(
|
|
2047
2047
|
this.env.FINBRICKS_BASE_URI,
|
|
2048
2048
|
this.env.FINBRICKS_MERCHANT_ID,
|
|
2049
2049
|
privateKeyPem,
|
|
2050
2050
|
this.env.REDIRECT_URI
|
|
2051
2051
|
);
|
|
2052
2052
|
return client.request({
|
|
2053
|
-
endpoint:
|
|
2053
|
+
endpoint: paymentDirection.FINBRICKS_ENDPOINTS.BANK_INFO,
|
|
2054
2054
|
method: "GET",
|
|
2055
2055
|
query: {
|
|
2056
2056
|
merchantId: this.env.FINBRICKS_MERCHANT_ID
|