@coursebuilder/adapter-drizzle 2.0.0 → 2.1.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/{chunk-ULJCXOOM.js → chunk-25RKHMRM.js} +521 -4993
- package/dist/{chunk-WPDVDHLH.js → chunk-2AW5KYAK.js} +2 -2
- package/dist/{chunk-QDWLBCD3.js → chunk-3AF6MZQ7.js} +2 -2
- package/dist/{chunk-RDAVEULA.js → chunk-3EF5ZXLG.js} +2 -2
- package/dist/{chunk-4SMVVOU5.js → chunk-4SWTV7Z3.js} +2 -2
- package/dist/{chunk-6VDGZ4KA.js → chunk-7FBSP3VD.js} +2 -2
- package/dist/chunk-AP5HBIV4.js +112 -0
- package/dist/chunk-CFSRMUNC.js +78 -0
- package/dist/{chunk-Q5NZ5UFZ.js → chunk-DUFH5L2F.js} +2 -2
- package/dist/{chunk-DHII2GRW.js → chunk-EZEQQJNH.js} +2 -2
- package/dist/chunk-F56AI52P.js +49 -0
- package/dist/chunk-FJGNLVE4.js +101 -0
- package/dist/chunk-HAQZSRJL.js +4696 -0
- package/dist/chunk-I2U5PTWN.js +79 -0
- package/dist/chunk-IBQGXFEX.js +8729 -0
- package/dist/chunk-KIQLUFJX.js +101 -0
- package/dist/{chunk-3XHKEHGF.js → chunk-M3WM5Q7W.js} +2 -2
- package/dist/{chunk-52A4W4YI.js → chunk-MYG6PCE3.js} +2 -2
- package/dist/chunk-PJORQUQP.js +58 -0
- package/dist/{chunk-DB473RZJ.js → chunk-PNPTKVJ4.js} +4 -4
- package/dist/chunk-W6RPAAKG.js +2144 -0
- package/dist/chunk-WKJTU24D.js +88 -0
- package/dist/chunk-WWBSNLRC.js +63 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +18 -17
- package/dist/lib/mysql/cms-resource-actions.cjs +4715 -0
- package/dist/lib/mysql/cms-resource-actions.cjs.map +1 -0
- package/dist/lib/mysql/cms-resource-actions.d.cts +140 -0
- package/dist/lib/mysql/cms-resource-actions.d.ts +140 -0
- package/dist/lib/mysql/cms-resource-actions.js +8 -0
- package/dist/lib/mysql/cms-resource-actions.js.map +1 -0
- package/dist/lib/mysql/index.cjs +398 -186
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +5 -0
- package/dist/lib/mysql/index.d.ts +5 -0
- package/dist/lib/mysql/index.js +21 -17
- package/dist/lib/mysql/schemas/auth/accounts.js +5 -5
- package/dist/lib/mysql/schemas/auth/device-access-token.js +6 -6
- package/dist/lib/mysql/schemas/auth/device-verification.js +6 -6
- package/dist/lib/mysql/schemas/auth/personal-access-token.js +6 -6
- package/dist/lib/mysql/schemas/auth/profiles.js +5 -5
- package/dist/lib/mysql/schemas/auth/role-permissions.js +6 -6
- package/dist/lib/mysql/schemas/auth/roles.js +5 -5
- package/dist/lib/mysql/schemas/auth/sessions.js +6 -6
- package/dist/lib/mysql/schemas/auth/user-permissions.js +5 -5
- package/dist/lib/mysql/schemas/auth/user-prefs.js +5 -5
- package/dist/lib/mysql/schemas/auth/user-roles.js +5 -5
- package/dist/lib/mysql/schemas/auth/users.js +5 -5
- package/dist/lib/mysql/schemas/commerce/coupon.js +5 -5
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +5 -5
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.js +5 -5
- package/dist/lib/mysql/schemas/commerce/price.js +5 -5
- package/dist/lib/mysql/schemas/commerce/product.js +5 -5
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +6 -6
- package/dist/lib/mysql/schemas/commerce/purchase.js +5 -5
- package/dist/lib/mysql/schemas/commerce/subscription.js +5 -5
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +6 -6
- package/dist/lib/mysql/schemas/communication/comment.js +5 -5
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +5 -5
- package/dist/lib/mysql/schemas/communication/question-response.js +6 -6
- package/dist/lib/mysql/schemas/content/content-contributions.js +5 -5
- package/dist/lib/mysql/schemas/content/content-resource-product.js +5 -5
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +5 -5
- package/dist/lib/mysql/schemas/content/content-resource-tag.js +5 -5
- package/dist/lib/mysql/schemas/content/content-resource-version.js +5 -5
- package/dist/lib/mysql/schemas/content/content-resource.js +5 -5
- package/dist/lib/mysql/schemas/content/tag-tag.js +5 -5
- package/dist/lib/mysql/schemas/content/tag.js +5 -5
- package/dist/lib/mysql/schemas/entitlements/entitlement.js +6 -6
- package/dist/lib/mysql/schemas/org/organization-membership-roles.js +5 -5
- package/dist/lib/mysql/schemas/org/organization-memberships.js +5 -5
- package/dist/lib/mysql/schemas/org/organizations.js +5 -5
- package/dist/lib/utils.d.cts +5 -0
- package/dist/lib/utils.d.ts +5 -0
- package/package.json +2 -2
- package/src/lib/mysql/cms-resource-actions.ts +490 -0
- package/src/lib/mysql/index.ts +2 -0
package/dist/lib/mysql/index.cjs
CHANGED
|
@@ -10,11 +10,11 @@ var __export = (target, all) => {
|
|
|
10
10
|
for (var name in all)
|
|
11
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
12
|
};
|
|
13
|
-
var __copyProps = (to, from, except,
|
|
13
|
+
var __copyProps = (to, from, except, desc3) => {
|
|
14
14
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
15
|
for (let key of __getOwnPropNames(from))
|
|
16
16
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc3 = __getOwnPropDesc(from, key)) || desc3.enumerable });
|
|
18
18
|
}
|
|
19
19
|
return to;
|
|
20
20
|
};
|
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/lib/mysql/index.ts
|
|
32
32
|
var mysql_exports = {};
|
|
33
33
|
__export(mysql_exports, {
|
|
34
|
+
createCmsResourceActions: () => createCmsResourceActions,
|
|
34
35
|
createTables: () => createTables,
|
|
35
36
|
getCourseBuilderSchema: () => getCourseBuilderSchema,
|
|
36
37
|
guid: () => guid,
|
|
@@ -40,7 +41,7 @@ __export(mysql_exports, {
|
|
|
40
41
|
module.exports = __toCommonJS(mysql_exports);
|
|
41
42
|
var import_slugify = __toESM(require("@sindresorhus/slugify"), 1);
|
|
42
43
|
var import_date_fns2 = require("date-fns");
|
|
43
|
-
var
|
|
44
|
+
var import_drizzle_orm47 = require("drizzle-orm");
|
|
44
45
|
var import_mysql_core52 = require("drizzle-orm/mysql-core");
|
|
45
46
|
var import_nanoid = require("nanoid");
|
|
46
47
|
var import_uuid = require("uuid");
|
|
@@ -13282,6 +13283,216 @@ function getEntitlementRelationsSchema(mysqlTable, overrides = {}) {
|
|
|
13282
13283
|
}
|
|
13283
13284
|
__name(getEntitlementRelationsSchema, "getEntitlementRelationsSchema");
|
|
13284
13285
|
|
|
13286
|
+
// src/lib/mysql/cms-resource-actions.ts
|
|
13287
|
+
var import_drizzle_orm46 = require("drizzle-orm");
|
|
13288
|
+
var CmsImageResourceRowSchema = external_exports.object({
|
|
13289
|
+
id: external_exports.string(),
|
|
13290
|
+
url: external_exports.string(),
|
|
13291
|
+
alt: external_exports.string().optional().nullable(),
|
|
13292
|
+
// Row creation time — the media tab's unified grid sorts by it.
|
|
13293
|
+
createdAt: external_exports.coerce.date().optional().nullable()
|
|
13294
|
+
});
|
|
13295
|
+
var ListResourcesForPickerInputSchema = external_exports.object({
|
|
13296
|
+
types: external_exports.array(external_exports.string()).min(1),
|
|
13297
|
+
search: external_exports.string().trim().max(200).optional(),
|
|
13298
|
+
excludeIds: external_exports.array(external_exports.string()).default([]),
|
|
13299
|
+
limit: external_exports.number().int().min(1).max(100).default(20)
|
|
13300
|
+
});
|
|
13301
|
+
function createCmsResourceActions(options) {
|
|
13302
|
+
const { db, contentResource, contentResourceResource, contentResourceProduct, getAuthContext, getEditHref } = options;
|
|
13303
|
+
const dbQuery = db.query;
|
|
13304
|
+
async function assertCanUpdateContent() {
|
|
13305
|
+
const { session, ability } = await getAuthContext();
|
|
13306
|
+
if (!session?.user || !ability.can("update", "Content")) {
|
|
13307
|
+
throw new Error("Unauthorized");
|
|
13308
|
+
}
|
|
13309
|
+
}
|
|
13310
|
+
__name(assertCanUpdateContent, "assertCanUpdateContent");
|
|
13311
|
+
async function listResourcesForPicker(input) {
|
|
13312
|
+
await assertCanUpdateContent();
|
|
13313
|
+
const { types, search, excludeIds, limit } = ListResourcesForPickerInputSchema.parse(input);
|
|
13314
|
+
const conditions = [
|
|
13315
|
+
(0, import_drizzle_orm46.inArray)(contentResource.type, types),
|
|
13316
|
+
(0, import_drizzle_orm46.isNull)(contentResource.deletedAt)
|
|
13317
|
+
];
|
|
13318
|
+
if (excludeIds.length > 0) {
|
|
13319
|
+
conditions.push((0, import_drizzle_orm46.notInArray)(contentResource.id, excludeIds));
|
|
13320
|
+
}
|
|
13321
|
+
if (search) {
|
|
13322
|
+
const escaped = search.replace(/[\\%_]/g, "\\$&");
|
|
13323
|
+
conditions.push(import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title')) LIKE ${`%${escaped}%`}`);
|
|
13324
|
+
}
|
|
13325
|
+
const rows = await db.select({
|
|
13326
|
+
id: contentResource.id,
|
|
13327
|
+
type: contentResource.type,
|
|
13328
|
+
title: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title'))`,
|
|
13329
|
+
// Generated (indexed) column — cheaper than a JSON_EXTRACT here.
|
|
13330
|
+
slug: contentResource.slug,
|
|
13331
|
+
state: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
|
|
13332
|
+
postType: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.postType'))`,
|
|
13333
|
+
updatedAt: contentResource.updatedAt
|
|
13334
|
+
}).from(contentResource).where((0, import_drizzle_orm46.and)(...conditions)).orderBy((0, import_drizzle_orm46.desc)(contentResource.updatedAt)).limit(limit);
|
|
13335
|
+
return rows.map((row) => ({
|
|
13336
|
+
id: row.id,
|
|
13337
|
+
type: row.type,
|
|
13338
|
+
title: row.title ?? row.slug ?? row.id,
|
|
13339
|
+
slug: row.slug ?? "",
|
|
13340
|
+
state: row.state ?? "draft",
|
|
13341
|
+
detail: row.postType ?? void 0,
|
|
13342
|
+
updatedAt: row.updatedAt ?? void 0
|
|
13343
|
+
}));
|
|
13344
|
+
}
|
|
13345
|
+
__name(listResourcesForPicker, "listResourcesForPicker");
|
|
13346
|
+
async function listVideoResourcesForPicker(input) {
|
|
13347
|
+
await assertCanUpdateContent();
|
|
13348
|
+
const excludeIds = input.excludeIds ?? [];
|
|
13349
|
+
const limit = Math.min(Math.max(input.limit ?? 20, 1), 200);
|
|
13350
|
+
const offset = Math.max(0, Math.floor(input.offset ?? 0));
|
|
13351
|
+
const conditions = [
|
|
13352
|
+
(0, import_drizzle_orm46.eq)(contentResource.type, "videoResource"),
|
|
13353
|
+
(0, import_drizzle_orm46.isNull)(contentResource.deletedAt)
|
|
13354
|
+
];
|
|
13355
|
+
if (excludeIds.length > 0) {
|
|
13356
|
+
conditions.push((0, import_drizzle_orm46.notInArray)(contentResource.id, excludeIds));
|
|
13357
|
+
}
|
|
13358
|
+
if (input.search) {
|
|
13359
|
+
const escaped = input.search.replace(/[\\%_]/g, "\\$&");
|
|
13360
|
+
conditions.push(import_drizzle_orm46.sql`${contentResource.id} LIKE ${`%${escaped}%`}`);
|
|
13361
|
+
}
|
|
13362
|
+
const pageRows = await db.select({
|
|
13363
|
+
id: contentResource.id,
|
|
13364
|
+
createdAt: contentResource.createdAt
|
|
13365
|
+
}).from(contentResource).where((0, import_drizzle_orm46.and)(...conditions)).orderBy((0, import_drizzle_orm46.desc)(contentResource.createdAt)).limit(offset + limit + 50);
|
|
13366
|
+
if (pageRows.length === 0)
|
|
13367
|
+
return [];
|
|
13368
|
+
const detailRows = await db.select({
|
|
13369
|
+
id: contentResource.id,
|
|
13370
|
+
state: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
|
|
13371
|
+
muxPlaybackId: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.muxPlaybackId'))`,
|
|
13372
|
+
duration: import_drizzle_orm46.sql`JSON_EXTRACT(${contentResource.fields}, '$.duration')`,
|
|
13373
|
+
createdAt: contentResource.createdAt
|
|
13374
|
+
}).from(contentResource).where((0, import_drizzle_orm46.inArray)(contentResource.id, pageRows.map((row) => row.id)));
|
|
13375
|
+
const byId = new Map(detailRows.map((row) => [
|
|
13376
|
+
row.id,
|
|
13377
|
+
row
|
|
13378
|
+
]));
|
|
13379
|
+
const rows = pageRows.flatMap((page) => byId.get(page.id) ?? []).filter((row) => row.state !== "deleted" && row.state !== "errored").slice(offset, offset + limit);
|
|
13380
|
+
return rows.map((row) => ({
|
|
13381
|
+
id: row.id,
|
|
13382
|
+
// videoResources have no title/slug — the filename-derived id is the
|
|
13383
|
+
// human-readable handle.
|
|
13384
|
+
title: row.id,
|
|
13385
|
+
state: row.state ?? "processing",
|
|
13386
|
+
thumbnailUrl: row.muxPlaybackId ? `https://image.mux.com/${row.muxPlaybackId}/thumbnail.png?width=96&height=54&fit_mode=smartcrop` : void 0,
|
|
13387
|
+
duration: row.duration != null ? Number(row.duration) : null,
|
|
13388
|
+
createdAt: row.createdAt
|
|
13389
|
+
}));
|
|
13390
|
+
}
|
|
13391
|
+
__name(listVideoResourcesForPicker, "listVideoResourcesForPicker");
|
|
13392
|
+
async function listImageResources({ limit, offset = 0 }) {
|
|
13393
|
+
const capped = Math.min(Math.max(1, Math.floor(limit)), 200);
|
|
13394
|
+
const skip = Math.max(0, Math.floor(offset));
|
|
13395
|
+
const rows = await db.select({
|
|
13396
|
+
id: contentResource.id,
|
|
13397
|
+
url: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.url'))`,
|
|
13398
|
+
alt: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.alt'))`,
|
|
13399
|
+
createdAt: contentResource.createdAt
|
|
13400
|
+
}).from(contentResource).where((0, import_drizzle_orm46.eq)(contentResource.type, "imageResource")).orderBy((0, import_drizzle_orm46.desc)(contentResource.createdAt)).limit(capped).offset(skip);
|
|
13401
|
+
const parsed = external_exports.array(CmsImageResourceRowSchema).safeParse(rows);
|
|
13402
|
+
return parsed.success ? parsed.data : [];
|
|
13403
|
+
}
|
|
13404
|
+
__name(listImageResources, "listImageResources");
|
|
13405
|
+
async function getPostListMemberships(postId) {
|
|
13406
|
+
await assertCanUpdateContent();
|
|
13407
|
+
const links = await dbQuery.contentResourceResource.findMany({
|
|
13408
|
+
where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, postId), (0, import_drizzle_orm46.isNull)(contentResourceResource.deletedAt)),
|
|
13409
|
+
with: {
|
|
13410
|
+
resourceOf: true
|
|
13411
|
+
}
|
|
13412
|
+
});
|
|
13413
|
+
return links.filter((link) => link.resourceOf?.type === "list" && !link.resourceOf.deletedAt).map((link) => {
|
|
13414
|
+
const fields = link.resourceOf.fields ?? {};
|
|
13415
|
+
return {
|
|
13416
|
+
listId: link.resourceOf.id,
|
|
13417
|
+
title: fields.title ?? fields.slug ?? link.resourceOf.id,
|
|
13418
|
+
slug: fields.slug ?? void 0,
|
|
13419
|
+
href: fields.slug ? getEditHref("list", fields.slug) : void 0,
|
|
13420
|
+
position: link.position
|
|
13421
|
+
};
|
|
13422
|
+
});
|
|
13423
|
+
}
|
|
13424
|
+
__name(getPostListMemberships, "getPostListMemberships");
|
|
13425
|
+
async function getResourceParents(resourceId) {
|
|
13426
|
+
await assertCanUpdateContent();
|
|
13427
|
+
const [containerLinks, productLinks] = await Promise.all([
|
|
13428
|
+
dbQuery.contentResourceResource.findMany({
|
|
13429
|
+
where: (0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, resourceId),
|
|
13430
|
+
with: {
|
|
13431
|
+
resourceOf: {
|
|
13432
|
+
with: {
|
|
13433
|
+
// Sibling JOIN rows only (no nested resource objects) —
|
|
13434
|
+
// cheap, and enough to compute this resource's ordinal.
|
|
13435
|
+
resources: {
|
|
13436
|
+
orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
|
|
13437
|
+
}
|
|
13438
|
+
}
|
|
13439
|
+
}
|
|
13440
|
+
}
|
|
13441
|
+
}),
|
|
13442
|
+
dbQuery.contentResourceProduct.findMany({
|
|
13443
|
+
where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceProduct.resourceId, resourceId), (0, import_drizzle_orm46.isNull)(contentResourceProduct.deletedAt)),
|
|
13444
|
+
with: {
|
|
13445
|
+
product: true
|
|
13446
|
+
}
|
|
13447
|
+
})
|
|
13448
|
+
]);
|
|
13449
|
+
const parents = [];
|
|
13450
|
+
for (const link of containerLinks) {
|
|
13451
|
+
const parent = link.resourceOf;
|
|
13452
|
+
if (!parent || parent.deletedAt)
|
|
13453
|
+
continue;
|
|
13454
|
+
if (parent.type === "videoResource")
|
|
13455
|
+
continue;
|
|
13456
|
+
const slug = parent.fields?.slug ?? "";
|
|
13457
|
+
const siblings = parent.resources ?? [];
|
|
13458
|
+
const index48 = siblings.findIndex((sibling) => sibling.resourceId === resourceId);
|
|
13459
|
+
parents.push({
|
|
13460
|
+
id: parent.id,
|
|
13461
|
+
type: parent.type,
|
|
13462
|
+
title: parent.fields?.title ?? (slug || parent.id),
|
|
13463
|
+
href: getEditHref(parent.type, slug || parent.id),
|
|
13464
|
+
...index48 !== -1 && {
|
|
13465
|
+
detail: `#${index48 + 1} of ${siblings.length}`
|
|
13466
|
+
}
|
|
13467
|
+
});
|
|
13468
|
+
}
|
|
13469
|
+
for (const link of productLinks) {
|
|
13470
|
+
const product = link.product;
|
|
13471
|
+
if (!product)
|
|
13472
|
+
continue;
|
|
13473
|
+
const slug = product.fields?.slug ?? "";
|
|
13474
|
+
parents.push({
|
|
13475
|
+
id: product.id,
|
|
13476
|
+
type: "product",
|
|
13477
|
+
title: product.name,
|
|
13478
|
+
// Products aren't in the resource-paths registries; every app's
|
|
13479
|
+
// product editor lives at /products/[slug]/edit.
|
|
13480
|
+
href: `/products/${slug || product.id}/edit`
|
|
13481
|
+
});
|
|
13482
|
+
}
|
|
13483
|
+
return parents;
|
|
13484
|
+
}
|
|
13485
|
+
__name(getResourceParents, "getResourceParents");
|
|
13486
|
+
return {
|
|
13487
|
+
listResourcesForPicker,
|
|
13488
|
+
listVideoResourcesForPicker,
|
|
13489
|
+
listImageResources,
|
|
13490
|
+
getPostListMemberships,
|
|
13491
|
+
getResourceParents
|
|
13492
|
+
};
|
|
13493
|
+
}
|
|
13494
|
+
__name(createCmsResourceActions, "createCmsResourceActions");
|
|
13495
|
+
|
|
13285
13496
|
// src/lib/mysql/index.ts
|
|
13286
13497
|
var guid = (0, import_nanoid.customAlphabet)("1234567890abcdefghijklmnopqrstuvwxyz", 5);
|
|
13287
13498
|
var normalizeExpirationDate = /* @__PURE__ */ __name((date) => {
|
|
@@ -13457,7 +13668,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13457
13668
|
const redeemingForCurrentUser = currentUser?.id === user.id;
|
|
13458
13669
|
if (bulkCouponRedemption) {
|
|
13459
13670
|
const existingValidRedemption = await client.query.purchases.findFirst({
|
|
13460
|
-
where: (0,
|
|
13671
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.redeemedBulkCouponId, coupon2.id), (0, import_drizzle_orm47.eq)(purchaseTable.userId, user.id), (0, import_drizzle_orm47.eq)(purchaseTable.status, "Valid"))
|
|
13461
13672
|
});
|
|
13462
13673
|
if (existingValidRedemption) {
|
|
13463
13674
|
logger2.info("adapter.coupon.redeem.duplicate_team_seat", {
|
|
@@ -13539,12 +13750,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13539
13750
|
},
|
|
13540
13751
|
incrementCouponUsedCount: async (couponId) => {
|
|
13541
13752
|
await client.update(coupon).set({
|
|
13542
|
-
usedCount:
|
|
13543
|
-
}).where((0,
|
|
13753
|
+
usedCount: import_drizzle_orm47.sql`${coupon.usedCount} + 1`
|
|
13754
|
+
}).where((0, import_drizzle_orm47.eq)(coupon.id, couponId));
|
|
13544
13755
|
},
|
|
13545
13756
|
getExistingNonBulkValidPurchasesOfProduct: async ({ userId, productId }) => {
|
|
13546
13757
|
const existingPurchases = await client.query.purchases.findMany({
|
|
13547
|
-
where: (0,
|
|
13758
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), productId ? (0, import_drizzle_orm47.eq)(purchaseTable.productId, productId) : void 0, (0, import_drizzle_orm47.eq)(purchaseTable.status, "Valid"), (0, import_drizzle_orm47.isNull)(purchaseTable.bulkCouponId))
|
|
13548
13759
|
});
|
|
13549
13760
|
return external_exports.array(purchaseSchema).parse(existingPurchases);
|
|
13550
13761
|
},
|
|
@@ -13557,7 +13768,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13557
13768
|
status: 1
|
|
13558
13769
|
});
|
|
13559
13770
|
return merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
|
|
13560
|
-
where: (0,
|
|
13771
|
+
where: (0, import_drizzle_orm47.eq)(merchantCustomer.identifier, options.identifier)
|
|
13561
13772
|
}));
|
|
13562
13773
|
},
|
|
13563
13774
|
createMerchantCoupon: async (options) => {
|
|
@@ -13570,17 +13781,17 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13570
13781
|
status: 1
|
|
13571
13782
|
});
|
|
13572
13783
|
return merchantCouponSchema.parse(await client.query.merchantCoupon.findFirst({
|
|
13573
|
-
where: (0,
|
|
13784
|
+
where: (0, import_drizzle_orm47.eq)(merchantCoupon.identifier, options.identifier)
|
|
13574
13785
|
}));
|
|
13575
13786
|
},
|
|
13576
13787
|
getMerchantAccount: async (options) => {
|
|
13577
13788
|
return merchantAccountSchema.parse(await client.query.merchantAccount.findFirst({
|
|
13578
|
-
where: (0,
|
|
13789
|
+
where: (0, import_drizzle_orm47.eq)(merchantAccount.label, options.provider)
|
|
13579
13790
|
}));
|
|
13580
13791
|
},
|
|
13581
13792
|
getMerchantPriceForProductId: async (productId) => {
|
|
13582
13793
|
const merchantPriceData = await client.query.merchantPrice.findFirst({
|
|
13583
|
-
where: (0,
|
|
13794
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantPrice.merchantProductId, productId), (0, import_drizzle_orm47.eq)(merchantPrice.status, 1))
|
|
13584
13795
|
});
|
|
13585
13796
|
const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
|
|
13586
13797
|
if (!parsedMerchantPrice.success) {
|
|
@@ -13594,7 +13805,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13594
13805
|
},
|
|
13595
13806
|
getMerchantProductForProductId: async (productId) => {
|
|
13596
13807
|
const merchantProductData = await client.query.merchantProduct.findFirst({
|
|
13597
|
-
where: (0,
|
|
13808
|
+
where: (0, import_drizzle_orm47.eq)(merchantProduct.productId, productId)
|
|
13598
13809
|
});
|
|
13599
13810
|
if (!merchantProductData)
|
|
13600
13811
|
return null;
|
|
@@ -13602,7 +13813,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13602
13813
|
},
|
|
13603
13814
|
getMerchantCustomerForUserId: async (userId) => {
|
|
13604
13815
|
const merchantCustomerData = await client.query.merchantCustomer.findFirst({
|
|
13605
|
-
where: (0,
|
|
13816
|
+
where: (0, import_drizzle_orm47.eq)(merchantCustomer.userId, userId)
|
|
13606
13817
|
});
|
|
13607
13818
|
if (!merchantCustomerData)
|
|
13608
13819
|
return null;
|
|
@@ -13611,14 +13822,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13611
13822
|
getUpgradableProducts: async (options) => {
|
|
13612
13823
|
const { upgradableFromId, upgradableToId } = options;
|
|
13613
13824
|
return external_exports.array(upgradableProductSchema).parse(await client.query.upgradableProducts.findMany({
|
|
13614
|
-
where: (0,
|
|
13825
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(upgradableProducts.upgradableFromId, upgradableFromId), (0, import_drizzle_orm47.eq)(upgradableProducts.upgradableToId, upgradableToId))
|
|
13615
13826
|
}));
|
|
13616
13827
|
},
|
|
13617
13828
|
async availableUpgradesForProduct(purchases, productId) {
|
|
13618
13829
|
const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
|
|
13619
13830
|
if (previousPurchaseProductIds.length > 0) {
|
|
13620
13831
|
return client.query.upgradableProducts.findMany({
|
|
13621
|
-
where: (0,
|
|
13832
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(upgradableProducts.upgradableToId, productId), (0, import_drizzle_orm47.inArray)(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
|
|
13622
13833
|
});
|
|
13623
13834
|
}
|
|
13624
13835
|
return [];
|
|
@@ -13631,7 +13842,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13631
13842
|
throw new Error("No lessonId provided");
|
|
13632
13843
|
}
|
|
13633
13844
|
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
13634
|
-
where: (0,
|
|
13845
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
|
|
13635
13846
|
});
|
|
13636
13847
|
const now = /* @__PURE__ */ new Date();
|
|
13637
13848
|
if (lessonProgress) {
|
|
@@ -13639,7 +13850,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13639
13850
|
await client.update(resourceProgress).set({
|
|
13640
13851
|
completedAt: now,
|
|
13641
13852
|
updatedAt: now
|
|
13642
|
-
}).where((0,
|
|
13853
|
+
}).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId)));
|
|
13643
13854
|
}
|
|
13644
13855
|
} else {
|
|
13645
13856
|
await client.insert(resourceProgress).values({
|
|
@@ -13650,7 +13861,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13650
13861
|
});
|
|
13651
13862
|
}
|
|
13652
13863
|
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
13653
|
-
where: (0,
|
|
13864
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
|
|
13654
13865
|
});
|
|
13655
13866
|
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
13656
13867
|
if (!parsedLessonProgress.success) {
|
|
@@ -13667,7 +13878,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13667
13878
|
if (!options.couponId && !options.code)
|
|
13668
13879
|
return null;
|
|
13669
13880
|
const couponForIdOrCode = await client.query.coupon.findFirst({
|
|
13670
|
-
where: (0,
|
|
13881
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)(options.code ? (0, import_drizzle_orm47.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm47.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm47.gte)(coupon.expires, /* @__PURE__ */ new Date())), (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)(options.code ? (0, import_drizzle_orm47.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm47.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm47.isNull)(coupon.expires))),
|
|
13671
13882
|
with: {
|
|
13672
13883
|
merchantCoupon: true
|
|
13673
13884
|
}
|
|
@@ -13698,7 +13909,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13698
13909
|
} : {}
|
|
13699
13910
|
});
|
|
13700
13911
|
return MerchantSessionSchema.parse(await client.query.merchantSession.findFirst({
|
|
13701
|
-
where: (0,
|
|
13912
|
+
where: (0, import_drizzle_orm47.eq)(merchantSession.id, id)
|
|
13702
13913
|
}));
|
|
13703
13914
|
},
|
|
13704
13915
|
async createMerchantChargeAndPurchase(options) {
|
|
@@ -13706,10 +13917,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13706
13917
|
try {
|
|
13707
13918
|
const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId, organizationId, attributionSnapshot } = options;
|
|
13708
13919
|
const existingMerchantCharge = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
|
|
13709
|
-
where: (0,
|
|
13920
|
+
where: (0, import_drizzle_orm47.eq)(merchantCharge.identifier, stripeChargeId)
|
|
13710
13921
|
}) || null);
|
|
13711
13922
|
const existingPurchaseForCharge = existingMerchantCharge ? await client.query.purchases.findFirst({
|
|
13712
|
-
where: (0,
|
|
13923
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantChargeId, existingMerchantCharge.id),
|
|
13713
13924
|
with: {
|
|
13714
13925
|
user: true,
|
|
13715
13926
|
product: true,
|
|
@@ -13730,12 +13941,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13730
13941
|
merchantCustomerId
|
|
13731
13942
|
});
|
|
13732
13943
|
const existingPurchase = purchaseSchema.nullable().parse(await client.query.purchases.findFirst({
|
|
13733
|
-
where: (0,
|
|
13944
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, [
|
|
13734
13945
|
"Valid",
|
|
13735
13946
|
"Restricted"
|
|
13736
13947
|
]))
|
|
13737
13948
|
}) || null);
|
|
13738
|
-
const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0,
|
|
13949
|
+
const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(coupon.id, purchaseTable.bulkCouponId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId))).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(coupon.restrictedToProductId, productId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.eq)(purchaseTable.status, "Valid"))).then((res) => {
|
|
13739
13950
|
return res[0]?.Coupon ?? null;
|
|
13740
13951
|
}));
|
|
13741
13952
|
const isBulkPurchase = quantity > 1 || Boolean(existingBulkCoupon) || Boolean(options.bulk);
|
|
@@ -13767,18 +13978,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13767
13978
|
...organizationId ? {
|
|
13768
13979
|
organizationId
|
|
13769
13980
|
} : {}
|
|
13770
|
-
}).where((0,
|
|
13981
|
+
}).where((0, import_drizzle_orm47.eq)(coupon.id, bulkCouponId));
|
|
13771
13982
|
} else {
|
|
13772
13983
|
let merchantCouponToUse = stripeCouponId ? merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
|
|
13773
|
-
where: (0,
|
|
13984
|
+
where: (0, import_drizzle_orm47.eq)(merchantCoupon.identifier, stripeCouponId)
|
|
13774
13985
|
}) || null) : null;
|
|
13775
13986
|
if (!merchantCouponToUse && usedCouponId) {
|
|
13776
13987
|
const usedCoupon = couponSchema.nullable().parse(await client.query.coupon.findFirst({
|
|
13777
|
-
where: (0,
|
|
13988
|
+
where: (0, import_drizzle_orm47.eq)(coupon.id, usedCouponId)
|
|
13778
13989
|
}) || null);
|
|
13779
13990
|
if (usedCoupon?.merchantCouponId) {
|
|
13780
13991
|
merchantCouponToUse = merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
|
|
13781
|
-
where: (0,
|
|
13992
|
+
where: (0, import_drizzle_orm47.eq)(merchantCoupon.id, usedCoupon.merchantCouponId)
|
|
13782
13993
|
}) || null);
|
|
13783
13994
|
}
|
|
13784
13995
|
}
|
|
@@ -13806,10 +14017,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13806
14017
|
merchantAccountId
|
|
13807
14018
|
});
|
|
13808
14019
|
const merchantCouponUsed = stripeCouponId ? await client.query.merchantCoupon.findFirst({
|
|
13809
|
-
where: (0,
|
|
14020
|
+
where: (0, import_drizzle_orm47.eq)(merchantCoupon.identifier, stripeCouponId)
|
|
13810
14021
|
}) : null;
|
|
13811
14022
|
const pppMerchantCoupon = appliedPPPStripeCouponId ? await client.query.merchantCoupon.findFirst({
|
|
13812
|
-
where: (0,
|
|
14023
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.identifier, appliedPPPStripeCouponId), (0, import_drizzle_orm47.eq)(merchantCoupon.type, "ppp"))
|
|
13813
14024
|
}) : null;
|
|
13814
14025
|
const newPurchaseStatus = merchantCouponUsed?.type === "ppp" || pppMerchantCoupon ? "Restricted" : "Valid";
|
|
13815
14026
|
await client.insert(purchaseTable).values({
|
|
@@ -13859,7 +14070,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13859
14070
|
}
|
|
13860
14071
|
});
|
|
13861
14072
|
const parsedPurchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
13862
|
-
where: (0,
|
|
14073
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId)
|
|
13863
14074
|
}));
|
|
13864
14075
|
if (!parsedPurchase.success) {
|
|
13865
14076
|
logger2.error(parsedPurchase.error, {
|
|
@@ -13874,7 +14085,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13874
14085
|
},
|
|
13875
14086
|
async findOrCreateMerchantCustomer(options) {
|
|
13876
14087
|
const merchantCustomer2 = merchantCustomerSchema.nullable().optional().parse(await client.query.merchantCustomer.findFirst({
|
|
13877
|
-
where: (merchantCustomer3, { eq:
|
|
14088
|
+
where: (merchantCustomer3, { eq: eq3 }) => eq3(merchantCustomer3.identifier, options.identifier)
|
|
13878
14089
|
}));
|
|
13879
14090
|
if (merchantCustomer2) {
|
|
13880
14091
|
return merchantCustomer2;
|
|
@@ -13894,21 +14105,21 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13894
14105
|
payload: options.payload
|
|
13895
14106
|
});
|
|
13896
14107
|
const createdEvent = await client.query.merchantEvents.findFirst({
|
|
13897
|
-
where: (0,
|
|
14108
|
+
where: (0, import_drizzle_orm47.eq)(merchantEvents.id, eventId)
|
|
13898
14109
|
});
|
|
13899
14110
|
return merchantEventsSchema.parse(createdEvent);
|
|
13900
14111
|
},
|
|
13901
14112
|
async getMerchantEventByIdentifier(identifier) {
|
|
13902
14113
|
const event = await client.query.merchantEvents.findFirst({
|
|
13903
|
-
where: (0,
|
|
14114
|
+
where: (0, import_drizzle_orm47.eq)(merchantEvents.identifier, identifier)
|
|
13904
14115
|
});
|
|
13905
14116
|
return event ? merchantEventsSchema.parse(event) : null;
|
|
13906
14117
|
},
|
|
13907
14118
|
async getMerchantEventsByAccount(merchantAccountId) {
|
|
13908
14119
|
const events = await client.query.merchantEvents.findMany({
|
|
13909
|
-
where: (0,
|
|
14120
|
+
where: (0, import_drizzle_orm47.eq)(merchantEvents.merchantAccountId, merchantAccountId),
|
|
13910
14121
|
orderBy: [
|
|
13911
|
-
(0,
|
|
14122
|
+
(0, import_drizzle_orm47.desc)(merchantEvents.createdAt)
|
|
13912
14123
|
]
|
|
13913
14124
|
});
|
|
13914
14125
|
return events.map((event) => merchantEventsSchema.parse(event));
|
|
@@ -13941,7 +14152,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13941
14152
|
},
|
|
13942
14153
|
async getCoupon(couponIdOrCode) {
|
|
13943
14154
|
const loadedCoupon = await client.query.coupon.findFirst({
|
|
13944
|
-
where: (0,
|
|
14155
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(coupon.id, couponIdOrCode), (0, import_drizzle_orm47.eq)(coupon.code, couponIdOrCode))
|
|
13945
14156
|
}) || null;
|
|
13946
14157
|
logger2.debug("getCoupon", {
|
|
13947
14158
|
couponIdOrCode,
|
|
@@ -13953,7 +14164,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13953
14164
|
return external_exports.array(purchaseSchema.extend({
|
|
13954
14165
|
user: userSchema
|
|
13955
14166
|
})).parse(await client.query.purchases.findMany({
|
|
13956
|
-
where: (0,
|
|
14167
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.bulkCouponId, bulkCouponId),
|
|
13957
14168
|
with: {
|
|
13958
14169
|
user: true
|
|
13959
14170
|
}
|
|
@@ -13967,7 +14178,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13967
14178
|
let bulkCouponPurchases = [];
|
|
13968
14179
|
try {
|
|
13969
14180
|
couponData = await client.query.coupon.findFirst({
|
|
13970
|
-
where: (0,
|
|
14181
|
+
where: (0, import_drizzle_orm47.eq)(coupon.id, couponId),
|
|
13971
14182
|
with: {
|
|
13972
14183
|
bulkPurchases: true,
|
|
13973
14184
|
redeemedBulkCouponPurchases: true
|
|
@@ -13982,7 +14193,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
13982
14193
|
}
|
|
13983
14194
|
try {
|
|
13984
14195
|
bulkCouponPurchases = await client.query.purchases.findMany({
|
|
13985
|
-
where: (0,
|
|
14196
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.redeemedBulkCouponId, couponId),
|
|
13986
14197
|
with: {
|
|
13987
14198
|
user: true
|
|
13988
14199
|
}
|
|
@@ -14024,8 +14235,8 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14024
14235
|
},
|
|
14025
14236
|
async getDefaultCoupon(productIds) {
|
|
14026
14237
|
const activeSaleCoupon = await client.query.coupon.findFirst({
|
|
14027
|
-
where: (0,
|
|
14028
|
-
orderBy: (0,
|
|
14238
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(coupon.status, 1), (0, import_drizzle_orm47.eq)(coupon.default, true), (0, import_drizzle_orm47.gte)(coupon.expires, /* @__PURE__ */ new Date()), (0, import_drizzle_orm47.or)(productIds ? (0, import_drizzle_orm47.inArray)(coupon.restrictedToProductId, productIds) : void 0, (0, import_drizzle_orm47.isNull)(coupon.restrictedToProductId))),
|
|
14239
|
+
orderBy: (0, import_drizzle_orm47.desc)(coupon.percentageDiscount),
|
|
14029
14240
|
with: {
|
|
14030
14241
|
merchantCoupon: true,
|
|
14031
14242
|
product: true
|
|
@@ -14049,7 +14260,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14049
14260
|
},
|
|
14050
14261
|
async getLessonProgressForUser(userId) {
|
|
14051
14262
|
const userProgress = await client.query.resourceProgress.findMany({
|
|
14052
|
-
where: (0,
|
|
14263
|
+
where: (0, import_drizzle_orm47.eq)(resourceProgress.userId, userId)
|
|
14053
14264
|
});
|
|
14054
14265
|
const parsed = external_exports.array(resourceProgressSchema).safeParse(userProgress);
|
|
14055
14266
|
if (!parsed.success) {
|
|
@@ -14063,7 +14274,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14063
14274
|
},
|
|
14064
14275
|
async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
|
|
14065
14276
|
const user = await client.query.users.findFirst({
|
|
14066
|
-
where: (0,
|
|
14277
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(users.id, userIdOrEmail), (0, import_drizzle_orm47.eq)(users.email, userIdOrEmail)),
|
|
14067
14278
|
columns: {
|
|
14068
14279
|
id: true
|
|
14069
14280
|
}
|
|
@@ -14081,7 +14292,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14081
14292
|
resource_slug: external_exports.string().nullable(),
|
|
14082
14293
|
completed_at: external_exports.string().nullable().transform((val) => val ? new Date(val) : null)
|
|
14083
14294
|
});
|
|
14084
|
-
const results = await client.execute(
|
|
14295
|
+
const results = await client.execute(import_drizzle_orm47.sql`
|
|
14085
14296
|
WITH RECURSIVE workshop AS (
|
|
14086
14297
|
SELECT id, fields->>'$.slug' AS slug
|
|
14087
14298
|
FROM ${contentResource}
|
|
@@ -14188,7 +14399,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14188
14399
|
},
|
|
14189
14400
|
async getMerchantCharge(merchantChargeId) {
|
|
14190
14401
|
const mCharge = await client.query.merchantCharge.findFirst({
|
|
14191
|
-
where: (0,
|
|
14402
|
+
where: (0, import_drizzle_orm47.eq)(merchantCharge.id, merchantChargeId)
|
|
14192
14403
|
});
|
|
14193
14404
|
const parsed = merchantChargeSchema.safeParse(mCharge);
|
|
14194
14405
|
if (!parsed.success) {
|
|
@@ -14202,12 +14413,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14202
14413
|
},
|
|
14203
14414
|
async getMerchantCouponsForTypeAndPercent(params) {
|
|
14204
14415
|
return external_exports.array(merchantCouponSchema).parse(await client.query.merchantCoupon.findMany({
|
|
14205
|
-
where: (0,
|
|
14416
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm47.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
|
|
14206
14417
|
}));
|
|
14207
14418
|
},
|
|
14208
14419
|
async getMerchantCouponForTypeAndPercent(params) {
|
|
14209
14420
|
const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
|
|
14210
|
-
where: (0,
|
|
14421
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm47.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
|
|
14211
14422
|
});
|
|
14212
14423
|
const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
|
|
14213
14424
|
if (parsed.success) {
|
|
@@ -14217,7 +14428,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14217
14428
|
},
|
|
14218
14429
|
async getMerchantCouponForTypeAndAmount(params) {
|
|
14219
14430
|
const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
|
|
14220
|
-
where: (0,
|
|
14431
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm47.eq)(merchantCoupon.amountDiscount, params.amountDiscount))
|
|
14221
14432
|
});
|
|
14222
14433
|
const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
|
|
14223
14434
|
if (parsed.success) {
|
|
@@ -14227,7 +14438,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14227
14438
|
},
|
|
14228
14439
|
async getMerchantCoupon(merchantCouponId) {
|
|
14229
14440
|
const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
|
|
14230
|
-
where: (0,
|
|
14441
|
+
where: (0, import_drizzle_orm47.eq)(merchantCoupon.id, merchantCouponId)
|
|
14231
14442
|
});
|
|
14232
14443
|
const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
|
|
14233
14444
|
if (parsed.success) {
|
|
@@ -14237,7 +14448,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14237
14448
|
},
|
|
14238
14449
|
async getMerchantProduct(stripeProductId) {
|
|
14239
14450
|
return merchantProductSchema.nullable().parse(await client.query.merchantProduct.findFirst({
|
|
14240
|
-
where: (0,
|
|
14451
|
+
where: (0, import_drizzle_orm47.eq)(merchantProduct.identifier, stripeProductId)
|
|
14241
14452
|
}));
|
|
14242
14453
|
},
|
|
14243
14454
|
getPrice(productId) {
|
|
@@ -14245,7 +14456,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14245
14456
|
},
|
|
14246
14457
|
async getPriceForProduct(productId) {
|
|
14247
14458
|
return priceSchema.nullable().parse(await client.query.prices.findFirst({
|
|
14248
|
-
where: (0,
|
|
14459
|
+
where: (0, import_drizzle_orm47.eq)(prices.productId, productId)
|
|
14249
14460
|
}));
|
|
14250
14461
|
},
|
|
14251
14462
|
async archiveProduct(productId) {
|
|
@@ -14261,19 +14472,19 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14261
14472
|
await client.update(products).set({
|
|
14262
14473
|
status: 0,
|
|
14263
14474
|
name: `${product.name} (Archived)`
|
|
14264
|
-
}).where((0,
|
|
14475
|
+
}).where((0, import_drizzle_orm47.eq)(products.id, productId));
|
|
14265
14476
|
await client.update(prices).set({
|
|
14266
14477
|
status: 0,
|
|
14267
14478
|
nickname: `${product.name} (Archived)`
|
|
14268
|
-
}).where((0,
|
|
14479
|
+
}).where((0, import_drizzle_orm47.eq)(prices.productId, productId));
|
|
14269
14480
|
await client.update(merchantProduct).set({
|
|
14270
14481
|
status: 0
|
|
14271
|
-
}).where((0,
|
|
14482
|
+
}).where((0, import_drizzle_orm47.eq)(merchantProduct.productId, productId));
|
|
14272
14483
|
await client.update(merchantPrice).set({
|
|
14273
14484
|
status: 0
|
|
14274
|
-
}).where((0,
|
|
14485
|
+
}).where((0, import_drizzle_orm47.eq)(merchantPrice.priceId, product.price.id));
|
|
14275
14486
|
const currentMerchantProduct = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
14276
|
-
where: (0,
|
|
14487
|
+
where: (0, import_drizzle_orm47.eq)(merchantProduct.productId, productId)
|
|
14277
14488
|
}));
|
|
14278
14489
|
if (!currentMerchantProduct || !currentMerchantProduct.identifier) {
|
|
14279
14490
|
throw new Error(`Merchant product not found for id (${productId})`);
|
|
@@ -14282,7 +14493,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14282
14493
|
active: false
|
|
14283
14494
|
});
|
|
14284
14495
|
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
14285
|
-
where: (0,
|
|
14496
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantPrice.priceId, product.price.id), (0, import_drizzle_orm47.eq)(merchantPrice.status, 1))
|
|
14286
14497
|
}));
|
|
14287
14498
|
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
14288
14499
|
throw new Error(`Merchant price not found for id (${productId})`);
|
|
@@ -14303,7 +14514,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14303
14514
|
throw new Error(`Product has no price`);
|
|
14304
14515
|
}
|
|
14305
14516
|
const merchantProduct2 = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
14306
|
-
where: (merchantProduct3, { eq:
|
|
14517
|
+
where: (merchantProduct3, { eq: eq3 }) => eq3(merchantProduct3.productId, input.id)
|
|
14307
14518
|
}));
|
|
14308
14519
|
if (!merchantProduct2 || !merchantProduct2.identifier) {
|
|
14309
14520
|
throw new Error(`Merchant product not found`);
|
|
@@ -14311,7 +14522,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14311
14522
|
const stripeProduct = await paymentProvider.getProduct(merchantProduct2.identifier);
|
|
14312
14523
|
const priceChanged = currentProduct.price.unitAmount.toString() !== input.price?.unitAmount.toString();
|
|
14313
14524
|
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
14314
|
-
where: (merchantPrice2, { eq:
|
|
14525
|
+
where: (merchantPrice2, { eq: eq3, and: and3 }) => and3(eq3(merchantPrice2.merchantProductId, merchantProduct2.id), eq3(merchantPrice2.status, 1))
|
|
14315
14526
|
}));
|
|
14316
14527
|
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
14317
14528
|
throw new Error(`Merchant price not found`);
|
|
@@ -14366,12 +14577,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14366
14577
|
if (currentMerchantPrice) {
|
|
14367
14578
|
await client.update(merchantPrice).set({
|
|
14368
14579
|
status: 0
|
|
14369
|
-
}).where((0,
|
|
14580
|
+
}).where((0, import_drizzle_orm47.eq)(merchantPrice.id, currentMerchantPrice.id));
|
|
14370
14581
|
}
|
|
14371
14582
|
await client.update(prices).set({
|
|
14372
14583
|
unitAmount: Math.floor(Number(input.price?.unitAmount || 0)).toString(),
|
|
14373
14584
|
nickname: input.name
|
|
14374
|
-
}).where((0,
|
|
14585
|
+
}).where((0, import_drizzle_orm47.eq)(prices.id, currentProduct.price.id));
|
|
14375
14586
|
if (currentStripePrice) {
|
|
14376
14587
|
await paymentProvider.updatePrice(currentStripePrice.id, {
|
|
14377
14588
|
active: false
|
|
@@ -14401,14 +14612,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14401
14612
|
}
|
|
14402
14613
|
},
|
|
14403
14614
|
type: input.type
|
|
14404
|
-
}).where((0,
|
|
14615
|
+
}).where((0, import_drizzle_orm47.eq)(products.id, currentProduct.id));
|
|
14405
14616
|
return adapter.getProduct(currentProduct.id);
|
|
14406
14617
|
},
|
|
14407
14618
|
async createProduct(input) {
|
|
14408
14619
|
if (!paymentProvider)
|
|
14409
14620
|
throw new Error("Payment provider not found");
|
|
14410
14621
|
const merchantAccount2 = merchantAccountSchema.nullish().parse(await client.query.merchantAccount.findFirst({
|
|
14411
|
-
where: (merchantAccount3, { eq:
|
|
14622
|
+
where: (merchantAccount3, { eq: eq3 }) => eq3(merchantAccount3.label, "stripe")
|
|
14412
14623
|
}));
|
|
14413
14624
|
if (!merchantAccount2) {
|
|
14414
14625
|
throw new Error("Merchant account not found");
|
|
@@ -14495,7 +14706,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14495
14706
|
}
|
|
14496
14707
|
try {
|
|
14497
14708
|
const productData = await client.query.products.findFirst({
|
|
14498
|
-
where: (0,
|
|
14709
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), (0, import_drizzle_orm47.eq)(products.id, productSlugOrId))),
|
|
14499
14710
|
with: {
|
|
14500
14711
|
price: true,
|
|
14501
14712
|
...withResources && {
|
|
@@ -14532,20 +14743,20 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14532
14743
|
},
|
|
14533
14744
|
async getProductResources(productId) {
|
|
14534
14745
|
const contentResourceProductsForProduct = external_exports.array(ContentResourceProductSchema).nullable().parse(await client.query.contentResourceProduct.findMany({
|
|
14535
|
-
where: (0,
|
|
14746
|
+
where: (0, import_drizzle_orm47.eq)(contentResourceProduct.productId, productId)
|
|
14536
14747
|
}));
|
|
14537
14748
|
if (!contentResourceProductsForProduct) {
|
|
14538
14749
|
return null;
|
|
14539
14750
|
} else {
|
|
14540
14751
|
const contentResources = external_exports.array(ContentResourceSchema).parse(await client.query.contentResource.findMany({
|
|
14541
|
-
where: (0,
|
|
14752
|
+
where: (0, import_drizzle_orm47.inArray)(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
|
|
14542
14753
|
}));
|
|
14543
14754
|
return contentResources;
|
|
14544
14755
|
}
|
|
14545
14756
|
},
|
|
14546
14757
|
async getPurchaseCountForProduct(productId) {
|
|
14547
14758
|
return await client.query.purchases.findMany({
|
|
14548
|
-
where: (0,
|
|
14759
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, [
|
|
14549
14760
|
"Valid",
|
|
14550
14761
|
"Restricted"
|
|
14551
14762
|
]))
|
|
@@ -14553,7 +14764,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14553
14764
|
},
|
|
14554
14765
|
async getPurchase(purchaseId) {
|
|
14555
14766
|
const purchase = await client.query.purchases.findFirst({
|
|
14556
|
-
where: (0,
|
|
14767
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId)
|
|
14557
14768
|
});
|
|
14558
14769
|
return purchase ? purchaseSchema.parse(purchase) : null;
|
|
14559
14770
|
},
|
|
@@ -14571,7 +14782,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14571
14782
|
stripeChargeId
|
|
14572
14783
|
});
|
|
14573
14784
|
const chargeForPurchase = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
|
|
14574
|
-
where: (0,
|
|
14785
|
+
where: (0, import_drizzle_orm47.eq)(merchantCharge.identifier, stripeChargeId)
|
|
14575
14786
|
}) || null);
|
|
14576
14787
|
if (!chargeForPurchase) {
|
|
14577
14788
|
logger2.debug("getPurchaseForStripeCharge: no matching charge", {
|
|
@@ -14581,7 +14792,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14581
14792
|
return null;
|
|
14582
14793
|
}
|
|
14583
14794
|
const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
14584
|
-
where: (0,
|
|
14795
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantChargeId, chargeForPurchase.id),
|
|
14585
14796
|
with: {
|
|
14586
14797
|
user: true,
|
|
14587
14798
|
product: true,
|
|
@@ -14598,7 +14809,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14598
14809
|
checkoutSessionId
|
|
14599
14810
|
});
|
|
14600
14811
|
const session = await client.query.merchantSession.findFirst({
|
|
14601
|
-
where: (0,
|
|
14812
|
+
where: (0, import_drizzle_orm47.eq)(merchantSession.identifier, checkoutSessionId)
|
|
14602
14813
|
});
|
|
14603
14814
|
if (!session) {
|
|
14604
14815
|
logger2.debug("getPurchaseByCheckoutSessionId: no matching session", {
|
|
@@ -14607,7 +14818,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14607
14818
|
return null;
|
|
14608
14819
|
}
|
|
14609
14820
|
const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
14610
|
-
where: (0,
|
|
14821
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantSessionId, String(session.id)),
|
|
14611
14822
|
with: {
|
|
14612
14823
|
user: true,
|
|
14613
14824
|
product: true,
|
|
@@ -14621,7 +14832,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14621
14832
|
},
|
|
14622
14833
|
async getPurchaseUserTransferById(options) {
|
|
14623
14834
|
const purchaseTransferData = await client.query.purchaseUserTransfer.findFirst({
|
|
14624
|
-
where: (0,
|
|
14835
|
+
where: (0, import_drizzle_orm47.eq)(purchaseUserTransfer.id, options.id),
|
|
14625
14836
|
with: {
|
|
14626
14837
|
sourceUser: true,
|
|
14627
14838
|
targetUser: true,
|
|
@@ -14637,7 +14848,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14637
14848
|
},
|
|
14638
14849
|
async getPurchaseWithUser(purchaseId) {
|
|
14639
14850
|
const purchaseData = await client.query.purchases.findFirst({
|
|
14640
|
-
where: (0,
|
|
14851
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId),
|
|
14641
14852
|
with: {
|
|
14642
14853
|
user: true
|
|
14643
14854
|
}
|
|
@@ -14664,13 +14875,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14664
14875
|
"Restricted"
|
|
14665
14876
|
];
|
|
14666
14877
|
const userPurchases = await client.query.purchases.findMany({
|
|
14667
|
-
where: (0,
|
|
14878
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, visiblePurchaseStates)),
|
|
14668
14879
|
with: {
|
|
14669
14880
|
user: true,
|
|
14670
14881
|
product: true,
|
|
14671
14882
|
bulkCoupon: true
|
|
14672
14883
|
},
|
|
14673
|
-
orderBy: (0,
|
|
14884
|
+
orderBy: (0, import_drizzle_orm47.asc)(purchaseTable.createdAt)
|
|
14674
14885
|
});
|
|
14675
14886
|
const parsedPurchases = external_exports.array(purchaseSchema).safeParse(userPurchases);
|
|
14676
14887
|
if (!parsedPurchases.success) {
|
|
@@ -14689,22 +14900,22 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14689
14900
|
return [];
|
|
14690
14901
|
}
|
|
14691
14902
|
const conditions = [
|
|
14692
|
-
(0,
|
|
14903
|
+
(0, import_drizzle_orm47.eq)(entitlementTable.userId, userId)
|
|
14693
14904
|
];
|
|
14694
14905
|
if (sourceType) {
|
|
14695
|
-
conditions.push((0,
|
|
14906
|
+
conditions.push((0, import_drizzle_orm47.eq)(entitlementTable.sourceType, sourceType));
|
|
14696
14907
|
}
|
|
14697
14908
|
if (entitlementType) {
|
|
14698
|
-
conditions.push((0,
|
|
14909
|
+
conditions.push((0, import_drizzle_orm47.eq)(entitlementTable.entitlementType, entitlementType));
|
|
14699
14910
|
}
|
|
14700
|
-
conditions.push((0,
|
|
14701
|
-
const expiresCondition = (0,
|
|
14911
|
+
conditions.push((0, import_drizzle_orm47.isNull)(entitlementTable.deletedAt));
|
|
14912
|
+
const expiresCondition = (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.isNull)(entitlementTable.expiresAt), (0, import_drizzle_orm47.gte)(entitlementTable.expiresAt, import_drizzle_orm47.sql`CURRENT_TIMESTAMP`));
|
|
14702
14913
|
if (expiresCondition) {
|
|
14703
14914
|
conditions.push(expiresCondition);
|
|
14704
14915
|
}
|
|
14705
14916
|
const userEntitlements = await client.query.entitlements.findMany({
|
|
14706
|
-
where: conditions.length > 0 ? (0,
|
|
14707
|
-
orderBy: (0,
|
|
14917
|
+
where: conditions.length > 0 ? (0, import_drizzle_orm47.and)(...conditions) : void 0,
|
|
14918
|
+
orderBy: (0, import_drizzle_orm47.asc)(entitlementTable.createdAt)
|
|
14708
14919
|
});
|
|
14709
14920
|
const parsedEntitlements = external_exports.array(entitlementSchema).safeParse(userEntitlements);
|
|
14710
14921
|
if (!parsedEntitlements.success) {
|
|
@@ -14721,7 +14932,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14721
14932
|
},
|
|
14722
14933
|
async getEntitlementTypeByName(name) {
|
|
14723
14934
|
const entitlementType = await client.query.entitlementTypes.findFirst({
|
|
14724
|
-
where: (0,
|
|
14935
|
+
where: (0, import_drizzle_orm47.eq)(entitlementTypes.name, name)
|
|
14725
14936
|
});
|
|
14726
14937
|
if (!entitlementType) {
|
|
14727
14938
|
return null;
|
|
@@ -14738,18 +14949,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14738
14949
|
"Restricted"
|
|
14739
14950
|
];
|
|
14740
14951
|
const userPurchases = await client.query.purchases.findMany({
|
|
14741
|
-
where: (0,
|
|
14952
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, visiblePurchaseStates)),
|
|
14742
14953
|
with: {
|
|
14743
14954
|
user: true,
|
|
14744
14955
|
product: true,
|
|
14745
14956
|
bulkCoupon: true
|
|
14746
14957
|
},
|
|
14747
|
-
orderBy: (0,
|
|
14958
|
+
orderBy: (0, import_drizzle_orm47.asc)(purchaseTable.createdAt)
|
|
14748
14959
|
});
|
|
14749
14960
|
const parsedPurchases = external_exports.array(purchaseSchema).safeParse(userPurchases);
|
|
14750
14961
|
const allPurchases = parsedPurchases.success ? parsedPurchases.data : [];
|
|
14751
14962
|
const thePurchase = await client.query.purchases.findFirst({
|
|
14752
|
-
where: (0,
|
|
14963
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId)),
|
|
14753
14964
|
with: {
|
|
14754
14965
|
user: true,
|
|
14755
14966
|
product: true,
|
|
@@ -14774,7 +14985,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14774
14985
|
let availableUpgrades = [];
|
|
14775
14986
|
if (purchaseCanUpgrade) {
|
|
14776
14987
|
availableUpgrades = await client.query.upgradableProducts.findMany({
|
|
14777
|
-
where: (0,
|
|
14988
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(upgradableProducts.upgradableFromId, parsedPurchase.data.product?.id), (0, import_drizzle_orm47.not)((0, import_drizzle_orm47.inArray)(upgradableProducts.upgradableToId, allPurchases.map((p) => p.product?.id)))),
|
|
14778
14989
|
with: {
|
|
14779
14990
|
upgradableTo: true,
|
|
14780
14991
|
upgradableFrom: true
|
|
@@ -14782,10 +14993,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14782
14993
|
});
|
|
14783
14994
|
}
|
|
14784
14995
|
const existingPurchase = purchaseSchema.optional().nullable().parse(await client.query.purchases.findFirst({
|
|
14785
|
-
where: (0,
|
|
14996
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.eq)(purchaseTable.productId, parsedPurchase.data.productId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, [
|
|
14786
14997
|
"Valid",
|
|
14787
14998
|
"Restricted"
|
|
14788
|
-
]), (0,
|
|
14999
|
+
]), (0, import_drizzle_orm47.isNull)(purchaseTable.bulkCouponId), (0, import_drizzle_orm47.not)((0, import_drizzle_orm47.eq)(purchaseTable.id, parsedPurchase.data.id))),
|
|
14789
15000
|
with: {
|
|
14790
15001
|
user: true,
|
|
14791
15002
|
product: true,
|
|
@@ -14800,7 +15011,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14800
15011
|
},
|
|
14801
15012
|
async getUserWithPurchasersByEmail(email) {
|
|
14802
15013
|
const user = await client.query.users.findFirst({
|
|
14803
|
-
where: (0,
|
|
15014
|
+
where: (0, import_drizzle_orm47.eq)(users.email, email.trim().toLowerCase()),
|
|
14804
15015
|
with: {
|
|
14805
15016
|
// merchantCustomer: true,
|
|
14806
15017
|
roles: {
|
|
@@ -14827,7 +15038,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14827
15038
|
},
|
|
14828
15039
|
async getUserById(userId) {
|
|
14829
15040
|
const user = await client.query.users.findFirst({
|
|
14830
|
-
where: (0,
|
|
15041
|
+
where: (0, import_drizzle_orm47.eq)(users.id, userId),
|
|
14831
15042
|
with: {
|
|
14832
15043
|
roles: {
|
|
14833
15044
|
with: {
|
|
@@ -14849,13 +15060,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14849
15060
|
if (userId === void 0)
|
|
14850
15061
|
return [];
|
|
14851
15062
|
const canUpgradeProducts = await client.query.upgradableProducts.findMany({
|
|
14852
|
-
where: (0,
|
|
15063
|
+
where: (0, import_drizzle_orm47.eq)(upgradableProducts.upgradableToId, bundleId)
|
|
14853
15064
|
});
|
|
14854
15065
|
const upgradableFrom = external_exports.array(external_exports.string()).parse(canUpgradeProducts.map((product) => {
|
|
14855
15066
|
return product.upgradableFromId;
|
|
14856
15067
|
}));
|
|
14857
15068
|
const purchases = await client.query.purchases.findMany({
|
|
14858
|
-
where: (0,
|
|
15069
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.productId, upgradableFrom))
|
|
14859
15070
|
});
|
|
14860
15071
|
const productsPurchased = external_exports.array(external_exports.string()).parse(purchases.map((purchase) => {
|
|
14861
15072
|
return purchase.productId;
|
|
@@ -14863,7 +15074,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14863
15074
|
if (productsPurchased.length === 0)
|
|
14864
15075
|
return [];
|
|
14865
15076
|
const foundPrices = await client.query.prices.findMany({
|
|
14866
|
-
where: (0,
|
|
15077
|
+
where: (0, import_drizzle_orm47.inArray)(prices.productId, productsPurchased)
|
|
14867
15078
|
});
|
|
14868
15079
|
return external_exports.array(priceSchema).parse(foundPrices);
|
|
14869
15080
|
},
|
|
@@ -14872,14 +15083,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14872
15083
|
throw new Error("No lessonId provided");
|
|
14873
15084
|
}
|
|
14874
15085
|
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
14875
|
-
where: (0,
|
|
15086
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
|
|
14876
15087
|
});
|
|
14877
15088
|
const now = /* @__PURE__ */ new Date();
|
|
14878
15089
|
if (lessonProgress) {
|
|
14879
15090
|
await client.update(resourceProgress).set({
|
|
14880
15091
|
completedAt: lessonProgress.completedAt ? null : now,
|
|
14881
15092
|
updatedAt: now
|
|
14882
|
-
}).where((0,
|
|
15093
|
+
}).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId)));
|
|
14883
15094
|
} else {
|
|
14884
15095
|
await client.insert(resourceProgress).values({
|
|
14885
15096
|
userId: options.userId,
|
|
@@ -14889,7 +15100,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14889
15100
|
});
|
|
14890
15101
|
}
|
|
14891
15102
|
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
14892
|
-
where: (0,
|
|
15103
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
|
|
14893
15104
|
});
|
|
14894
15105
|
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
14895
15106
|
if (!parsedLessonProgress.success) {
|
|
@@ -14915,7 +15126,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14915
15126
|
throw new Error("No purchase found");
|
|
14916
15127
|
await trx.update(purchaseTable).set({
|
|
14917
15128
|
userId: targetUserId
|
|
14918
|
-
}).where((0,
|
|
15129
|
+
}).where((0, import_drizzle_orm47.eq)(purchaseTable.id, purchase.id));
|
|
14919
15130
|
await trx.insert(purchaseUserTransfer).values({
|
|
14920
15131
|
id: transferId,
|
|
14921
15132
|
purchaseId: purchase.id,
|
|
@@ -14930,21 +15141,21 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14930
15141
|
if (paymentProvider && purchase.merchantChargeId) {
|
|
14931
15142
|
await trx.update(merchantCharge).set({
|
|
14932
15143
|
userId: targetUserId
|
|
14933
|
-
}).where((0,
|
|
15144
|
+
}).where((0, import_drizzle_orm47.eq)(merchantCharge.id, purchase.merchantChargeId));
|
|
14934
15145
|
const updatedMerchantCharge = await adapter.getMerchantCharge(purchase.merchantChargeId);
|
|
14935
15146
|
if (!updatedMerchantCharge)
|
|
14936
15147
|
throw new Error("No merchant charge found");
|
|
14937
15148
|
await trx.update(merchantCustomer).set({
|
|
14938
15149
|
userId: targetUserId
|
|
14939
|
-
}).where((0,
|
|
15150
|
+
}).where((0, import_drizzle_orm47.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId));
|
|
14940
15151
|
const updatedMerchantCustomer = merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
|
|
14941
|
-
where: (0,
|
|
15152
|
+
where: (0, import_drizzle_orm47.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId)
|
|
14942
15153
|
}));
|
|
14943
15154
|
const targetUser = userSchema.parse(await client.query.users.findFirst({
|
|
14944
|
-
where: (0,
|
|
15155
|
+
where: (0, import_drizzle_orm47.eq)(users.id, targetUserId)
|
|
14945
15156
|
}));
|
|
14946
15157
|
const sourceUser = userSchema.parse(await client.query.users.findFirst({
|
|
14947
|
-
where: (0,
|
|
15158
|
+
where: (0, import_drizzle_orm47.eq)(users.id, sourceUserId)
|
|
14948
15159
|
}));
|
|
14949
15160
|
await paymentProvider.updateCustomer(updatedMerchantCustomer.identifier, {
|
|
14950
15161
|
email: targetUser.email,
|
|
@@ -14971,7 +15182,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14971
15182
|
status
|
|
14972
15183
|
});
|
|
14973
15184
|
const merchantChargeForPurchase = await client.query.merchantCharge.findFirst({
|
|
14974
|
-
where: (0,
|
|
15185
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(merchantCharge.identifier, chargeId), (0, import_drizzle_orm47.eq)(merchantCharge.id, chargeId))
|
|
14975
15186
|
});
|
|
14976
15187
|
logger2.debug("adapter.purchase.status_update.charge_resolved", {
|
|
14977
15188
|
chargeId,
|
|
@@ -14982,15 +15193,15 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
14982
15193
|
if (!parsedMerchantChargeForPurchase)
|
|
14983
15194
|
throw new Error(`no-charge-found-for-purchase ${chargeId}`);
|
|
14984
15195
|
const purchase = await client.query.purchases.findFirst({
|
|
14985
|
-
where: (0,
|
|
15196
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
|
|
14986
15197
|
});
|
|
14987
15198
|
const parsedPurchase = purchaseSchema.nullable().parse(purchase);
|
|
14988
15199
|
if (parsedPurchase) {
|
|
14989
15200
|
await client.update(purchaseTable).set({
|
|
14990
15201
|
status
|
|
14991
|
-
}).where((0,
|
|
15202
|
+
}).where((0, import_drizzle_orm47.eq)(purchaseTable.id, parsedPurchase.id));
|
|
14992
15203
|
const newPurchase = await client.query.purchases.findFirst({
|
|
14993
|
-
where: (0,
|
|
15204
|
+
where: (0, import_drizzle_orm47.eq)(purchaseTable.id, parsedPurchase.id)
|
|
14994
15205
|
});
|
|
14995
15206
|
return purchaseSchema.optional().parse(newPurchase);
|
|
14996
15207
|
} else {
|
|
@@ -15008,16 +15219,16 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15008
15219
|
async updatePurchaseUserTransferTransferState(options) {
|
|
15009
15220
|
await client.update(purchaseUserTransfer).set({
|
|
15010
15221
|
transferState: options.transferState
|
|
15011
|
-
}).where((0,
|
|
15222
|
+
}).where((0, import_drizzle_orm47.eq)(purchaseUserTransfer.id, options.id));
|
|
15012
15223
|
const purchaseUserTransferData = await client.query.purchaseUserTransfer.findFirst({
|
|
15013
|
-
where: (0,
|
|
15224
|
+
where: (0, import_drizzle_orm47.eq)(purchaseUserTransfer.id, options.id)
|
|
15014
15225
|
}) || null;
|
|
15015
15226
|
return purchaseUserTransferSchema.nullable().parse(purchaseUserTransferData);
|
|
15016
15227
|
},
|
|
15017
15228
|
addResourceToResource: async function(options) {
|
|
15018
15229
|
const { parentResourceId, childResourceId } = options;
|
|
15019
15230
|
const parentResourceData = await client.query.contentResource.findFirst({
|
|
15020
|
-
where: (0,
|
|
15231
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm47.eq)(contentResource.id, parentResourceId)),
|
|
15021
15232
|
with: {
|
|
15022
15233
|
resources: true
|
|
15023
15234
|
}
|
|
@@ -15033,7 +15244,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15033
15244
|
position: parentResource.resources?.length || 0
|
|
15034
15245
|
});
|
|
15035
15246
|
const resourceJoin = await client.query.contentResourceResource.findFirst({
|
|
15036
|
-
where: (0,
|
|
15247
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, childResourceId)),
|
|
15037
15248
|
with: {
|
|
15038
15249
|
resource: true
|
|
15039
15250
|
}
|
|
@@ -15047,7 +15258,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15047
15258
|
async removeResourceFromResource(options) {
|
|
15048
15259
|
const { childResourceId, parentResourceId } = options;
|
|
15049
15260
|
const parentResourceData = await client.query.contentResource.findFirst({
|
|
15050
|
-
where: (0,
|
|
15261
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm47.eq)(contentResource.id, parentResourceId))
|
|
15051
15262
|
});
|
|
15052
15263
|
const parsedParentResource = ContentResourceSchema.safeParse(parentResourceData);
|
|
15053
15264
|
if (!parsedParentResource.success) {
|
|
@@ -15055,7 +15266,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15055
15266
|
}
|
|
15056
15267
|
const parentResource = parsedParentResource.data;
|
|
15057
15268
|
const resourceJoin = await client.query.contentResourceResource.findFirst({
|
|
15058
|
-
where: (0,
|
|
15269
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, childResourceId)),
|
|
15059
15270
|
with: {
|
|
15060
15271
|
resource: true
|
|
15061
15272
|
}
|
|
@@ -15064,22 +15275,22 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15064
15275
|
if (!parsedResourceJoin.success) {
|
|
15065
15276
|
return null;
|
|
15066
15277
|
}
|
|
15067
|
-
await client.delete(contentResourceResource).where((0,
|
|
15278
|
+
await client.delete(contentResourceResource).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, childResourceId)));
|
|
15068
15279
|
return parsedResourceJoin.data.resource;
|
|
15069
15280
|
},
|
|
15070
15281
|
async updateContentResourceFields(options) {
|
|
15071
15282
|
if (!options.id) {
|
|
15072
15283
|
throw new Error("No content resource id.");
|
|
15073
15284
|
}
|
|
15074
|
-
const currentResource = await client.select().from(contentResource).where((0,
|
|
15285
|
+
const currentResource = await client.select().from(contentResource).where((0, import_drizzle_orm47.eq)(contentResource.id, options.id)).then((res) => res[0]);
|
|
15075
15286
|
await client.update(contentResource).set({
|
|
15076
15287
|
fields: {
|
|
15077
15288
|
...currentResource.fields,
|
|
15078
15289
|
...options.fields
|
|
15079
15290
|
}
|
|
15080
|
-
}).where((0,
|
|
15291
|
+
}).where((0, import_drizzle_orm47.eq)(contentResource.id, options.id));
|
|
15081
15292
|
const resource = await client.query.contentResource.findFirst({
|
|
15082
|
-
where: (0,
|
|
15293
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, options.id),
|
|
15083
15294
|
with: {
|
|
15084
15295
|
resources: {
|
|
15085
15296
|
with: {
|
|
@@ -15089,12 +15300,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15089
15300
|
with: {
|
|
15090
15301
|
resource: true
|
|
15091
15302
|
},
|
|
15092
|
-
orderBy: (0,
|
|
15303
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15093
15304
|
}
|
|
15094
15305
|
}
|
|
15095
15306
|
}
|
|
15096
15307
|
},
|
|
15097
|
-
orderBy: (0,
|
|
15308
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15098
15309
|
}
|
|
15099
15310
|
}
|
|
15100
15311
|
});
|
|
@@ -15112,7 +15323,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15112
15323
|
if (!id) {
|
|
15113
15324
|
return null;
|
|
15114
15325
|
}
|
|
15115
|
-
const query =
|
|
15326
|
+
const query = import_drizzle_orm47.sql`
|
|
15116
15327
|
SELECT
|
|
15117
15328
|
id as id,
|
|
15118
15329
|
CAST(updatedAt AS DATETIME) as updatedAt,
|
|
@@ -15145,7 +15356,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15145
15356
|
if (!videoResourceId) {
|
|
15146
15357
|
return null;
|
|
15147
15358
|
}
|
|
15148
|
-
const results = await client.select().from(contentResource).innerJoin(contentResourceResource, (0,
|
|
15359
|
+
const results = await client.select().from(contentResource).innerJoin(contentResourceResource, (0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, contentResource.id)).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, videoResourceId), (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.type, "post"), (0, import_drizzle_orm47.eq)(contentResource.type, "lesson")))).limit(1);
|
|
15149
15360
|
if (!results || results.length === 0) {
|
|
15150
15361
|
return null;
|
|
15151
15362
|
}
|
|
@@ -15154,7 +15365,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15154
15365
|
return null;
|
|
15155
15366
|
}
|
|
15156
15367
|
const fullResource = await client.query.contentResource.findFirst({
|
|
15157
|
-
where: (0,
|
|
15368
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, resourceData.id),
|
|
15158
15369
|
with: {
|
|
15159
15370
|
resources: true
|
|
15160
15371
|
}
|
|
@@ -15171,7 +15382,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15171
15382
|
id
|
|
15172
15383
|
});
|
|
15173
15384
|
const resource = await client.query.contentResource.findFirst({
|
|
15174
|
-
where: (0,
|
|
15385
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, id),
|
|
15175
15386
|
with: {
|
|
15176
15387
|
resources: {
|
|
15177
15388
|
with: {
|
|
@@ -15181,12 +15392,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15181
15392
|
with: {
|
|
15182
15393
|
resource: true
|
|
15183
15394
|
},
|
|
15184
|
-
orderBy: (0,
|
|
15395
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15185
15396
|
}
|
|
15186
15397
|
}
|
|
15187
15398
|
}
|
|
15188
15399
|
},
|
|
15189
|
-
orderBy: (0,
|
|
15400
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15190
15401
|
}
|
|
15191
15402
|
}
|
|
15192
15403
|
});
|
|
@@ -15203,7 +15414,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15203
15414
|
},
|
|
15204
15415
|
async getContentResource(data) {
|
|
15205
15416
|
const resource = await client.query.contentResource.findFirst({
|
|
15206
|
-
where: (0,
|
|
15417
|
+
where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.id, data), (0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, `${data}`)),
|
|
15207
15418
|
with: {
|
|
15208
15419
|
resources: {
|
|
15209
15420
|
with: {
|
|
@@ -15221,12 +15432,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15221
15432
|
}
|
|
15222
15433
|
}
|
|
15223
15434
|
},
|
|
15224
|
-
orderBy: (0,
|
|
15435
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15225
15436
|
}
|
|
15226
15437
|
}
|
|
15227
15438
|
}
|
|
15228
15439
|
},
|
|
15229
|
-
orderBy: (0,
|
|
15440
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15230
15441
|
}
|
|
15231
15442
|
}
|
|
15232
15443
|
});
|
|
@@ -15244,14 +15455,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15244
15455
|
async getEvent(eventIdOrSlug, options) {
|
|
15245
15456
|
const { withResources = false, withTags = false, withProducts = false, withPricing = false } = options || {};
|
|
15246
15457
|
const eventQuery = await client.query.contentResource.findFirst({
|
|
15247
|
-
where: (0,
|
|
15458
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.type, "event"), (0, import_drizzle_orm47.eq)(contentResource.type, "event-series")), (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.id, eventIdOrSlug), (0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, eventIdOrSlug))),
|
|
15248
15459
|
with: {
|
|
15249
15460
|
...withResources && {
|
|
15250
15461
|
resources: {
|
|
15251
15462
|
with: {
|
|
15252
15463
|
resource: true
|
|
15253
15464
|
},
|
|
15254
|
-
orderBy: (0,
|
|
15465
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15255
15466
|
}
|
|
15256
15467
|
},
|
|
15257
15468
|
...withTags && {
|
|
@@ -15259,7 +15470,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15259
15470
|
with: {
|
|
15260
15471
|
tag: true
|
|
15261
15472
|
},
|
|
15262
|
-
orderBy: (0,
|
|
15473
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceTag.position)
|
|
15263
15474
|
}
|
|
15264
15475
|
},
|
|
15265
15476
|
...withProducts && {
|
|
@@ -15302,7 +15513,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15302
15513
|
}
|
|
15303
15514
|
});
|
|
15304
15515
|
const resourceProduct = await client.query.contentResourceProduct.findFirst({
|
|
15305
|
-
where: (0,
|
|
15516
|
+
where: (0, import_drizzle_orm47.eq)(contentResourceProduct.resourceId, resource.id),
|
|
15306
15517
|
with: {
|
|
15307
15518
|
resource: true,
|
|
15308
15519
|
product: true
|
|
@@ -15464,7 +15675,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15464
15675
|
};
|
|
15465
15676
|
await tx.insert(contentResource).values(newEventSeries);
|
|
15466
15677
|
const eventSeriesResource = await tx.query.contentResource.findFirst({
|
|
15467
|
-
where: (0,
|
|
15678
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, eventSeriesResourceId),
|
|
15468
15679
|
with: {
|
|
15469
15680
|
resources: {
|
|
15470
15681
|
with: {
|
|
@@ -15474,18 +15685,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15474
15685
|
with: {
|
|
15475
15686
|
resource: true
|
|
15476
15687
|
},
|
|
15477
|
-
orderBy: (0,
|
|
15688
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15478
15689
|
}
|
|
15479
15690
|
}
|
|
15480
15691
|
}
|
|
15481
15692
|
},
|
|
15482
|
-
orderBy: (0,
|
|
15693
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15483
15694
|
},
|
|
15484
15695
|
tags: {
|
|
15485
15696
|
with: {
|
|
15486
15697
|
tag: true
|
|
15487
15698
|
},
|
|
15488
|
-
orderBy: (0,
|
|
15699
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceTag.position)
|
|
15489
15700
|
},
|
|
15490
15701
|
resourceProducts: {
|
|
15491
15702
|
with: {
|
|
@@ -15538,7 +15749,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15538
15749
|
};
|
|
15539
15750
|
await tx.insert(contentResource).values(newChildEvent);
|
|
15540
15751
|
const childEventResource = await tx.query.contentResource.findFirst({
|
|
15541
|
-
where: (0,
|
|
15752
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, childEventResourceId),
|
|
15542
15753
|
with: {
|
|
15543
15754
|
resources: {
|
|
15544
15755
|
with: {
|
|
@@ -15548,18 +15759,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15548
15759
|
with: {
|
|
15549
15760
|
resource: true
|
|
15550
15761
|
},
|
|
15551
|
-
orderBy: (0,
|
|
15762
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15552
15763
|
}
|
|
15553
15764
|
}
|
|
15554
15765
|
}
|
|
15555
15766
|
},
|
|
15556
|
-
orderBy: (0,
|
|
15767
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15557
15768
|
},
|
|
15558
15769
|
tags: {
|
|
15559
15770
|
with: {
|
|
15560
15771
|
tag: true
|
|
15561
15772
|
},
|
|
15562
|
-
orderBy: (0,
|
|
15773
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceTag.position)
|
|
15563
15774
|
},
|
|
15564
15775
|
resourceProducts: {
|
|
15565
15776
|
with: {
|
|
@@ -15686,13 +15897,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15686
15897
|
}
|
|
15687
15898
|
});
|
|
15688
15899
|
const cohort2 = await tx.query.contentResource.findFirst({
|
|
15689
|
-
where: (0,
|
|
15900
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, cohortId),
|
|
15690
15901
|
with: {
|
|
15691
15902
|
resources: {
|
|
15692
15903
|
with: {
|
|
15693
15904
|
resource: true
|
|
15694
15905
|
},
|
|
15695
|
-
orderBy: (0,
|
|
15906
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15696
15907
|
}
|
|
15697
15908
|
}
|
|
15698
15909
|
});
|
|
@@ -15805,7 +16016,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15805
16016
|
}
|
|
15806
16017
|
});
|
|
15807
16018
|
const workshop = await tx.query.contentResource.findFirst({
|
|
15808
|
-
where: (0,
|
|
16019
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, workshopId),
|
|
15809
16020
|
with: {
|
|
15810
16021
|
resources: {
|
|
15811
16022
|
with: {
|
|
@@ -15815,12 +16026,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15815
16026
|
with: {
|
|
15816
16027
|
resource: true
|
|
15817
16028
|
},
|
|
15818
|
-
orderBy: (0,
|
|
16029
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15819
16030
|
}
|
|
15820
16031
|
}
|
|
15821
16032
|
}
|
|
15822
16033
|
},
|
|
15823
|
-
orderBy: (0,
|
|
16034
|
+
orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
|
|
15824
16035
|
}
|
|
15825
16036
|
}
|
|
15826
16037
|
});
|
|
@@ -15864,7 +16075,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15864
16075
|
position
|
|
15865
16076
|
});
|
|
15866
16077
|
const section = await tx.query.contentResource.findFirst({
|
|
15867
|
-
where: (0,
|
|
16078
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, sectionId)
|
|
15868
16079
|
});
|
|
15869
16080
|
if (section) {
|
|
15870
16081
|
createdSections.push(section);
|
|
@@ -15898,7 +16109,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15898
16109
|
position: lessonPosition
|
|
15899
16110
|
});
|
|
15900
16111
|
const lesson = await tx.query.contentResource.findFirst({
|
|
15901
|
-
where: (0,
|
|
16112
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, lessonId)
|
|
15902
16113
|
});
|
|
15903
16114
|
if (lesson) {
|
|
15904
16115
|
createdLessons.push(lesson);
|
|
@@ -15934,7 +16145,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
15934
16145
|
position
|
|
15935
16146
|
});
|
|
15936
16147
|
const lesson = await tx.query.contentResource.findFirst({
|
|
15937
|
-
where: (0,
|
|
16148
|
+
where: (0, import_drizzle_orm47.eq)(contentResource.id, lessonId)
|
|
15938
16149
|
});
|
|
15939
16150
|
if (lesson) {
|
|
15940
16151
|
createdLessons.push(lesson);
|
|
@@ -16037,7 +16248,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16037
16248
|
__name(findClosestDiscount, "findClosestDiscount");
|
|
16038
16249
|
const percentageDiscount = findClosestDiscount(Number(input.percentageDiscount) * 100);
|
|
16039
16250
|
const merchantCouponResult = percentageDiscount < 1 ? await client.query.merchantCoupon.findFirst({
|
|
16040
|
-
where: (0,
|
|
16251
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.percentageDiscount, percentageDiscount.toString()), (0, import_drizzle_orm47.eq)(merchantCoupon.type, "special"))
|
|
16041
16252
|
}) : null;
|
|
16042
16253
|
if (!merchantCouponResult) {
|
|
16043
16254
|
return [];
|
|
@@ -16084,54 +16295,54 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16084
16295
|
}
|
|
16085
16296
|
},
|
|
16086
16297
|
async getUser(data) {
|
|
16087
|
-
return await client.select().from(users).where((0,
|
|
16298
|
+
return await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.id, data)).then((res) => res[0]) ?? null;
|
|
16088
16299
|
},
|
|
16089
16300
|
async getUserByEmail(data) {
|
|
16090
|
-
return await client.select().from(users).where((0,
|
|
16301
|
+
return await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.email, data)).then((res) => res[0]) ?? null;
|
|
16091
16302
|
},
|
|
16092
16303
|
async createSession(data) {
|
|
16093
16304
|
await client.insert(sessions).values(data);
|
|
16094
|
-
return await client.select().from(sessions).where((0,
|
|
16305
|
+
return await client.select().from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
|
|
16095
16306
|
},
|
|
16096
16307
|
async getSessionAndUser(data) {
|
|
16097
16308
|
return await client.select({
|
|
16098
16309
|
session: sessions,
|
|
16099
16310
|
user: users
|
|
16100
|
-
}).from(sessions).where((0,
|
|
16311
|
+
}).from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data)).innerJoin(users, (0, import_drizzle_orm47.eq)(users.id, sessions.userId)).then((res) => res[0]) ?? null;
|
|
16101
16312
|
},
|
|
16102
16313
|
async updateUser(data) {
|
|
16103
16314
|
if (!data.id) {
|
|
16104
16315
|
throw new Error("No user id.");
|
|
16105
16316
|
}
|
|
16106
|
-
await client.update(users).set(data).where((0,
|
|
16107
|
-
return await client.select().from(users).where((0,
|
|
16317
|
+
await client.update(users).set(data).where((0, import_drizzle_orm47.eq)(users.id, data.id));
|
|
16318
|
+
return await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.id, data.id)).then((res) => res[0]);
|
|
16108
16319
|
},
|
|
16109
16320
|
async updateSession(data) {
|
|
16110
|
-
await client.update(sessions).set(data).where((0,
|
|
16111
|
-
return await client.select().from(sessions).where((0,
|
|
16321
|
+
await client.update(sessions).set(data).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data.sessionToken));
|
|
16322
|
+
return await client.select().from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
|
|
16112
16323
|
},
|
|
16113
16324
|
async linkAccount(rawAccount) {
|
|
16114
16325
|
await client.insert(accounts).values(rawAccount);
|
|
16115
16326
|
},
|
|
16116
16327
|
async getUserByAccount(account) {
|
|
16117
|
-
const dbAccount = await client.select().from(accounts).where((0,
|
|
16328
|
+
const dbAccount = await client.select().from(accounts).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm47.eq)(accounts.provider, account.provider))).leftJoin(users, (0, import_drizzle_orm47.eq)(accounts.userId, users.id)).then((res) => res[0]) ?? null;
|
|
16118
16329
|
if (!dbAccount) {
|
|
16119
16330
|
return null;
|
|
16120
16331
|
}
|
|
16121
16332
|
return dbAccount.User;
|
|
16122
16333
|
},
|
|
16123
16334
|
async deleteSession(sessionToken) {
|
|
16124
|
-
const session = await client.select().from(sessions).where((0,
|
|
16125
|
-
await client.delete(sessions).where((0,
|
|
16335
|
+
const session = await client.select().from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
|
|
16336
|
+
await client.delete(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, sessionToken));
|
|
16126
16337
|
return session;
|
|
16127
16338
|
},
|
|
16128
16339
|
async createVerificationToken(token) {
|
|
16129
16340
|
await client.insert(verificationTokens).values(token);
|
|
16130
|
-
return await client.select().from(verificationTokens).where((0,
|
|
16341
|
+
return await client.select().from(verificationTokens).where((0, import_drizzle_orm47.eq)(verificationTokens.identifier, token.identifier)).then((res) => res[0]);
|
|
16131
16342
|
},
|
|
16132
16343
|
async useVerificationToken(token) {
|
|
16133
16344
|
try {
|
|
16134
|
-
const deletedToken = await client.select().from(verificationTokens).where((0,
|
|
16345
|
+
const deletedToken = await client.select().from(verificationTokens).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm47.eq)(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
|
|
16135
16346
|
if (deletedToken?.createdAt) {
|
|
16136
16347
|
const TIMEOUT_IN_SECONDS = 90;
|
|
16137
16348
|
const expireMultipleClicks = (0, import_date_fns2.addSeconds)(deletedToken.createdAt, TIMEOUT_IN_SECONDS);
|
|
@@ -16140,7 +16351,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16140
16351
|
const { id: _, ...verificationToken } = token;
|
|
16141
16352
|
return deletedToken;
|
|
16142
16353
|
} else {
|
|
16143
|
-
await client.delete(verificationTokens).where((0,
|
|
16354
|
+
await client.delete(verificationTokens).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm47.eq)(verificationTokens.token, token.token)));
|
|
16144
16355
|
return deletedToken;
|
|
16145
16356
|
}
|
|
16146
16357
|
}
|
|
@@ -16150,14 +16361,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16150
16361
|
}
|
|
16151
16362
|
},
|
|
16152
16363
|
async deleteUser(id) {
|
|
16153
|
-
const user = await client.select().from(users).where((0,
|
|
16154
|
-
await client.delete(users).where((0,
|
|
16155
|
-
await client.delete(sessions).where((0,
|
|
16156
|
-
await client.delete(accounts).where((0,
|
|
16364
|
+
const user = await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.id, id)).then((res) => res[0] ?? null);
|
|
16365
|
+
await client.delete(users).where((0, import_drizzle_orm47.eq)(users.id, id));
|
|
16366
|
+
await client.delete(sessions).where((0, import_drizzle_orm47.eq)(sessions.userId, id));
|
|
16367
|
+
await client.delete(accounts).where((0, import_drizzle_orm47.eq)(accounts.userId, id));
|
|
16157
16368
|
return user;
|
|
16158
16369
|
},
|
|
16159
16370
|
async unlinkAccount(account) {
|
|
16160
|
-
await client.delete(accounts).where((0,
|
|
16371
|
+
await client.delete(accounts).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm47.eq)(accounts.provider, account.provider)));
|
|
16161
16372
|
return void 0;
|
|
16162
16373
|
},
|
|
16163
16374
|
createOrganization: async (options) => {
|
|
@@ -16170,12 +16381,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16170
16381
|
},
|
|
16171
16382
|
getOrganization: async (organizationId) => {
|
|
16172
16383
|
return OrganizationSchema.parse(await client.query.organization.findFirst({
|
|
16173
|
-
where: (0,
|
|
16384
|
+
where: (0, import_drizzle_orm47.eq)(organizationTable.id, organizationId)
|
|
16174
16385
|
}));
|
|
16175
16386
|
},
|
|
16176
16387
|
addMemberToOrganization: async (options) => {
|
|
16177
16388
|
const currentMembership = await client.query.organizationMemberships.findFirst({
|
|
16178
|
-
where: (0,
|
|
16389
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(organizationMembershipTable.userId, options.userId)),
|
|
16179
16390
|
with: {
|
|
16180
16391
|
organization: true,
|
|
16181
16392
|
user: true
|
|
@@ -16190,7 +16401,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16190
16401
|
id
|
|
16191
16402
|
});
|
|
16192
16403
|
return OrganizationMemberSchema.parse(await client.query.organizationMemberships.findFirst({
|
|
16193
|
-
where: (0,
|
|
16404
|
+
where: (0, import_drizzle_orm47.eq)(organizationMembershipTable.id, id),
|
|
16194
16405
|
with: {
|
|
16195
16406
|
organization: true,
|
|
16196
16407
|
user: true
|
|
@@ -16199,13 +16410,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16199
16410
|
}
|
|
16200
16411
|
},
|
|
16201
16412
|
removeMemberFromOrganization: async (options) => {
|
|
16202
|
-
await client.delete(organizationMembershipTable).where((0,
|
|
16413
|
+
await client.delete(organizationMembershipTable).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(organizationMembershipTable.userId, options.userId)));
|
|
16203
16414
|
},
|
|
16204
16415
|
addRoleForMember: async (options) => {
|
|
16205
16416
|
const existingRole = external_exports.object({
|
|
16206
16417
|
id: external_exports.string()
|
|
16207
16418
|
}).nullish().parse(await client.query.roles.findFirst({
|
|
16208
|
-
where: (0,
|
|
16419
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(roleTable.name, options.role))
|
|
16209
16420
|
}));
|
|
16210
16421
|
const roleId = existingRole?.id || crypto.randomUUID();
|
|
16211
16422
|
if (!existingRole) {
|
|
@@ -16216,7 +16427,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16216
16427
|
});
|
|
16217
16428
|
}
|
|
16218
16429
|
const currentOrgMembershipRole = await client.query.organizationMembershipRoles.findFirst({
|
|
16219
|
-
where: (0,
|
|
16430
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(organizationMembershipRoleTable.organizationMembershipId, options.memberId), (0, import_drizzle_orm47.eq)(organizationMembershipRoleTable.roleId, roleId))
|
|
16220
16431
|
});
|
|
16221
16432
|
if (!currentOrgMembershipRole) {
|
|
16222
16433
|
await client.insert(organizationMembershipRoleTable).values({
|
|
@@ -16230,16 +16441,16 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16230
16441
|
const existingRole = external_exports.object({
|
|
16231
16442
|
id: external_exports.string()
|
|
16232
16443
|
}).nullable().parse(await client.query.roles.findFirst({
|
|
16233
|
-
where: (0,
|
|
16444
|
+
where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(roleTable.name, options.role))
|
|
16234
16445
|
}));
|
|
16235
16446
|
const roleId = existingRole?.id;
|
|
16236
16447
|
if (roleId) {
|
|
16237
|
-
await client.delete(organizationMembershipRoleTable).where((0,
|
|
16448
|
+
await client.delete(organizationMembershipRoleTable).where((0, import_drizzle_orm47.eq)(organizationMembershipRoleTable.roleId, roleId));
|
|
16238
16449
|
}
|
|
16239
16450
|
},
|
|
16240
16451
|
getMembershipsForUser: async (userId) => {
|
|
16241
16452
|
return OrganizationMemberSchema.array().parse(await client.query.organizationMemberships.findMany({
|
|
16242
|
-
where: (0,
|
|
16453
|
+
where: (0, import_drizzle_orm47.eq)(organizationMembershipTable.userId, userId),
|
|
16243
16454
|
with: {
|
|
16244
16455
|
organization: true,
|
|
16245
16456
|
user: true
|
|
@@ -16248,7 +16459,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16248
16459
|
},
|
|
16249
16460
|
getOrganizationMembers: async (organizationId) => {
|
|
16250
16461
|
return OrganizationMemberSchema.array().parse(await client.query.organizationMemberships.findMany({
|
|
16251
|
-
where: (0,
|
|
16462
|
+
where: (0, import_drizzle_orm47.eq)(organizationMembershipTable.organizationId, organizationId)
|
|
16252
16463
|
}) || []);
|
|
16253
16464
|
},
|
|
16254
16465
|
createSubscription: async (options) => {
|
|
@@ -16258,7 +16469,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16258
16469
|
id
|
|
16259
16470
|
});
|
|
16260
16471
|
return SubscriptionSchema.parse(await client.query.subscription.findFirst({
|
|
16261
|
-
where: (0,
|
|
16472
|
+
where: (0, import_drizzle_orm47.eq)(subscriptionTable.id, id),
|
|
16262
16473
|
with: {
|
|
16263
16474
|
product: true
|
|
16264
16475
|
}
|
|
@@ -16266,7 +16477,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16266
16477
|
},
|
|
16267
16478
|
getMerchantSubscription: async (merchantSubscriptionId) => {
|
|
16268
16479
|
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
16269
|
-
where: (0,
|
|
16480
|
+
where: (0, import_drizzle_orm47.eq)(merchantSubscriptionTable.id, merchantSubscriptionId)
|
|
16270
16481
|
}));
|
|
16271
16482
|
},
|
|
16272
16483
|
createMerchantSubscription: async (options) => {
|
|
@@ -16276,7 +16487,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16276
16487
|
id
|
|
16277
16488
|
});
|
|
16278
16489
|
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
16279
|
-
where: (0,
|
|
16490
|
+
where: (0, import_drizzle_orm47.eq)(merchantSubscriptionTable.id, id)
|
|
16280
16491
|
}));
|
|
16281
16492
|
},
|
|
16282
16493
|
updateMerchantSubscription: async (options) => {
|
|
@@ -16287,13 +16498,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16287
16498
|
},
|
|
16288
16499
|
getSubscriptionForStripeId: async (stripeSubscriptionId) => {
|
|
16289
16500
|
const merchantSubscriptionParsed = MerchantSubscriptionSchema.safeParse(await client.query.merchantSubscription.findFirst({
|
|
16290
|
-
where: (0,
|
|
16501
|
+
where: (0, import_drizzle_orm47.eq)(merchantSubscriptionTable.identifier, stripeSubscriptionId)
|
|
16291
16502
|
}));
|
|
16292
16503
|
if (!merchantSubscriptionParsed.success) {
|
|
16293
16504
|
throw new Error(`No merchant subscription found for stripe id ${stripeSubscriptionId} ${merchantSubscriptionParsed.error}`);
|
|
16294
16505
|
}
|
|
16295
16506
|
const subscriptionParsed = SubscriptionSchema.safeParse(await client.query.subscription.findFirst({
|
|
16296
|
-
where: (0,
|
|
16507
|
+
where: (0, import_drizzle_orm47.eq)(subscriptionTable.merchantSubscriptionId, merchantSubscriptionParsed.data.id),
|
|
16297
16508
|
with: {
|
|
16298
16509
|
product: true
|
|
16299
16510
|
}
|
|
@@ -16306,7 +16517,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16306
16517
|
updateSubscriptionStatus: async (subscriptionId, status) => {
|
|
16307
16518
|
await client.update(subscriptionTable).set({
|
|
16308
16519
|
status
|
|
16309
|
-
}).where((0,
|
|
16520
|
+
}).where((0, import_drizzle_orm47.eq)(subscriptionTable.id, subscriptionId));
|
|
16310
16521
|
}
|
|
16311
16522
|
};
|
|
16312
16523
|
return adapter;
|
|
@@ -16314,6 +16525,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
|
|
|
16314
16525
|
__name(mySqlDrizzleAdapter, "mySqlDrizzleAdapter");
|
|
16315
16526
|
// Annotate the CommonJS export names for ESM import in node:
|
|
16316
16527
|
0 && (module.exports = {
|
|
16528
|
+
createCmsResourceActions,
|
|
16317
16529
|
createTables,
|
|
16318
16530
|
getCourseBuilderSchema,
|
|
16319
16531
|
guid,
|