@fonderie/customers 5.0.0 → 6.0.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/README.md +2 -2
- package/brain/signatures.md +1 -6
- package/dist/index.cjs +29 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -7
- package/dist/types.d.ts +1 -7
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomerSex, IAddress, ICustomerAddress, ICustomer, ICustomerDetail, ICustomerEmail, ICustomerNote, ICustomerPhone, ICustomerTag, ICustomerDetailD2 } from './types.cjs';
|
|
2
|
-
export {
|
|
2
|
+
export { CustomerType } from './types.cjs';
|
|
3
3
|
import { IStoreAdapter } from '@fonderie/store';
|
|
4
4
|
import { IFonderieModule, IFonderieApp } from '@fonderie/core';
|
|
5
5
|
import { EventBus } from '@fonderie/events';
|
|
@@ -160,6 +160,7 @@ declare class CustomerModel {
|
|
|
160
160
|
/** Resolve a referral code to the referring customer's id, within a workspace. */
|
|
161
161
|
resolveReferralCode(workspaceId: string, code: string): Promise<string | null>;
|
|
162
162
|
list(opts: ListCustomersOpts): Promise<ICustomer[]>;
|
|
163
|
+
count(opts: Omit<ListCustomersOpts, 'limit' | 'offset'>): Promise<number>;
|
|
163
164
|
findById(id: string, workspaceId: string): Promise<ICustomer | null>;
|
|
164
165
|
findDetail(id: string, workspaceId: string, depth: 2): Promise<ICustomerDetailD2 | null>;
|
|
165
166
|
findDetail(id: string, workspaceId: string, depth?: 1): Promise<ICustomerDetail | null>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomerSex, IAddress, ICustomerAddress, ICustomer, ICustomerDetail, ICustomerEmail, ICustomerNote, ICustomerPhone, ICustomerTag, ICustomerDetailD2 } from './types.js';
|
|
2
|
-
export {
|
|
2
|
+
export { CustomerType } from './types.js';
|
|
3
3
|
import { IStoreAdapter } from '@fonderie/store';
|
|
4
4
|
import { IFonderieModule, IFonderieApp } from '@fonderie/core';
|
|
5
5
|
import { EventBus } from '@fonderie/events';
|
|
@@ -160,6 +160,7 @@ declare class CustomerModel {
|
|
|
160
160
|
/** Resolve a referral code to the referring customer's id, within a workspace. */
|
|
161
161
|
resolveReferralCode(workspaceId: string, code: string): Promise<string | null>;
|
|
162
162
|
list(opts: ListCustomersOpts): Promise<ICustomer[]>;
|
|
163
|
+
count(opts: Omit<ListCustomersOpts, 'limit' | 'offset'>): Promise<number>;
|
|
163
164
|
findById(id: string, workspaceId: string): Promise<ICustomer | null>;
|
|
164
165
|
findDetail(id: string, workspaceId: string, depth: 2): Promise<ICustomerDetailD2 | null>;
|
|
165
166
|
findDetail(id: string, workspaceId: string, depth?: 1): Promise<ICustomerDetail | null>;
|
package/dist/index.js
CHANGED
|
@@ -257,6 +257,28 @@ var CustomerModel = class {
|
|
|
257
257
|
params
|
|
258
258
|
);
|
|
259
259
|
}
|
|
260
|
+
async count(opts) {
|
|
261
|
+
const conditions = ["workspace_id = $1"];
|
|
262
|
+
const params = [opts.workspaceId];
|
|
263
|
+
if (opts.blacklisted !== void 0) {
|
|
264
|
+
params.push(opts.blacklisted);
|
|
265
|
+
conditions.push(`is_blacklisted = $${params.length}`);
|
|
266
|
+
}
|
|
267
|
+
if (opts.search) {
|
|
268
|
+
params.push(`%${opts.search}%`);
|
|
269
|
+
const idx = params.length;
|
|
270
|
+
conditions.push(
|
|
271
|
+
`(first_name ILIKE $${idx} OR last_name ILIKE $${idx} OR company_name ILIKE $${idx} OR reference_code ILIKE $${idx})`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
const [row] = await this.store.query(
|
|
275
|
+
`SELECT COUNT(*) AS count
|
|
276
|
+
FROM fonderie_customers
|
|
277
|
+
WHERE ${conditions.join(" AND ")}`,
|
|
278
|
+
params
|
|
279
|
+
);
|
|
280
|
+
return Number(row?.count ?? 0);
|
|
281
|
+
}
|
|
260
282
|
async findById(id, workspaceId) {
|
|
261
283
|
const [row] = await this.store.query(
|
|
262
284
|
`SELECT ${SELECT_CUSTOMER}
|
|
@@ -1309,9 +1331,14 @@ function customerController(store, config = {}, bus) {
|
|
|
1309
1331
|
if (archived !== null && archived !== void 0) {
|
|
1310
1332
|
listOpts.blacklisted = archived === "true" || archived === "1";
|
|
1311
1333
|
}
|
|
1312
|
-
const
|
|
1334
|
+
const { limit: _limit, offset: _offset, ...countOpts } = listOpts;
|
|
1335
|
+
const [list, total] = await Promise.all([
|
|
1336
|
+
customers.list(listOpts),
|
|
1337
|
+
customers.count(countOpts)
|
|
1338
|
+
]);
|
|
1313
1339
|
return setApiResponse(HTTP.OK, "CUSTOMERS_FETCHED", "Customers retrieved successfully.", {
|
|
1314
|
-
customers: list.map(toCustomerDTO)
|
|
1340
|
+
customers: list.map(toCustomerDTO),
|
|
1341
|
+
total
|
|
1315
1342
|
});
|
|
1316
1343
|
},
|
|
1317
1344
|
async get(ctx) {
|