@vrplatform/kysely 1.3.45-stage.4736 → 1.3.45-stage.4741
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/build/main/control-plane/index.d.ts +14 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/query/listing/status.js +29 -6
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/billing-partner.d.ts +4 -0
- package/build/main/query/tenant/billing-partner.js +7 -0
- package/build/main/query/tenant/billing-partner.js.map +1 -0
- package/build/main/query/tenant/index.d.ts +1 -0
- package/build/main/query/tenant/index.js +1 -0
- package/build/main/query/tenant/index.js.map +1 -1
- package/build/module/control-plane/index.d.ts +14 -0
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/query/listing/status.js +29 -6
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/query/tenant/billing-partner.d.ts +4 -0
- package/build/module/query/tenant/billing-partner.js +4 -0
- package/build/module/query/tenant/billing-partner.js.map +1 -0
- package/build/module/query/tenant/index.d.ts +1 -0
- package/build/module/query/tenant/index.js +1 -0
- package/build/module/query/tenant/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -39,6 +39,17 @@ export interface ControlPlaneBookingChannel {
|
|
|
39
39
|
export interface ControlPlaneCurrency {
|
|
40
40
|
name: string;
|
|
41
41
|
}
|
|
42
|
+
export interface ControlPlaneEvent {
|
|
43
|
+
createdAt: Generated<Timestamp>;
|
|
44
|
+
id: Generated<string>;
|
|
45
|
+
name: string;
|
|
46
|
+
packageName: string;
|
|
47
|
+
props: Json;
|
|
48
|
+
tenantId: string | null;
|
|
49
|
+
timestamp: Generated<Timestamp>;
|
|
50
|
+
trackedAt: Generated<Timestamp | null>;
|
|
51
|
+
userId: string | null;
|
|
52
|
+
}
|
|
42
53
|
export interface ControlPlaneConnectionRoute {
|
|
43
54
|
connectionId: string;
|
|
44
55
|
createdAt: Generated<Timestamp>;
|
|
@@ -79,6 +90,8 @@ export interface ControlPlaneOutbox {
|
|
|
79
90
|
publishedAt: Timestamp | null;
|
|
80
91
|
}
|
|
81
92
|
export interface ControlPlaneTenant {
|
|
93
|
+
billingCustomerId: string | null;
|
|
94
|
+
billingPartnerId: string | null;
|
|
82
95
|
billingPlan: string | null;
|
|
83
96
|
createdAt: Generated<Timestamp>;
|
|
84
97
|
dataRegion: Generated<string>;
|
|
@@ -134,6 +147,7 @@ export interface ControlPlaneDB {
|
|
|
134
147
|
'public.bookingChannel': ControlPlaneBookingChannel;
|
|
135
148
|
'public.connectionRoute': ControlPlaneConnectionRoute;
|
|
136
149
|
'public.currency': ControlPlaneCurrency;
|
|
150
|
+
'public.events': ControlPlaneEvent;
|
|
137
151
|
'public.feature': ControlPlaneFeature;
|
|
138
152
|
'public.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;
|
|
139
153
|
'public.controlPlaneOutbox': ControlPlaneOutbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["control-plane/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { ColumnType, Kysely as K } from 'kysely';\n\nexport type Generated<T> =\n T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>;\n\nexport type Json = JsonValue;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Timestamp = ColumnType<Date | string, Date | string, Date | string>;\n\nexport interface ControlPlaneApp {\n authentication: Generated<Json>;\n category: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconRound: string | null;\n id: Generated<string>;\n info: Json | null;\n name: string;\n type: string;\n version: Generated<number>;\n}\n\nexport interface ControlPlaneBookingChannel {\n channelRef: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconProvider: string | null;\n id: Generated<string>;\n lastGenerateRun: Timestamp | null;\n logo: string | null;\n logoProvider: string | null;\n selectedBookingChannelIconCandidateId: string | null;\n selectedBookingChannelLogoCandidateId: string | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneCurrency {\n name: string;\n}\n\nexport interface ControlPlaneConnectionRoute {\n connectionId: string;\n createdAt: Generated<Timestamp>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeature {\n createdAt: Generated<Timestamp>;\n description: string | null;\n id: Generated<string>;\n issueUrl: string | null;\n requiredApprovals: Generated<Json | null>;\n status: Generated<string | null>;\n tenantId: string | null;\n title: string;\n updatedAt: Generated<Timestamp>;\n url: string | null;\n}\n\nexport interface ControlPlaneFeatureEnabledTeam {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneOutbox {\n aggregateId: string;\n aggregateType: string;\n attempts: Generated<number>;\n createdAt: Generated<Timestamp>;\n dataRegion: string | null;\n eventType: string;\n eventVersion: number;\n id: Generated<string>;\n lastError: string | null;\n payload: Generated<Json>;\n publishedAt: Timestamp | null;\n}\n\nexport interface ControlPlaneTenant {\n billingPlan: string | null;\n createdAt: Generated<Timestamp>;\n dataRegion: Generated<string>;\n id: Generated<string>;\n name: string;\n partnerId: string | null;\n slug: string;\n status: Generated<string | null>;\n storageRealm: Generated<string>;\n type: Generated<string | null>;\n uniqueRef: string | null;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneTenantUser {\n createdAt: Generated<Timestamp | null>;\n id: Generated<string>;\n lastInvitedAt: Timestamp | null;\n role: Generated<string | null>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp | null>;\n userId: string;\n}\n\nexport interface ControlPlaneToken {\n createdAt: Generated<Timestamp>;\n expiresAt: Timestamp | null;\n id: Generated<string>;\n nanoId: Generated<string>;\n payload: Generated<Json>;\n tenantId: string | null;\n type: string | null;\n userId: string | null;\n}\n\nexport interface ControlPlaneUser {\n clerkId: string | null;\n createdAt: Generated<Timestamp | null>;\n email: string | null;\n firstName: string | null;\n id: Generated<string>;\n isAdmin: Generated<boolean>;\n lastName: string | null;\n name: string | null;\n partnerId: string | null;\n phone: string | null;\n secondaryEmails: Generated<Json>;\n status: Generated<string | null>;\n sub: string | null;\n type: Generated<string | null>;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneDB {\n 'public.app': ControlPlaneApp;\n 'public.bookingChannel': ControlPlaneBookingChannel;\n 'public.connectionRoute': ControlPlaneConnectionRoute;\n 'public.currency': ControlPlaneCurrency;\n 'public.feature': ControlPlaneFeature;\n 'public.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;\n 'public.controlPlaneOutbox': ControlPlaneOutbox;\n 'public.tenant': ControlPlaneTenant;\n 'public.tenantUser': ControlPlaneTenantUser;\n 'public.token': ControlPlaneToken;\n 'public.user': ControlPlaneUser;\n}\n\nexport type ControlPlaneKysely = K<ControlPlaneDB>;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["control-plane/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { ColumnType, Kysely as K } from 'kysely';\n\nexport type Generated<T> =\n T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>;\n\nexport type Json = JsonValue;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Timestamp = ColumnType<Date | string, Date | string, Date | string>;\n\nexport interface ControlPlaneApp {\n authentication: Generated<Json>;\n category: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconRound: string | null;\n id: Generated<string>;\n info: Json | null;\n name: string;\n type: string;\n version: Generated<number>;\n}\n\nexport interface ControlPlaneBookingChannel {\n channelRef: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconProvider: string | null;\n id: Generated<string>;\n lastGenerateRun: Timestamp | null;\n logo: string | null;\n logoProvider: string | null;\n selectedBookingChannelIconCandidateId: string | null;\n selectedBookingChannelLogoCandidateId: string | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneCurrency {\n name: string;\n}\n\nexport interface ControlPlaneEvent {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n name: string;\n packageName: string;\n props: Json;\n tenantId: string | null;\n timestamp: Generated<Timestamp>;\n trackedAt: Generated<Timestamp | null>;\n userId: string | null;\n}\n\nexport interface ControlPlaneConnectionRoute {\n connectionId: string;\n createdAt: Generated<Timestamp>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeature {\n createdAt: Generated<Timestamp>;\n description: string | null;\n id: Generated<string>;\n issueUrl: string | null;\n requiredApprovals: Generated<Json | null>;\n status: Generated<string | null>;\n tenantId: string | null;\n title: string;\n updatedAt: Generated<Timestamp>;\n url: string | null;\n}\n\nexport interface ControlPlaneFeatureEnabledTeam {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneOutbox {\n aggregateId: string;\n aggregateType: string;\n attempts: Generated<number>;\n createdAt: Generated<Timestamp>;\n dataRegion: string | null;\n eventType: string;\n eventVersion: number;\n id: Generated<string>;\n lastError: string | null;\n payload: Generated<Json>;\n publishedAt: Timestamp | null;\n}\n\nexport interface ControlPlaneTenant {\n billingCustomerId: string | null;\n billingPartnerId: string | null;\n billingPlan: string | null;\n createdAt: Generated<Timestamp>;\n dataRegion: Generated<string>;\n id: Generated<string>;\n name: string;\n partnerId: string | null;\n slug: string;\n status: Generated<string | null>;\n storageRealm: Generated<string>;\n type: Generated<string | null>;\n uniqueRef: string | null;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneTenantUser {\n createdAt: Generated<Timestamp | null>;\n id: Generated<string>;\n lastInvitedAt: Timestamp | null;\n role: Generated<string | null>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp | null>;\n userId: string;\n}\n\nexport interface ControlPlaneToken {\n createdAt: Generated<Timestamp>;\n expiresAt: Timestamp | null;\n id: Generated<string>;\n nanoId: Generated<string>;\n payload: Generated<Json>;\n tenantId: string | null;\n type: string | null;\n userId: string | null;\n}\n\nexport interface ControlPlaneUser {\n clerkId: string | null;\n createdAt: Generated<Timestamp | null>;\n email: string | null;\n firstName: string | null;\n id: Generated<string>;\n isAdmin: Generated<boolean>;\n lastName: string | null;\n name: string | null;\n partnerId: string | null;\n phone: string | null;\n secondaryEmails: Generated<Json>;\n status: Generated<string | null>;\n sub: string | null;\n type: Generated<string | null>;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneDB {\n 'public.app': ControlPlaneApp;\n 'public.bookingChannel': ControlPlaneBookingChannel;\n 'public.connectionRoute': ControlPlaneConnectionRoute;\n 'public.currency': ControlPlaneCurrency;\n 'public.events': ControlPlaneEvent;\n 'public.feature': ControlPlaneFeature;\n 'public.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;\n 'public.controlPlaneOutbox': ControlPlaneOutbox;\n 'public.tenant': ControlPlaneTenant;\n 'public.tenantUser': ControlPlaneTenantUser;\n 'public.token': ControlPlaneToken;\n 'public.user': ControlPlaneUser;\n}\n\nexport type ControlPlaneKysely = K<ControlPlaneDB>;\n"]}
|
|
@@ -7,7 +7,7 @@ exports.selectListingIsActive = selectListingIsActive;
|
|
|
7
7
|
exports.selectListingStatus = selectListingStatus;
|
|
8
8
|
const utils_1 = require("@vrplatform/utils");
|
|
9
9
|
const isomorphic_1 = require("../../isomorphic");
|
|
10
|
-
function
|
|
10
|
+
function hasActiveListing(eb, today) {
|
|
11
11
|
return eb.exists(eb
|
|
12
12
|
.selectFrom('public.tenant as tenant')
|
|
13
13
|
.leftJoin('public.tenant as billingPartner', 'billingPartner.id', 'tenant.calculatedBillingPartnerId')
|
|
@@ -17,6 +17,16 @@ function hasActiveTenant(eb) {
|
|
|
17
17
|
.where((eb2) => eb2.or([
|
|
18
18
|
eb2('tenant.calculatedBillingPartnerId', 'is', null),
|
|
19
19
|
eb2('billingPartner.calculatedStatus', '=', 'active'),
|
|
20
|
+
]))
|
|
21
|
+
.where((eb2) => eb2.or([
|
|
22
|
+
eb2.and([
|
|
23
|
+
eb2('tenant.isGeneralLedger', '=', false),
|
|
24
|
+
eb('l.calculatedStatus', '=', 'active'),
|
|
25
|
+
]),
|
|
26
|
+
eb2.and([
|
|
27
|
+
eb2('tenant.isGeneralLedger', '=', true),
|
|
28
|
+
eb.not(hasInactiveOwnership(eb, today)),
|
|
29
|
+
]),
|
|
20
30
|
]))
|
|
21
31
|
.limit(1));
|
|
22
32
|
}
|
|
@@ -40,14 +50,27 @@ function hasInactiveOwnership(eb, today) {
|
|
|
40
50
|
]))
|
|
41
51
|
.limit(1));
|
|
42
52
|
}
|
|
53
|
+
function hasInactiveListing(eb, today) {
|
|
54
|
+
return eb.exists(eb
|
|
55
|
+
.selectFrom('public.tenant as tenant')
|
|
56
|
+
.select('tenant.id')
|
|
57
|
+
.whereRef('tenant.id', '=', 'l.tenantId')
|
|
58
|
+
.where((eb2) => eb2.or([
|
|
59
|
+
eb2.and([
|
|
60
|
+
eb2('tenant.isGeneralLedger', '=', false),
|
|
61
|
+
eb('l.calculatedStatus', '=', 'inactive'),
|
|
62
|
+
]),
|
|
63
|
+
eb2.and([
|
|
64
|
+
eb2('tenant.isGeneralLedger', '=', true),
|
|
65
|
+
hasInactiveOwnership(eb, today),
|
|
66
|
+
]),
|
|
67
|
+
])));
|
|
68
|
+
}
|
|
43
69
|
function whereListingIsInactive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
44
|
-
return
|
|
70
|
+
return hasInactiveListing(eb, today);
|
|
45
71
|
}
|
|
46
72
|
function whereListingIsActive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
47
|
-
return eb
|
|
48
|
-
hasActiveTenant(eb),
|
|
49
|
-
eb.not(whereListingIsInactive(eb, today)),
|
|
50
|
-
]);
|
|
73
|
+
return hasActiveListing(eb, today);
|
|
51
74
|
}
|
|
52
75
|
function selectListingIsInactive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
53
76
|
return whereListingIsInactive(eb, today);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"src/","sources":["query/listing/status.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"src/","sources":["query/listing/status.ts"],"names":[],"mappings":";;AAiGA,wDAKC;AAED,oDAKC;AAED,0DAKC;AAED,sDAKC;AAED,kDAUC;AAvID,6CAAwC;AAExC,iDAAuC;AAEvC,SAAS,gBAAgB,CACvB,EAAqD,EACrD,KAAa;IAEb,OAAO,EAAE,CAAC,MAAM,CACd,EAAE;SACC,UAAU,CAAC,yBAAyB,CAAC;SACrC,QAAQ,CACP,iCAAiC,EACjC,mBAAmB,EACnB,mCAAmC,CACpC;SACA,MAAM,CAAC,WAAW,CAAC;SACnB,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE,YAAY,CAAC;SACxC,KAAK,CAAC,yBAAyB,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC/C,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CACb,GAAG,CAAC,EAAE,CAAC;QACL,GAAG,CAAC,mCAAmC,EAAE,IAAI,EAAE,IAAI,CAAC;QACpD,GAAG,CAAC,iCAAiC,EAAE,GAAG,EAAE,QAAQ,CAAC;KACtD,CAAC,CACH;SACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CACb,GAAG,CAAC,EAA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AAG,GAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,oBAAoB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,mBAAmB,CACjC,EAAqD,EACrD,QAAgB,IAAA,WAAG,GAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,EAAE;SACN,IAAI,EAAE;SACN,IAAI,CAAC,sBAAsB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;SACvC,IAAI,CAAC,UAAU,CAAC;SAChB,IAAI,CAAC,QAAQ,CAAC;SACd,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\nimport type { DB, ExpressionBuilder, PublicListing } from '../../isomorphic';\nimport { sql } from '../../isomorphic';\n\nfunction hasActiveListing(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n return eb.exists(\n eb\n .selectFrom('public.tenant as tenant')\n .leftJoin(\n 'public.tenant as billingPartner',\n 'billingPartner.id',\n 'tenant.calculatedBillingPartnerId'\n )\n .select('tenant.id')\n .whereRef('tenant.id', '=', 'l.tenantId')\n .where('tenant.calculatedStatus', '=', 'active')\n .where((eb2) =>\n eb2.or([\n eb2('tenant.calculatedBillingPartnerId', 'is', null),\n eb2('billingPartner.calculatedStatus', '=', 'active'),\n ])\n )\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', false),\n eb('l.calculatedStatus', '=', 'active'),\n ]),\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', true),\n eb.not(hasInactiveOwnership(eb, today)),\n ]),\n ])\n )\n .limit(1)\n );\n}\n\nfunction hasInactiveOwnership(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n const onDate = day(today).toDate();\n return eb.exists(\n eb\n .selectFrom('public.listingOwnershipPeriod as lop')\n .select('lop.id')\n .where(\n 'lop.listingId',\n '=',\n sql<string>`coalesce(${sql.ref('l.parentId')}, ${sql.ref('l.id')})`\n )\n .whereRef('lop.tenantId', '=', 'l.tenantId')\n .where('lop.setListingInactive', '=', true)\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('lop.startAt', '<=', onDate),\n eb2('lop.endAt', '>=', onDate),\n ]),\n eb2.and([\n eb2('lop.startAt', '<=', onDate),\n eb2('lop.endAt', 'is', null),\n ]),\n ])\n )\n .limit(1)\n );\n}\n\nfunction hasInactiveListing(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n return eb.exists(\n eb\n .selectFrom('public.tenant as tenant')\n .select('tenant.id')\n .whereRef('tenant.id', '=', 'l.tenantId')\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', false),\n eb('l.calculatedStatus', '=', 'inactive'),\n ]),\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', true),\n hasInactiveOwnership(eb, today),\n ]),\n ])\n )\n );\n}\n\nexport function whereListingIsInactive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return hasInactiveListing(eb, today);\n}\n\nexport function whereListingIsActive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return hasActiveListing(eb, today);\n}\n\nexport function selectListingIsInactive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return whereListingIsInactive(eb, today);\n}\n\nexport function selectListingIsActive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return whereListingIsActive(eb, today);\n}\n\nexport function selectListingStatus(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return eb\n .case()\n .when(whereListingIsInactive(eb, today))\n .then('inactive')\n .else('active')\n .end();\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCalculatedBillingPartnerId = getCalculatedBillingPartnerId;
|
|
4
|
+
function getCalculatedBillingPartnerId({ billingPartnerId, partnerId, }) {
|
|
5
|
+
return billingPartnerId ?? partnerId;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=billing-partner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing-partner.js","sourceRoot":"src/","sources":["query/tenant/billing-partner.ts"],"names":[],"mappings":";;AAAA,sEAQC;AARD,SAAgB,6BAA6B,CAAC,EAC5C,gBAAgB,EAChB,SAAS,GAIV;IACC,OAAO,gBAAgB,IAAI,SAAS,CAAC;AACvC,CAAC","sourcesContent":["export function getCalculatedBillingPartnerId({\n billingPartnerId,\n partnerId,\n}: {\n billingPartnerId?: string | null;\n partnerId?: string | null;\n}) {\n return billingPartnerId ?? partnerId;\n}\n"]}
|
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./billing-partner"), exports);
|
|
17
18
|
__exportStar(require("./status"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/tenant/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB","sourcesContent":["export * from './status';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/tenant/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,2CAAyB","sourcesContent":["export * from './billing-partner';\nexport * from './status';\n"]}
|
|
@@ -39,6 +39,17 @@ export interface ControlPlaneBookingChannel {
|
|
|
39
39
|
export interface ControlPlaneCurrency {
|
|
40
40
|
name: string;
|
|
41
41
|
}
|
|
42
|
+
export interface ControlPlaneEvent {
|
|
43
|
+
createdAt: Generated<Timestamp>;
|
|
44
|
+
id: Generated<string>;
|
|
45
|
+
name: string;
|
|
46
|
+
packageName: string;
|
|
47
|
+
props: Json;
|
|
48
|
+
tenantId: string | null;
|
|
49
|
+
timestamp: Generated<Timestamp>;
|
|
50
|
+
trackedAt: Generated<Timestamp | null>;
|
|
51
|
+
userId: string | null;
|
|
52
|
+
}
|
|
42
53
|
export interface ControlPlaneConnectionRoute {
|
|
43
54
|
connectionId: string;
|
|
44
55
|
createdAt: Generated<Timestamp>;
|
|
@@ -79,6 +90,8 @@ export interface ControlPlaneOutbox {
|
|
|
79
90
|
publishedAt: Timestamp | null;
|
|
80
91
|
}
|
|
81
92
|
export interface ControlPlaneTenant {
|
|
93
|
+
billingCustomerId: string | null;
|
|
94
|
+
billingPartnerId: string | null;
|
|
82
95
|
billingPlan: string | null;
|
|
83
96
|
createdAt: Generated<Timestamp>;
|
|
84
97
|
dataRegion: Generated<string>;
|
|
@@ -134,6 +147,7 @@ export interface ControlPlaneDB {
|
|
|
134
147
|
'public.bookingChannel': ControlPlaneBookingChannel;
|
|
135
148
|
'public.connectionRoute': ControlPlaneConnectionRoute;
|
|
136
149
|
'public.currency': ControlPlaneCurrency;
|
|
150
|
+
'public.events': ControlPlaneEvent;
|
|
137
151
|
'public.feature': ControlPlaneFeature;
|
|
138
152
|
'public.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;
|
|
139
153
|
'public.controlPlaneOutbox': ControlPlaneOutbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["control-plane/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { ColumnType, Kysely as K } from 'kysely';\n\nexport type Generated<T> =\n T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>;\n\nexport type Json = JsonValue;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Timestamp = ColumnType<Date | string, Date | string, Date | string>;\n\nexport interface ControlPlaneApp {\n authentication: Generated<Json>;\n category: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconRound: string | null;\n id: Generated<string>;\n info: Json | null;\n name: string;\n type: string;\n version: Generated<number>;\n}\n\nexport interface ControlPlaneBookingChannel {\n channelRef: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconProvider: string | null;\n id: Generated<string>;\n lastGenerateRun: Timestamp | null;\n logo: string | null;\n logoProvider: string | null;\n selectedBookingChannelIconCandidateId: string | null;\n selectedBookingChannelLogoCandidateId: string | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneCurrency {\n name: string;\n}\n\nexport interface ControlPlaneConnectionRoute {\n connectionId: string;\n createdAt: Generated<Timestamp>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeature {\n createdAt: Generated<Timestamp>;\n description: string | null;\n id: Generated<string>;\n issueUrl: string | null;\n requiredApprovals: Generated<Json | null>;\n status: Generated<string | null>;\n tenantId: string | null;\n title: string;\n updatedAt: Generated<Timestamp>;\n url: string | null;\n}\n\nexport interface ControlPlaneFeatureEnabledTeam {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneOutbox {\n aggregateId: string;\n aggregateType: string;\n attempts: Generated<number>;\n createdAt: Generated<Timestamp>;\n dataRegion: string | null;\n eventType: string;\n eventVersion: number;\n id: Generated<string>;\n lastError: string | null;\n payload: Generated<Json>;\n publishedAt: Timestamp | null;\n}\n\nexport interface ControlPlaneTenant {\n billingPlan: string | null;\n createdAt: Generated<Timestamp>;\n dataRegion: Generated<string>;\n id: Generated<string>;\n name: string;\n partnerId: string | null;\n slug: string;\n status: Generated<string | null>;\n storageRealm: Generated<string>;\n type: Generated<string | null>;\n uniqueRef: string | null;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneTenantUser {\n createdAt: Generated<Timestamp | null>;\n id: Generated<string>;\n lastInvitedAt: Timestamp | null;\n role: Generated<string | null>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp | null>;\n userId: string;\n}\n\nexport interface ControlPlaneToken {\n createdAt: Generated<Timestamp>;\n expiresAt: Timestamp | null;\n id: Generated<string>;\n nanoId: Generated<string>;\n payload: Generated<Json>;\n tenantId: string | null;\n type: string | null;\n userId: string | null;\n}\n\nexport interface ControlPlaneUser {\n clerkId: string | null;\n createdAt: Generated<Timestamp | null>;\n email: string | null;\n firstName: string | null;\n id: Generated<string>;\n isAdmin: Generated<boolean>;\n lastName: string | null;\n name: string | null;\n partnerId: string | null;\n phone: string | null;\n secondaryEmails: Generated<Json>;\n status: Generated<string | null>;\n sub: string | null;\n type: Generated<string | null>;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneDB {\n 'public.app': ControlPlaneApp;\n 'public.bookingChannel': ControlPlaneBookingChannel;\n 'public.connectionRoute': ControlPlaneConnectionRoute;\n 'public.currency': ControlPlaneCurrency;\n 'public.feature': ControlPlaneFeature;\n 'public.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;\n 'public.controlPlaneOutbox': ControlPlaneOutbox;\n 'public.tenant': ControlPlaneTenant;\n 'public.tenantUser': ControlPlaneTenantUser;\n 'public.token': ControlPlaneToken;\n 'public.user': ControlPlaneUser;\n}\n\nexport type ControlPlaneKysely = K<ControlPlaneDB>;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["control-plane/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { ColumnType, Kysely as K } from 'kysely';\n\nexport type Generated<T> =\n T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>;\n\nexport type Json = JsonValue;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Timestamp = ColumnType<Date | string, Date | string, Date | string>;\n\nexport interface ControlPlaneApp {\n authentication: Generated<Json>;\n category: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconRound: string | null;\n id: Generated<string>;\n info: Json | null;\n name: string;\n type: string;\n version: Generated<number>;\n}\n\nexport interface ControlPlaneBookingChannel {\n channelRef: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconProvider: string | null;\n id: Generated<string>;\n lastGenerateRun: Timestamp | null;\n logo: string | null;\n logoProvider: string | null;\n selectedBookingChannelIconCandidateId: string | null;\n selectedBookingChannelLogoCandidateId: string | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneCurrency {\n name: string;\n}\n\nexport interface ControlPlaneEvent {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n name: string;\n packageName: string;\n props: Json;\n tenantId: string | null;\n timestamp: Generated<Timestamp>;\n trackedAt: Generated<Timestamp | null>;\n userId: string | null;\n}\n\nexport interface ControlPlaneConnectionRoute {\n connectionId: string;\n createdAt: Generated<Timestamp>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeature {\n createdAt: Generated<Timestamp>;\n description: string | null;\n id: Generated<string>;\n issueUrl: string | null;\n requiredApprovals: Generated<Json | null>;\n status: Generated<string | null>;\n tenantId: string | null;\n title: string;\n updatedAt: Generated<Timestamp>;\n url: string | null;\n}\n\nexport interface ControlPlaneFeatureEnabledTeam {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneOutbox {\n aggregateId: string;\n aggregateType: string;\n attempts: Generated<number>;\n createdAt: Generated<Timestamp>;\n dataRegion: string | null;\n eventType: string;\n eventVersion: number;\n id: Generated<string>;\n lastError: string | null;\n payload: Generated<Json>;\n publishedAt: Timestamp | null;\n}\n\nexport interface ControlPlaneTenant {\n billingCustomerId: string | null;\n billingPartnerId: string | null;\n billingPlan: string | null;\n createdAt: Generated<Timestamp>;\n dataRegion: Generated<string>;\n id: Generated<string>;\n name: string;\n partnerId: string | null;\n slug: string;\n status: Generated<string | null>;\n storageRealm: Generated<string>;\n type: Generated<string | null>;\n uniqueRef: string | null;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneTenantUser {\n createdAt: Generated<Timestamp | null>;\n id: Generated<string>;\n lastInvitedAt: Timestamp | null;\n role: Generated<string | null>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp | null>;\n userId: string;\n}\n\nexport interface ControlPlaneToken {\n createdAt: Generated<Timestamp>;\n expiresAt: Timestamp | null;\n id: Generated<string>;\n nanoId: Generated<string>;\n payload: Generated<Json>;\n tenantId: string | null;\n type: string | null;\n userId: string | null;\n}\n\nexport interface ControlPlaneUser {\n clerkId: string | null;\n createdAt: Generated<Timestamp | null>;\n email: string | null;\n firstName: string | null;\n id: Generated<string>;\n isAdmin: Generated<boolean>;\n lastName: string | null;\n name: string | null;\n partnerId: string | null;\n phone: string | null;\n secondaryEmails: Generated<Json>;\n status: Generated<string | null>;\n sub: string | null;\n type: Generated<string | null>;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneDB {\n 'public.app': ControlPlaneApp;\n 'public.bookingChannel': ControlPlaneBookingChannel;\n 'public.connectionRoute': ControlPlaneConnectionRoute;\n 'public.currency': ControlPlaneCurrency;\n 'public.events': ControlPlaneEvent;\n 'public.feature': ControlPlaneFeature;\n 'public.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;\n 'public.controlPlaneOutbox': ControlPlaneOutbox;\n 'public.tenant': ControlPlaneTenant;\n 'public.tenantUser': ControlPlaneTenantUser;\n 'public.token': ControlPlaneToken;\n 'public.user': ControlPlaneUser;\n}\n\nexport type ControlPlaneKysely = K<ControlPlaneDB>;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { day } from '@vrplatform/utils';
|
|
2
2
|
import { sql } from '../../isomorphic';
|
|
3
|
-
function
|
|
3
|
+
function hasActiveListing(eb, today) {
|
|
4
4
|
return eb.exists(eb
|
|
5
5
|
.selectFrom('public.tenant as tenant')
|
|
6
6
|
.leftJoin('public.tenant as billingPartner', 'billingPartner.id', 'tenant.calculatedBillingPartnerId')
|
|
@@ -10,6 +10,16 @@ function hasActiveTenant(eb) {
|
|
|
10
10
|
.where((eb2) => eb2.or([
|
|
11
11
|
eb2('tenant.calculatedBillingPartnerId', 'is', null),
|
|
12
12
|
eb2('billingPartner.calculatedStatus', '=', 'active'),
|
|
13
|
+
]))
|
|
14
|
+
.where((eb2) => eb2.or([
|
|
15
|
+
eb2.and([
|
|
16
|
+
eb2('tenant.isGeneralLedger', '=', false),
|
|
17
|
+
eb('l.calculatedStatus', '=', 'active'),
|
|
18
|
+
]),
|
|
19
|
+
eb2.and([
|
|
20
|
+
eb2('tenant.isGeneralLedger', '=', true),
|
|
21
|
+
eb.not(hasInactiveOwnership(eb, today)),
|
|
22
|
+
]),
|
|
13
23
|
]))
|
|
14
24
|
.limit(1));
|
|
15
25
|
}
|
|
@@ -33,14 +43,27 @@ function hasInactiveOwnership(eb, today) {
|
|
|
33
43
|
]))
|
|
34
44
|
.limit(1));
|
|
35
45
|
}
|
|
46
|
+
function hasInactiveListing(eb, today) {
|
|
47
|
+
return eb.exists(eb
|
|
48
|
+
.selectFrom('public.tenant as tenant')
|
|
49
|
+
.select('tenant.id')
|
|
50
|
+
.whereRef('tenant.id', '=', 'l.tenantId')
|
|
51
|
+
.where((eb2) => eb2.or([
|
|
52
|
+
eb2.and([
|
|
53
|
+
eb2('tenant.isGeneralLedger', '=', false),
|
|
54
|
+
eb('l.calculatedStatus', '=', 'inactive'),
|
|
55
|
+
]),
|
|
56
|
+
eb2.and([
|
|
57
|
+
eb2('tenant.isGeneralLedger', '=', true),
|
|
58
|
+
hasInactiveOwnership(eb, today),
|
|
59
|
+
]),
|
|
60
|
+
])));
|
|
61
|
+
}
|
|
36
62
|
export function whereListingIsInactive(eb, today = day().yyyymmdd()) {
|
|
37
|
-
return
|
|
63
|
+
return hasInactiveListing(eb, today);
|
|
38
64
|
}
|
|
39
65
|
export function whereListingIsActive(eb, today = day().yyyymmdd()) {
|
|
40
|
-
return eb
|
|
41
|
-
hasActiveTenant(eb),
|
|
42
|
-
eb.not(whereListingIsInactive(eb, today)),
|
|
43
|
-
]);
|
|
66
|
+
return hasActiveListing(eb, today);
|
|
44
67
|
}
|
|
45
68
|
export function selectListingIsInactive(eb, today = day().yyyymmdd()) {
|
|
46
69
|
return whereListingIsInactive(eb, today);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"src/","sources":["query/listing/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,SAAS,
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"src/","sources":["query/listing/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,SAAS,gBAAgB,CACvB,EAAqD,EACrD,KAAa;IAEb,OAAO,EAAE,CAAC,MAAM,CACd,EAAE;SACC,UAAU,CAAC,yB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AG,EAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,kBAAkB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,EAAqD,EACrD,QAAgB,GAAG,EAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,gBAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,EAAqD,EACrD,QAAgB,GAAG,EAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,sBAAsB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,EAAqD,EACrD,QAAgB,GAAG,EAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,oBAAoB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,EAAqD,EACrD,QAAgB,GAAG,EAAE,CAAC,QAAQ,EAAE;IAEhC,OAAO,EAAE;SACN,IAAI,EAAE;SACN,IAAI,CAAC,sBAAsB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;SACvC,IAAI,CAAC,UAAU,CAAC;SAChB,IAAI,CAAC,QAAQ,CAAC;SACd,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\nimport type { DB, ExpressionBuilder, PublicListing } from '../../isomorphic';\nimport { sql } from '../../isomorphic';\n\nfunction hasActiveListing(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n return eb.exists(\n eb\n .selectFrom('public.tenant as tenant')\n .leftJoin(\n 'public.tenant as billingPartner',\n 'billingPartner.id',\n 'tenant.calculatedBillingPartnerId'\n )\n .select('tenant.id')\n .whereRef('tenant.id', '=', 'l.tenantId')\n .where('tenant.calculatedStatus', '=', 'active')\n .where((eb2) =>\n eb2.or([\n eb2('tenant.calculatedBillingPartnerId', 'is', null),\n eb2('billingPartner.calculatedStatus', '=', 'active'),\n ])\n )\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', false),\n eb('l.calculatedStatus', '=', 'active'),\n ]),\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', true),\n eb.not(hasInactiveOwnership(eb, today)),\n ]),\n ])\n )\n .limit(1)\n );\n}\n\nfunction hasInactiveOwnership(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n const onDate = day(today).toDate();\n return eb.exists(\n eb\n .selectFrom('public.listingOwnershipPeriod as lop')\n .select('lop.id')\n .where(\n 'lop.listingId',\n '=',\n sql<string>`coalesce(${sql.ref('l.parentId')}, ${sql.ref('l.id')})`\n )\n .whereRef('lop.tenantId', '=', 'l.tenantId')\n .where('lop.setListingInactive', '=', true)\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('lop.startAt', '<=', onDate),\n eb2('lop.endAt', '>=', onDate),\n ]),\n eb2.and([\n eb2('lop.startAt', '<=', onDate),\n eb2('lop.endAt', 'is', null),\n ]),\n ])\n )\n .limit(1)\n );\n}\n\nfunction hasInactiveListing(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n return eb.exists(\n eb\n .selectFrom('public.tenant as tenant')\n .select('tenant.id')\n .whereRef('tenant.id', '=', 'l.tenantId')\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', false),\n eb('l.calculatedStatus', '=', 'inactive'),\n ]),\n eb2.and([\n eb2('tenant.isGeneralLedger', '=', true),\n hasInactiveOwnership(eb, today),\n ]),\n ])\n )\n );\n}\n\nexport function whereListingIsInactive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return hasInactiveListing(eb, today);\n}\n\nexport function whereListingIsActive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return hasActiveListing(eb, today);\n}\n\nexport function selectListingIsInactive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return whereListingIsInactive(eb, today);\n}\n\nexport function selectListingIsActive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return whereListingIsActive(eb, today);\n}\n\nexport function selectListingStatus(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return eb\n .case()\n .when(whereListingIsInactive(eb, today))\n .then('inactive')\n .else('active')\n .end();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing-partner.js","sourceRoot":"src/","sources":["query/tenant/billing-partner.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,6BAA6B,CAAC,EAC5C,gBAAgB,EAChB,SAAS,GAIV;IACC,OAAO,gBAAgB,IAAI,SAAS,CAAC;AACvC,CAAC","sourcesContent":["export function getCalculatedBillingPartnerId({\n billingPartnerId,\n partnerId,\n}: {\n billingPartnerId?: string | null;\n partnerId?: string | null;\n}) {\n return billingPartnerId ?? partnerId;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/tenant/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC","sourcesContent":["export * from './status';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/tenant/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC","sourcesContent":["export * from './billing-partner';\nexport * from './status';\n"]}
|