@coursebuilder/adapter-drizzle 0.5.0 → 0.5.2
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-BM5UKWXI.js → chunk-27UC2HEP.js} +2 -2
- package/dist/{chunk-QTGVGIRO.js → chunk-6SLQW6OM.js} +2 -2
- package/dist/{chunk-TBM3AK3P.js → chunk-EFVZ7IN4.js} +2 -2
- package/dist/{chunk-FRA4ZCRA.js → chunk-JW2PFVLO.js} +485 -223
- package/dist/{chunk-O6JECJRY.js → chunk-QQA7STVO.js} +2 -2
- package/dist/{chunk-CQNKTFXE.js → chunk-XJXCDN7B.js} +2 -2
- package/dist/{chunk-JZQ666KH.js → chunk-YMFPIZMO.js} +2 -2
- package/dist/{chunk-Z245DYMP.js → chunk-ZYQYJNLK.js} +569 -198
- package/dist/index.d.ts +3 -1
- package/dist/index.js +12 -12
- package/dist/lib/mysql/index.cjs +1349 -721
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +3147 -126
- package/dist/lib/mysql/index.d.ts +3147 -126
- package/dist/lib/mysql/index.js +10 -8
- package/dist/lib/mysql/schemas/auth/accounts.cjs +87 -71
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.d.cts +58 -1
- package/dist/lib/mysql/schemas/auth/accounts.d.ts +58 -1
- package/dist/lib/mysql/schemas/auth/accounts.js +1 -1
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs +79 -63
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-access-token.d.cts +12 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.d.ts +12 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.js +2 -2
- package/dist/lib/mysql/schemas/auth/device-verification.cjs +81 -65
- package/dist/lib/mysql/schemas/auth/device-verification.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-verification.d.cts +24 -0
- package/dist/lib/mysql/schemas/auth/device-verification.d.ts +24 -0
- package/dist/lib/mysql/schemas/auth/device-verification.js +2 -2
- package/dist/lib/mysql/schemas/auth/permissions.d.cts +28 -0
- package/dist/lib/mysql/schemas/auth/permissions.d.ts +28 -0
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs +76 -60
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.d.cts +24 -0
- package/dist/lib/mysql/schemas/auth/role-permissions.d.ts +24 -0
- package/dist/lib/mysql/schemas/auth/role-permissions.js +2 -2
- package/dist/lib/mysql/schemas/auth/roles.cjs +76 -60
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.d.cts +28 -0
- package/dist/lib/mysql/schemas/auth/roles.d.ts +28 -0
- package/dist/lib/mysql/schemas/auth/roles.js +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.cjs +77 -61
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.d.cts +12 -0
- package/dist/lib/mysql/schemas/auth/sessions.d.ts +12 -0
- package/dist/lib/mysql/schemas/auth/sessions.js +2 -2
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs +78 -62
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.d.cts +24 -0
- package/dist/lib/mysql/schemas/auth/user-permissions.d.ts +24 -0
- package/dist/lib/mysql/schemas/auth/user-permissions.js +1 -1
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs +82 -66
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-prefs.d.cts +28 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.d.ts +28 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.js +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.cjs +78 -62
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.d.cts +24 -0
- package/dist/lib/mysql/schemas/auth/user-roles.d.ts +24 -0
- package/dist/lib/mysql/schemas/auth/user-roles.js +1 -1
- package/dist/lib/mysql/schemas/auth/users.cjs +179 -159
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.d.cts +32 -0
- package/dist/lib/mysql/schemas/auth/users.d.ts +32 -0
- package/dist/lib/mysql/schemas/auth/users.js +1 -1
- package/dist/lib/mysql/schemas/auth/verification-tokens.d.cts +16 -0
- package/dist/lib/mysql/schemas/auth/verification-tokens.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/coupon.cjs +57 -51
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.d.cts +50 -14
- package/dist/lib/mysql/schemas/commerce/coupon.d.ts +50 -14
- package/dist/lib/mysql/schemas/commerce/coupon.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.cts +20 -0
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.ts +20 -0
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.cts +32 -0
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +32 -0
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.cts +24 -0
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.ts +24 -0
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.cts +24 -0
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.ts +24 -0
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.cts +28 -0
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.ts +28 -0
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.cts +24 -0
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.ts +24 -0
- package/dist/lib/mysql/schemas/commerce/merchant-session.d.cts +12 -0
- package/dist/lib/mysql/schemas/commerce/merchant-session.d.ts +12 -0
- package/dist/lib/mysql/schemas/commerce/price.cjs +44 -28
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.d.cts +28 -0
- package/dist/lib/mysql/schemas/commerce/price.d.ts +28 -0
- package/dist/lib/mysql/schemas/commerce/price.js +1 -1
- package/dist/lib/mysql/schemas/commerce/product.cjs +58 -42
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.d.cts +32 -0
- package/dist/lib/mysql/schemas/commerce/product.d.ts +32 -0
- package/dist/lib/mysql/schemas/commerce/product.js +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +106 -90
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.cts +40 -0
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +40 -0
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +2 -2
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +110 -98
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.d.cts +68 -0
- package/dist/lib/mysql/schemas/commerce/purchase.d.ts +68 -0
- package/dist/lib/mysql/schemas/commerce/purchase.js +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +50 -34
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.cts +28 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.ts +28 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +2 -2
- package/dist/lib/mysql/schemas/communication/comment.cjs +82 -66
- package/dist/lib/mysql/schemas/communication/comment.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/comment.d.cts +28 -0
- package/dist/lib/mysql/schemas/communication/comment.d.ts +28 -0
- package/dist/lib/mysql/schemas/communication/comment.js +1 -1
- package/dist/lib/mysql/schemas/communication/communication-channel.d.cts +28 -0
- package/dist/lib/mysql/schemas/communication/communication-channel.d.ts +28 -0
- package/dist/lib/mysql/schemas/communication/communication-preference-types.d.cts +28 -0
- package/dist/lib/mysql/schemas/communication/communication-preference-types.d.ts +28 -0
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +100 -84
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.d.cts +44 -0
- package/dist/lib/mysql/schemas/communication/communication-preferences.d.ts +44 -0
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +112 -92
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.d.cts +32 -0
- package/dist/lib/mysql/schemas/content/content-contributions.d.ts +32 -0
- package/dist/lib/mysql/schemas/content/content-contributions.js +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs +49 -29
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.d.cts +28 -0
- package/dist/lib/mysql/schemas/content/content-resource-product.d.ts +28 -0
- package/dist/lib/mysql/schemas/content/content-resource-product.js +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +49 -29
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.cts +28 -0
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.ts +28 -0
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-tag.cjs +274 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.cjs.map +1 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.d.cts +97 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.d.ts +97 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.js +21 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.js.map +1 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.cjs +288 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.cjs.map +1 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.d.cts +130 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.d.ts +130 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.js +21 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.js.map +1 -0
- package/dist/lib/mysql/schemas/content/content-resource.cjs +141 -15
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.d.cts +47 -0
- package/dist/lib/mysql/schemas/content/content-resource.d.ts +47 -0
- package/dist/lib/mysql/schemas/content/content-resource.js +1 -1
- package/dist/lib/mysql/schemas/content/contribution-types.d.cts +32 -0
- package/dist/lib/mysql/schemas/content/contribution-types.d.ts +32 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.d.cts +40 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.d.ts +40 -0
- package/dist/lib/mysql/schemas/content/resource-progress.d.cts +24 -0
- package/dist/lib/mysql/schemas/content/resource-progress.d.ts +24 -0
- package/dist/lib/mysql/schemas/content/tag-tag.cjs +241 -0
- package/dist/lib/mysql/schemas/content/tag-tag.cjs.map +1 -0
- package/dist/lib/mysql/schemas/content/tag-tag.d.cts +129 -0
- package/dist/lib/mysql/schemas/content/tag-tag.d.ts +129 -0
- package/dist/lib/mysql/schemas/content/tag-tag.js +21 -0
- package/dist/lib/mysql/schemas/content/tag-tag.js.map +1 -0
- package/dist/lib/mysql/schemas/content/tag.cjs +263 -0
- package/dist/lib/mysql/schemas/content/tag.cjs.map +1 -0
- package/dist/lib/mysql/schemas/content/tag.d.cts +114 -0
- package/dist/lib/mysql/schemas/content/tag.d.ts +114 -0
- package/dist/lib/mysql/schemas/content/tag.js +21 -0
- package/dist/lib/mysql/schemas/content/tag.js.map +1 -0
- package/dist/lib/mysql/utils.d.cts +1 -0
- package/dist/lib/mysql/utils.d.ts +1 -0
- package/dist/lib/utils.d.cts +2 -0
- package/dist/lib/utils.d.ts +2 -0
- package/package.json +8 -6
- package/src/index.ts +14 -4
- package/src/lib/mysql/index.ts +718 -182
- package/src/lib/mysql/schemas/commerce/coupon.ts +3 -9
- package/src/lib/mysql/schemas/content/content-resource-tag.ts +59 -0
- package/src/lib/mysql/schemas/content/content-resource-version.ts +69 -0
- package/src/lib/mysql/schemas/content/content-resource.ts +17 -0
- package/src/lib/mysql/schemas/content/tag-tag.ts +59 -0
- package/src/lib/mysql/schemas/content/tag.ts +48 -0
|
@@ -7,30 +7,30 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
getPurchaseUserTransferRelationsSchema,
|
|
9
9
|
getPurchaseUserTransferSchema
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-XJXCDN7B.js";
|
|
11
11
|
import {
|
|
12
12
|
getUpgradableProductsRelationsSchema,
|
|
13
13
|
getUpgradableProductsSchema
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-27UC2HEP.js";
|
|
15
15
|
import {
|
|
16
16
|
getRolePermissionsRelationsSchema,
|
|
17
17
|
getRolePermissionsSchema
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-QQA7STVO.js";
|
|
19
19
|
import {
|
|
20
20
|
getSessionRelationsSchema,
|
|
21
21
|
getSessionsSchema
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-EFVZ7IN4.js";
|
|
23
23
|
import {
|
|
24
24
|
getVerificationTokensSchema
|
|
25
25
|
} from "./chunk-LERR6HQ3.js";
|
|
26
26
|
import {
|
|
27
27
|
getDeviceAccessTokenRelationsSchema,
|
|
28
28
|
getDeviceAccessTokenSchema
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-6SLQW6OM.js";
|
|
30
30
|
import {
|
|
31
31
|
getDeviceVerificationRelationsSchema,
|
|
32
32
|
getDeviceVerificationSchema
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-YMFPIZMO.js";
|
|
34
34
|
import {
|
|
35
35
|
getAccountsRelationsSchema,
|
|
36
36
|
getAccountsSchema,
|
|
@@ -46,6 +46,10 @@ import {
|
|
|
46
46
|
getContentResourceResourceRelationsSchema,
|
|
47
47
|
getContentResourceResourceSchema,
|
|
48
48
|
getContentResourceSchema,
|
|
49
|
+
getContentResourceTagRelationsSchema,
|
|
50
|
+
getContentResourceTagSchema,
|
|
51
|
+
getContentResourceVersionRelationsSchema,
|
|
52
|
+
getContentResourceVersionSchema,
|
|
49
53
|
getCouponRelationsSchema,
|
|
50
54
|
getCouponSchema,
|
|
51
55
|
getPriceSchema,
|
|
@@ -55,6 +59,10 @@ import {
|
|
|
55
59
|
getPurchaseSchema,
|
|
56
60
|
getRolesRelationsSchema,
|
|
57
61
|
getRolesSchema,
|
|
62
|
+
getTagRelationsSchema,
|
|
63
|
+
getTagSchema,
|
|
64
|
+
getTagTagRelationsSchema,
|
|
65
|
+
getTagTagSchema,
|
|
58
66
|
getUserPermissionsRelationsSchema,
|
|
59
67
|
getUserPermissionsSchema,
|
|
60
68
|
getUserPrefsRelationsSchema,
|
|
@@ -63,7 +71,7 @@ import {
|
|
|
63
71
|
getUserRolesSchema,
|
|
64
72
|
getUsersRelationsSchema,
|
|
65
73
|
getUsersSchema
|
|
66
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-JW2PFVLO.js";
|
|
67
75
|
import {
|
|
68
76
|
getContributionTypesRelationsSchema,
|
|
69
77
|
getContributionTypesSchema
|
|
@@ -105,9 +113,11 @@ import {
|
|
|
105
113
|
} from "./chunk-H736K5TN.js";
|
|
106
114
|
|
|
107
115
|
// src/lib/mysql/index.ts
|
|
116
|
+
import slugify from "@sindresorhus/slugify";
|
|
108
117
|
import { addSeconds, isAfter } from "date-fns";
|
|
109
|
-
import { and, asc, desc, eq, gte, inArray,
|
|
118
|
+
import { and, asc, desc, eq, gte, inArray, isNull, not, or, sql } from "drizzle-orm";
|
|
110
119
|
import { mysqlTable as defaultMySqlTableFn } from "drizzle-orm/mysql-core";
|
|
120
|
+
import { customAlphabet } from "nanoid";
|
|
111
121
|
import { v4 } from "uuid";
|
|
112
122
|
|
|
113
123
|
// ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
|
@@ -8123,6 +8133,29 @@ var z2 = /* @__PURE__ */ Object.freeze({
|
|
|
8123
8133
|
ZodError: ZodError2
|
|
8124
8134
|
});
|
|
8125
8135
|
|
|
8136
|
+
// ../core/dist/chunk-CMH4QQ3R.js
|
|
8137
|
+
var VideoResourceSchema = z2.object({
|
|
8138
|
+
id: z2.string(),
|
|
8139
|
+
updatedAt: z2.coerce.date().optional(),
|
|
8140
|
+
createdAt: z2.coerce.date().optional(),
|
|
8141
|
+
title: z2.string().optional().nullable(),
|
|
8142
|
+
duration: z2.number().optional().nullable(),
|
|
8143
|
+
muxPlaybackId: z2.string().optional().nullable(),
|
|
8144
|
+
muxAssetId: z2.string().optional().nullable(),
|
|
8145
|
+
transcript: z2.string().optional().nullable(),
|
|
8146
|
+
transcriptWithScreenshots: z2.string().optional().nullable(),
|
|
8147
|
+
srt: z2.string().optional().nullable(),
|
|
8148
|
+
wordLevelSrt: z2.string().optional().nullable(),
|
|
8149
|
+
state: z2.enum([
|
|
8150
|
+
"new",
|
|
8151
|
+
"processing",
|
|
8152
|
+
"preparing",
|
|
8153
|
+
"ready",
|
|
8154
|
+
"errored",
|
|
8155
|
+
"deleted"
|
|
8156
|
+
])
|
|
8157
|
+
});
|
|
8158
|
+
|
|
8126
8159
|
// ../core/dist/chunk-CHYUPSYW.js
|
|
8127
8160
|
var userSchema = z2.object({
|
|
8128
8161
|
id: z2.string().max(255),
|
|
@@ -8157,25 +8190,26 @@ var priceSchema = z2.object({
|
|
|
8157
8190
|
fields: z2.record(z2.any()).default({})
|
|
8158
8191
|
});
|
|
8159
8192
|
|
|
8160
|
-
// ../core/dist/chunk-
|
|
8193
|
+
// ../core/dist/chunk-6BXXN6IV.js
|
|
8161
8194
|
var ContentResourceResourceSchema = z2.object({
|
|
8162
8195
|
resourceId: z2.string(),
|
|
8163
8196
|
resourceOfId: z2.string(),
|
|
8164
8197
|
position: z2.number().default(0),
|
|
8165
8198
|
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8166
|
-
createdAt: z2.date().nullable(),
|
|
8167
|
-
updatedAt: z2.date().nullable(),
|
|
8168
|
-
deletedAt: z2.date().nullable(),
|
|
8199
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8200
|
+
updatedAt: z2.coerce.date().nullable(),
|
|
8201
|
+
deletedAt: z2.coerce.date().nullable(),
|
|
8169
8202
|
resource: z2.any()
|
|
8170
8203
|
});
|
|
8171
8204
|
var ContentResourceSchema = z2.object({
|
|
8172
8205
|
id: z2.string(),
|
|
8173
8206
|
type: z2.string(),
|
|
8174
8207
|
createdById: z2.string(),
|
|
8208
|
+
currentVersionId: z2.string().nullish(),
|
|
8175
8209
|
fields: z2.record(z2.string(), z2.any()).default({}).nullable().optional(),
|
|
8176
|
-
createdAt: z2.date().nullable(),
|
|
8177
|
-
updatedAt: z2.date().nullable(),
|
|
8178
|
-
deletedAt: z2.date().nullable(),
|
|
8210
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8211
|
+
updatedAt: z2.coerce.date().nullable(),
|
|
8212
|
+
deletedAt: z2.coerce.date().nullable(),
|
|
8179
8213
|
resources: z2.array(ContentResourceResourceSchema).default([]).nullable()
|
|
8180
8214
|
});
|
|
8181
8215
|
var ContentResourceProductSchema = z2.object({
|
|
@@ -8183,9 +8217,9 @@ var ContentResourceProductSchema = z2.object({
|
|
|
8183
8217
|
productId: z2.string(),
|
|
8184
8218
|
position: z2.number().default(0),
|
|
8185
8219
|
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8186
|
-
createdAt: z2.date().nullable(),
|
|
8187
|
-
updatedAt: z2.date().nullable(),
|
|
8188
|
-
deletedAt: z2.date().nullable(),
|
|
8220
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8221
|
+
updatedAt: z2.coerce.date().nullable(),
|
|
8222
|
+
deletedAt: z2.coerce.date().nullable(),
|
|
8189
8223
|
resource: z2.any(),
|
|
8190
8224
|
product: z2.any()
|
|
8191
8225
|
});
|
|
@@ -8201,7 +8235,7 @@ var ResourceVisibilitySchema = z2.union([
|
|
|
8201
8235
|
z2.literal("unlisted")
|
|
8202
8236
|
]);
|
|
8203
8237
|
|
|
8204
|
-
// ../core/dist/chunk-
|
|
8238
|
+
// ../core/dist/chunk-LVVTCZ7P.js
|
|
8205
8239
|
var productSchema = z2.object({
|
|
8206
8240
|
id: z2.string().max(191),
|
|
8207
8241
|
name: z2.string().max(191),
|
|
@@ -8212,10 +8246,10 @@ var productSchema = z2.object({
|
|
|
8212
8246
|
]).default("self-paced"),
|
|
8213
8247
|
fields: z2.object({
|
|
8214
8248
|
body: z2.string().nullable().optional(),
|
|
8215
|
-
description: z2.string().
|
|
8249
|
+
description: z2.string().nullish(),
|
|
8216
8250
|
slug: z2.string(),
|
|
8217
8251
|
image: z2.object({
|
|
8218
|
-
url: z2.string()
|
|
8252
|
+
url: z2.string(),
|
|
8219
8253
|
alt: z2.string().optional().nullable(),
|
|
8220
8254
|
width: z2.number().optional().nullable(),
|
|
8221
8255
|
height: z2.number().optional().nullable()
|
|
@@ -8233,14 +8267,19 @@ var productSchema = z2.object({
|
|
|
8233
8267
|
"unlisted"
|
|
8234
8268
|
]).default("unlisted")
|
|
8235
8269
|
}),
|
|
8236
|
-
createdAt: z2.date().nullable(),
|
|
8270
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8237
8271
|
status: z2.number().int().default(0),
|
|
8238
8272
|
quantityAvailable: z2.number().int().default(-1),
|
|
8239
8273
|
price: priceSchema.nullable().optional(),
|
|
8240
8274
|
resources: z2.array(ContentResourceProductSchema).default([]).nullable()
|
|
8241
8275
|
});
|
|
8276
|
+
var NewProductSchema = z2.object({
|
|
8277
|
+
name: z2.string().min(2).max(90),
|
|
8278
|
+
quantityAvailable: z2.coerce.number().default(-1),
|
|
8279
|
+
price: z2.coerce.number().gte(0).default(0)
|
|
8280
|
+
});
|
|
8242
8281
|
|
|
8243
|
-
// ../core/dist/chunk-
|
|
8282
|
+
// ../core/dist/chunk-RCFZC3SN.js
|
|
8244
8283
|
var couponSchema = z2.object({
|
|
8245
8284
|
id: z2.string(),
|
|
8246
8285
|
code: z2.string().max(191).optional().nullable(),
|
|
@@ -8257,11 +8296,12 @@ var couponSchema = z2.object({
|
|
|
8257
8296
|
return decimalPlaces <= 2;
|
|
8258
8297
|
}),
|
|
8259
8298
|
restrictedToProductId: z2.string().max(191).optional().nullable(),
|
|
8260
|
-
|
|
8261
|
-
|
|
8299
|
+
bulkPurchases: z2.array(z2.any()).default([]),
|
|
8300
|
+
redeemedBulkCouponPurchases: z2.array(z2.any()).default([]),
|
|
8301
|
+
bulkPurchaseId: z2.string().max(191).optional().nullable()
|
|
8262
8302
|
});
|
|
8263
8303
|
|
|
8264
|
-
// ../core/dist/chunk-
|
|
8304
|
+
// ../core/dist/chunk-ACXDXYNY.js
|
|
8265
8305
|
var purchaseSchema = z2.object({
|
|
8266
8306
|
id: z2.string().max(191),
|
|
8267
8307
|
userId: z2.string().max(191).optional().nullable(),
|
|
@@ -8310,18 +8350,15 @@ var purchaseUserTransferSchema = z2.object({
|
|
|
8310
8350
|
completedAt: z2.date().nullable()
|
|
8311
8351
|
});
|
|
8312
8352
|
|
|
8313
|
-
// ../core/dist/chunk-
|
|
8353
|
+
// ../core/dist/chunk-6BTTEQD2.js
|
|
8314
8354
|
var resourceProgressSchema = z2.object({
|
|
8315
8355
|
userId: z2.string().max(191),
|
|
8316
8356
|
resourceId: z2.string().max(191).optional().nullable(),
|
|
8317
|
-
|
|
8318
|
-
completedAt: z2.date().nullable(),
|
|
8319
|
-
updatedAt: z2.date().nullable(),
|
|
8320
|
-
createdAt: z2.date().nullable()
|
|
8357
|
+
completedAt: z2.date().nullable()
|
|
8321
8358
|
});
|
|
8322
8359
|
var moduleProgressSchema = z2.object({
|
|
8323
8360
|
completedLessons: z2.array(resourceProgressSchema),
|
|
8324
|
-
nextResource: ContentResourceSchema.nullable(),
|
|
8361
|
+
nextResource: ContentResourceSchema.partial().nullable(),
|
|
8325
8362
|
percentCompleted: z2.number().default(0),
|
|
8326
8363
|
completedLessonsCount: z2.number().default(0),
|
|
8327
8364
|
totalLessonsCount: z2.number().default(0)
|
|
@@ -8338,29 +8375,6 @@ var upgradableProductSchema = z2.object({
|
|
|
8338
8375
|
deletedAt: z2.date().nullable()
|
|
8339
8376
|
});
|
|
8340
8377
|
|
|
8341
|
-
// ../core/dist/chunk-5QZXOTEH.js
|
|
8342
|
-
var VideoResourceSchema = z2.object({
|
|
8343
|
-
id: z2.string(),
|
|
8344
|
-
updatedAt: z2.string().optional(),
|
|
8345
|
-
createdAt: z2.string().optional(),
|
|
8346
|
-
title: z2.string().optional().nullable(),
|
|
8347
|
-
duration: z2.number().optional().nullable(),
|
|
8348
|
-
muxPlaybackId: z2.string().optional().nullable(),
|
|
8349
|
-
muxAssetId: z2.string().optional().nullable(),
|
|
8350
|
-
transcript: z2.string().optional().nullable(),
|
|
8351
|
-
transcriptWithScreenshots: z2.string().optional().nullable(),
|
|
8352
|
-
srt: z2.string().optional().nullable(),
|
|
8353
|
-
wordLevelSrt: z2.string().optional().nullable(),
|
|
8354
|
-
state: z2.enum([
|
|
8355
|
-
"new",
|
|
8356
|
-
"processing",
|
|
8357
|
-
"preparing",
|
|
8358
|
-
"ready",
|
|
8359
|
-
"errored",
|
|
8360
|
-
"deleted"
|
|
8361
|
-
])
|
|
8362
|
-
});
|
|
8363
|
-
|
|
8364
8378
|
// ../core/dist/chunk-EDDT2FFU.js
|
|
8365
8379
|
var merchantCustomerSchema = z2.object({
|
|
8366
8380
|
id: z2.string().max(191),
|
|
@@ -8556,6 +8570,7 @@ var validateCoupon = /* @__PURE__ */ __name2((coupon, productIds = []) => {
|
|
|
8556
8570
|
}, "validateCoupon");
|
|
8557
8571
|
|
|
8558
8572
|
// src/lib/mysql/index.ts
|
|
8573
|
+
var guid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", 5);
|
|
8559
8574
|
function getCourseBuilderSchema(mysqlTable) {
|
|
8560
8575
|
return {
|
|
8561
8576
|
accounts: getAccountsSchema(mysqlTable),
|
|
@@ -8599,9 +8614,13 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8599
8614
|
contentContributions: getContentContributionsSchema(mysqlTable),
|
|
8600
8615
|
contentContributionRelations: getContentContributionRelationsSchema(mysqlTable),
|
|
8601
8616
|
contentResource: getContentResourceSchema(mysqlTable),
|
|
8617
|
+
contentResourceVersion: getContentResourceVersionSchema(mysqlTable),
|
|
8618
|
+
contentResourceVersionRelations: getContentResourceVersionRelationsSchema(mysqlTable),
|
|
8602
8619
|
contentResourceRelations: getContentResourceRelationsSchema(mysqlTable),
|
|
8603
8620
|
contentResourceResource: getContentResourceResourceSchema(mysqlTable),
|
|
8604
8621
|
contentResourceResourceRelations: getContentResourceResourceRelationsSchema(mysqlTable),
|
|
8622
|
+
contentResourceTag: getContentResourceTagSchema(mysqlTable),
|
|
8623
|
+
contentResourceTagRelations: getContentResourceTagRelationsSchema(mysqlTable),
|
|
8605
8624
|
contributionTypes: getContributionTypesSchema(mysqlTable),
|
|
8606
8625
|
contributionTypesRelations: getContributionTypesRelationsSchema(mysqlTable),
|
|
8607
8626
|
resourceProgress: getResourceProgressSchema(mysqlTable),
|
|
@@ -8616,6 +8635,10 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8616
8635
|
deviceVerificationRelations: getDeviceVerificationRelationsSchema(mysqlTable),
|
|
8617
8636
|
deviceAccessToken: getDeviceAccessTokenSchema(mysqlTable),
|
|
8618
8637
|
deviceAccessTokenRelations: getDeviceAccessTokenRelationsSchema(mysqlTable),
|
|
8638
|
+
tag: getTagSchema(mysqlTable),
|
|
8639
|
+
tagRelations: getTagRelationsSchema(mysqlTable),
|
|
8640
|
+
tagTag: getTagTagSchema(mysqlTable),
|
|
8641
|
+
tagTagRelations: getTagTagRelationsSchema(mysqlTable),
|
|
8619
8642
|
userPrefs: getUserPrefsSchema(mysqlTable),
|
|
8620
8643
|
userPrefsRelations: getUserPrefsRelationsSchema(mysqlTable)
|
|
8621
8644
|
};
|
|
@@ -8625,8 +8648,8 @@ function createTables(mySqlTable) {
|
|
|
8625
8648
|
return getCourseBuilderSchema(mySqlTable);
|
|
8626
8649
|
}
|
|
8627
8650
|
__name(createTables, "createTables");
|
|
8628
|
-
function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
8629
|
-
const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress, comments } = createTables(tableFn);
|
|
8651
|
+
function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvider) {
|
|
8652
|
+
const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, contentResourceProduct, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress, comments } = createTables(tableFn);
|
|
8630
8653
|
const adapter = {
|
|
8631
8654
|
client,
|
|
8632
8655
|
async redeemFullPriceCoupon(options) {
|
|
@@ -8638,7 +8661,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8638
8661
|
throw new Error(`unable-to-find-any-product-id`);
|
|
8639
8662
|
const couponValidation = validateCoupon(coupon2, productIds);
|
|
8640
8663
|
if (coupon2 && couponValidation.isRedeemable) {
|
|
8641
|
-
const bulkCouponRedemption = Boolean(coupon2.
|
|
8664
|
+
const bulkCouponRedemption = Boolean(coupon2.maxUses > 1);
|
|
8642
8665
|
const { user } = await adapter.findOrCreateUser(email);
|
|
8643
8666
|
if (!user)
|
|
8644
8667
|
throw new Error(`unable-to-create-user-${email}`);
|
|
@@ -8648,8 +8671,18 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8648
8671
|
userId: user.id,
|
|
8649
8672
|
productId
|
|
8650
8673
|
});
|
|
8651
|
-
if (existingPurchases.length > 0)
|
|
8652
|
-
|
|
8674
|
+
if (existingPurchases.length > 0) {
|
|
8675
|
+
const errorMessage = `already-purchased-${email}`;
|
|
8676
|
+
console.error(errorMessage);
|
|
8677
|
+
return {
|
|
8678
|
+
error: {
|
|
8679
|
+
message: errorMessage
|
|
8680
|
+
},
|
|
8681
|
+
redeemingForCurrentUser,
|
|
8682
|
+
purchase: null
|
|
8683
|
+
};
|
|
8684
|
+
throw new Error(errorMessage);
|
|
8685
|
+
}
|
|
8653
8686
|
const purchaseId = `purchase-${v4()}`;
|
|
8654
8687
|
await adapter.createPurchase({
|
|
8655
8688
|
id: purchaseId,
|
|
@@ -8715,7 +8748,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8715
8748
|
},
|
|
8716
8749
|
getMerchantPriceForProductId: async (productId) => {
|
|
8717
8750
|
const merchantPriceData = await client.query.merchantPrice.findFirst({
|
|
8718
|
-
where: eq(merchantPrice.merchantProductId, productId)
|
|
8751
|
+
where: and(eq(merchantPrice.merchantProductId, productId), eq(merchantPrice.status, 1))
|
|
8719
8752
|
});
|
|
8720
8753
|
const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
|
|
8721
8754
|
if (!parsedMerchantPrice.success) {
|
|
@@ -8749,7 +8782,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8749
8782
|
async availableUpgradesForProduct(purchases, productId) {
|
|
8750
8783
|
const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
|
|
8751
8784
|
if (previousPurchaseProductIds.length > 0) {
|
|
8752
|
-
return
|
|
8785
|
+
return client.query.upgradableProducts.findMany({
|
|
8753
8786
|
where: and(eq(upgradableProducts.upgradableToId, productId), inArray(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
|
|
8754
8787
|
});
|
|
8755
8788
|
}
|
|
@@ -8971,18 +9004,31 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8971
9004
|
couponId
|
|
8972
9005
|
});
|
|
8973
9006
|
let couponData;
|
|
9007
|
+
let bulkCouponPurchases;
|
|
8974
9008
|
try {
|
|
8975
9009
|
couponData = await client.query.coupon.findFirst({
|
|
8976
9010
|
where: eq(coupon.id, couponId),
|
|
8977
9011
|
with: {
|
|
8978
|
-
|
|
8979
|
-
|
|
9012
|
+
bulkPurchases: true,
|
|
9013
|
+
redeemedBulkCouponPurchases: true
|
|
8980
9014
|
}
|
|
8981
9015
|
}) || null;
|
|
8982
9016
|
} catch (e) {
|
|
8983
9017
|
console.log("getCouponWithBulkPurchases");
|
|
8984
9018
|
logger.error(e);
|
|
8985
9019
|
}
|
|
9020
|
+
try {
|
|
9021
|
+
bulkCouponPurchases = await client.query.purchases.findMany({
|
|
9022
|
+
where: eq(purchaseTable.redeemedBulkCouponId, couponId),
|
|
9023
|
+
with: {
|
|
9024
|
+
user: true
|
|
9025
|
+
}
|
|
9026
|
+
});
|
|
9027
|
+
console.log("purchases with redeemedBulkCouponId", bulkCouponPurchases);
|
|
9028
|
+
} catch (e) {
|
|
9029
|
+
console.log("getCouponWithBulkPurchases");
|
|
9030
|
+
logger.error(e);
|
|
9031
|
+
}
|
|
8986
9032
|
if (!couponData) {
|
|
8987
9033
|
logger.debug("getCouponWithBulkPurchases", {
|
|
8988
9034
|
couponId,
|
|
@@ -8990,12 +9036,15 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8990
9036
|
});
|
|
8991
9037
|
return null;
|
|
8992
9038
|
}
|
|
9039
|
+
const couponWithBulkPurchases = {
|
|
9040
|
+
...couponData,
|
|
9041
|
+
redeemedBulkCouponPurchases: bulkCouponPurchases || []
|
|
9042
|
+
};
|
|
8993
9043
|
const parsedCoupon = couponSchema.merge(z.object({
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
})).nullable().safeParse(couponData);
|
|
9044
|
+
redeemedBulkCouponPurchases: z.array(purchaseSchema)
|
|
9045
|
+
})).nullable().safeParse(couponWithBulkPurchases);
|
|
8997
9046
|
if (!parsedCoupon.success) {
|
|
8998
|
-
console.error("Error parsing coupon", couponData);
|
|
9047
|
+
console.error("Error parsing coupon", JSON.stringify(parsedCoupon.error), couponData);
|
|
8999
9048
|
return null;
|
|
9000
9049
|
}
|
|
9001
9050
|
return parsedCoupon.data;
|
|
@@ -9037,109 +9086,65 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9037
9086
|
return parsed.data;
|
|
9038
9087
|
},
|
|
9039
9088
|
async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
|
|
9040
|
-
const ALLOWED_MODULE_RESOURCE_TYPES = [
|
|
9041
|
-
"lesson",
|
|
9042
|
-
"exercise",
|
|
9043
|
-
"solution"
|
|
9044
|
-
];
|
|
9045
|
-
const COUNTABLE_MODULE_RESOURCE_TYPES = [
|
|
9046
|
-
"lesson",
|
|
9047
|
-
"exercise"
|
|
9048
|
-
];
|
|
9049
|
-
const module = await client.query.contentResource.findFirst({
|
|
9050
|
-
where: or(eq(contentResource.id, moduleIdOrSlug), eq(sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, moduleIdOrSlug)),
|
|
9051
|
-
with: {
|
|
9052
|
-
resources: {
|
|
9053
|
-
with: {
|
|
9054
|
-
resource: {
|
|
9055
|
-
with: {
|
|
9056
|
-
resources: {
|
|
9057
|
-
with: {
|
|
9058
|
-
resource: {
|
|
9059
|
-
with: {
|
|
9060
|
-
resources: {
|
|
9061
|
-
with: {
|
|
9062
|
-
resource: true
|
|
9063
|
-
}
|
|
9064
|
-
}
|
|
9065
|
-
}
|
|
9066
|
-
}
|
|
9067
|
-
},
|
|
9068
|
-
orderBy: asc(contentResourceResource.position)
|
|
9069
|
-
}
|
|
9070
|
-
}
|
|
9071
|
-
}
|
|
9072
|
-
},
|
|
9073
|
-
orderBy: asc(contentResourceResource.position)
|
|
9074
|
-
}
|
|
9075
|
-
}
|
|
9076
|
-
});
|
|
9077
|
-
const parsedModule = ContentResourceSchema.parse(module);
|
|
9078
|
-
function flattenResources(resources) {
|
|
9079
|
-
const result = [];
|
|
9080
|
-
function recurse(resources2) {
|
|
9081
|
-
for (const nestedResource of resources2) {
|
|
9082
|
-
const resource = nestedResource.resource;
|
|
9083
|
-
result.push(resource);
|
|
9084
|
-
if (resource.resources) {
|
|
9085
|
-
recurse(resource.resources);
|
|
9086
|
-
}
|
|
9087
|
-
}
|
|
9088
|
-
}
|
|
9089
|
-
__name(recurse, "recurse");
|
|
9090
|
-
recurse(resources);
|
|
9091
|
-
return result;
|
|
9092
|
-
}
|
|
9093
|
-
__name(flattenResources, "flattenResources");
|
|
9094
|
-
const allResources = parsedModule?.resources && flattenResources(parsedModule.resources);
|
|
9095
|
-
const filteredResources = allResources?.filter((resource) => {
|
|
9096
|
-
return ALLOWED_MODULE_RESOURCE_TYPES.includes(resource.type);
|
|
9097
|
-
});
|
|
9098
|
-
const parsedResources = z.array(ContentResourceSchema).safeParse(filteredResources);
|
|
9099
|
-
if (!parsedResources.success) {
|
|
9100
|
-
console.error("Error parsing module resources", parsedResources.error);
|
|
9101
|
-
return {
|
|
9102
|
-
completedLessons: [],
|
|
9103
|
-
nextResource: null,
|
|
9104
|
-
percentCompleted: 0,
|
|
9105
|
-
completedLessonsCount: 0,
|
|
9106
|
-
totalLessonsCount: 0
|
|
9107
|
-
};
|
|
9108
|
-
}
|
|
9109
|
-
const progressResources = parsedResources.data.filter((r) => {
|
|
9110
|
-
return COUNTABLE_MODULE_RESOURCE_TYPES.includes(r.type);
|
|
9111
|
-
});
|
|
9112
|
-
const totalLessonsCount = progressResources.length;
|
|
9113
9089
|
const user = await client.query.users.findFirst({
|
|
9114
9090
|
where: or(eq(users.id, userIdOrEmail), eq(users.email, userIdOrEmail)),
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
with: {
|
|
9118
|
-
role: true
|
|
9119
|
-
}
|
|
9120
|
-
}
|
|
9121
|
-
}
|
|
9122
|
-
}).then(async (res) => {
|
|
9123
|
-
if (res) {
|
|
9124
|
-
return {
|
|
9125
|
-
...res,
|
|
9126
|
-
roles: res.roles.map((r) => r.role)
|
|
9127
|
-
};
|
|
9091
|
+
columns: {
|
|
9092
|
+
id: true
|
|
9128
9093
|
}
|
|
9129
9094
|
});
|
|
9130
9095
|
if (!user) {
|
|
9131
|
-
|
|
9132
|
-
return {
|
|
9133
|
-
completedLessons: [],
|
|
9134
|
-
nextResource: null,
|
|
9135
|
-
percentCompleted: 0,
|
|
9136
|
-
completedLessonsCount: 0,
|
|
9137
|
-
totalLessonsCount
|
|
9138
|
-
};
|
|
9096
|
+
return null;
|
|
9139
9097
|
}
|
|
9140
|
-
const
|
|
9141
|
-
|
|
9142
|
-
|
|
9098
|
+
const ResultRowSchema = z.object({
|
|
9099
|
+
resource_id: z.string(),
|
|
9100
|
+
resource_type: z.enum([
|
|
9101
|
+
"lesson",
|
|
9102
|
+
"exercise"
|
|
9103
|
+
]),
|
|
9104
|
+
resource_slug: z.string().nullable(),
|
|
9105
|
+
completed_at: z.string().nullable().transform((val) => val ? new Date(val) : null)
|
|
9106
|
+
});
|
|
9107
|
+
const results = await client.execute(sql`
|
|
9108
|
+
SELECT
|
|
9109
|
+
cr.id AS resource_id,
|
|
9110
|
+
cr.type AS resource_type,
|
|
9111
|
+
cr.fields->>'$.slug' AS resource_slug,
|
|
9112
|
+
rp.completedAt AS completed_at
|
|
9113
|
+
FROM
|
|
9114
|
+
(SELECT id, fields->>'$.slug' AS slug
|
|
9115
|
+
FROM ${contentResource}
|
|
9116
|
+
WHERE id = ${moduleIdOrSlug}
|
|
9117
|
+
OR fields->>'$.slug' = ${moduleIdOrSlug}) AS w
|
|
9118
|
+
LEFT JOIN
|
|
9119
|
+
(SELECT
|
|
9120
|
+
crr.resourceOfId AS workshop_id,
|
|
9121
|
+
crr.resourceId,
|
|
9122
|
+
crr.position
|
|
9123
|
+
FROM ${contentResourceResource} crr) AS tlr ON w.id = tlr.workshop_id
|
|
9124
|
+
LEFT JOIN ${contentResource} sections ON sections.id = tlr.resourceId AND sections.type = 'section'
|
|
9125
|
+
LEFT JOIN
|
|
9126
|
+
(SELECT
|
|
9127
|
+
crr.resourceOfId AS section_id,
|
|
9128
|
+
crr.resourceId AS resource_id,
|
|
9129
|
+
crr.position AS position_in_section,
|
|
9130
|
+
section_crr.position AS section_position
|
|
9131
|
+
FROM ${contentResourceResource} crr
|
|
9132
|
+
JOIN ${contentResourceResource} section_crr ON crr.resourceOfId = section_crr.resourceId) AS sr
|
|
9133
|
+
ON sr.section_id = sections.id
|
|
9134
|
+
JOIN ${contentResource} cr ON cr.id = COALESCE(sr.resource_id, tlr.resourceId)
|
|
9135
|
+
LEFT JOIN ${resourceProgress} rp ON rp.resourceId = cr.id
|
|
9136
|
+
AND rp.userId = ${user.id}
|
|
9137
|
+
WHERE
|
|
9138
|
+
cr.type IN ('lesson', 'exercise')
|
|
9139
|
+
|
|
9140
|
+
`);
|
|
9141
|
+
const completedLessons = [];
|
|
9142
|
+
let nextResource = null;
|
|
9143
|
+
let completedLessonsCount = 0;
|
|
9144
|
+
let totalLessonsCount = results.rows.length;
|
|
9145
|
+
const parsedRows = z.array(ResultRowSchema).safeParse(results.rows);
|
|
9146
|
+
if (!parsedRows.success) {
|
|
9147
|
+
console.error("Error parsing rows", parsedRows.error);
|
|
9143
9148
|
return {
|
|
9144
9149
|
completedLessons: [],
|
|
9145
9150
|
nextResource: null,
|
|
@@ -9148,34 +9153,30 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9148
9153
|
totalLessonsCount
|
|
9149
9154
|
};
|
|
9150
9155
|
}
|
|
9151
|
-
const
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
percentCompleted: 0,
|
|
9169
|
-
completedLessonsCount: 0,
|
|
9170
|
-
totalLessonsCount
|
|
9171
|
-
};
|
|
9156
|
+
for (const row of parsedRows.data) {
|
|
9157
|
+
if (row.completed_at) {
|
|
9158
|
+
completedLessonsCount++;
|
|
9159
|
+
completedLessons.push({
|
|
9160
|
+
userId: user.id,
|
|
9161
|
+
resourceId: row.resource_id,
|
|
9162
|
+
completedAt: new Date(row.completed_at)
|
|
9163
|
+
});
|
|
9164
|
+
} else if (!nextResource) {
|
|
9165
|
+
nextResource = {
|
|
9166
|
+
id: row.resource_id,
|
|
9167
|
+
type: row.resource_type,
|
|
9168
|
+
fields: {
|
|
9169
|
+
slug: row.resource_slug
|
|
9170
|
+
}
|
|
9171
|
+
};
|
|
9172
|
+
}
|
|
9172
9173
|
}
|
|
9173
|
-
const percentCompleted = Math.
|
|
9174
|
+
const percentCompleted = totalLessonsCount > 0 ? Math.ceil(completedLessonsCount / totalLessonsCount * 100) : 0;
|
|
9174
9175
|
return {
|
|
9175
|
-
completedLessons
|
|
9176
|
-
nextResource
|
|
9176
|
+
completedLessons,
|
|
9177
|
+
nextResource,
|
|
9177
9178
|
percentCompleted,
|
|
9178
|
-
completedLessonsCount
|
|
9179
|
+
completedLessonsCount,
|
|
9179
9180
|
totalLessonsCount
|
|
9180
9181
|
};
|
|
9181
9182
|
},
|
|
@@ -9188,7 +9189,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9188
9189
|
});
|
|
9189
9190
|
const parsed = merchantChargeSchema.safeParse(mCharge);
|
|
9190
9191
|
if (!parsed.success) {
|
|
9191
|
-
console.
|
|
9192
|
+
console.info("Error parsing merchantCharge", mCharge);
|
|
9192
9193
|
return null;
|
|
9193
9194
|
}
|
|
9194
9195
|
return parsed.data;
|
|
@@ -9231,10 +9232,249 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9231
9232
|
where: eq(prices.productId, productId)
|
|
9232
9233
|
}));
|
|
9233
9234
|
},
|
|
9234
|
-
async
|
|
9235
|
-
|
|
9236
|
-
|
|
9235
|
+
async archiveProduct(productId) {
|
|
9236
|
+
if (!paymentProvider)
|
|
9237
|
+
throw new Error("Payment provider not found");
|
|
9238
|
+
const product = await adapter.getProduct(productId);
|
|
9239
|
+
if (!product) {
|
|
9240
|
+
throw new Error(`Product not found for id (${productId})`);
|
|
9241
|
+
}
|
|
9242
|
+
if (!product.price) {
|
|
9243
|
+
throw new Error(`Product has no price`);
|
|
9244
|
+
}
|
|
9245
|
+
await client.update(products).set({
|
|
9246
|
+
status: 0,
|
|
9247
|
+
name: `${product.name} (Archived)`
|
|
9248
|
+
}).where(eq(products.id, productId));
|
|
9249
|
+
await client.update(prices).set({
|
|
9250
|
+
status: 0,
|
|
9251
|
+
nickname: `${product.name} (Archived)`
|
|
9252
|
+
}).where(eq(prices.productId, productId));
|
|
9253
|
+
await client.update(merchantProduct).set({
|
|
9254
|
+
status: 0
|
|
9255
|
+
}).where(eq(merchantProduct.productId, productId));
|
|
9256
|
+
await client.update(merchantPrice).set({
|
|
9257
|
+
status: 0
|
|
9258
|
+
}).where(eq(merchantPrice.priceId, product.price.id));
|
|
9259
|
+
const currentMerchantProduct = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
9260
|
+
where: eq(merchantProduct.productId, productId)
|
|
9261
|
+
}));
|
|
9262
|
+
if (!currentMerchantProduct || !currentMerchantProduct.identifier) {
|
|
9263
|
+
throw new Error(`Merchant product not found for id (${productId})`);
|
|
9264
|
+
}
|
|
9265
|
+
await paymentProvider.updateProduct(currentMerchantProduct.identifier, {
|
|
9266
|
+
active: false
|
|
9267
|
+
});
|
|
9268
|
+
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
9269
|
+
where: and(eq(merchantPrice.priceId, product.price.id), eq(merchantPrice.status, 1))
|
|
9270
|
+
}));
|
|
9271
|
+
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
9272
|
+
throw new Error(`Merchant price not found for id (${productId})`);
|
|
9273
|
+
}
|
|
9274
|
+
await paymentProvider.updatePrice(currentMerchantPrice.identifier, {
|
|
9275
|
+
active: false
|
|
9276
|
+
});
|
|
9277
|
+
return adapter.getProduct(productId);
|
|
9278
|
+
},
|
|
9279
|
+
async updateProduct(input) {
|
|
9280
|
+
if (!paymentProvider)
|
|
9281
|
+
throw new Error("Payment provider not found");
|
|
9282
|
+
const currentProduct = await adapter.getProduct(input.id);
|
|
9283
|
+
if (!currentProduct) {
|
|
9284
|
+
throw new Error(`Product not found`);
|
|
9285
|
+
}
|
|
9286
|
+
if (!currentProduct.price) {
|
|
9287
|
+
throw new Error(`Product has no price`);
|
|
9288
|
+
}
|
|
9289
|
+
const merchantProduct2 = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
9290
|
+
where: (merchantProduct3, { eq: eq2 }) => eq2(merchantProduct3.productId, input.id)
|
|
9291
|
+
}));
|
|
9292
|
+
if (!merchantProduct2 || !merchantProduct2.identifier) {
|
|
9293
|
+
throw new Error(`Merchant product not found`);
|
|
9294
|
+
}
|
|
9295
|
+
const stripeProduct = await paymentProvider.getProduct(merchantProduct2.identifier);
|
|
9296
|
+
const priceChanged = currentProduct.price.unitAmount.toString() !== input.price?.unitAmount.toString();
|
|
9297
|
+
if (priceChanged) {
|
|
9298
|
+
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
9299
|
+
where: (merchantPrice2, { eq: eq2, and: and2 }) => and2(eq2(merchantPrice2.merchantProductId, merchantProduct2.id), eq2(merchantPrice2.status, 1))
|
|
9300
|
+
}));
|
|
9301
|
+
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
9302
|
+
throw new Error(`Merchant price not found`);
|
|
9303
|
+
}
|
|
9304
|
+
const currentStripePrice = await paymentProvider.getPrice(currentMerchantPrice.identifier);
|
|
9305
|
+
const newStripePrice = await paymentProvider.createPrice({
|
|
9306
|
+
product: stripeProduct.id,
|
|
9307
|
+
unit_amount: Math.floor(Number(input.price?.unitAmount || 0) * 100),
|
|
9308
|
+
currency: "usd",
|
|
9309
|
+
metadata: {
|
|
9310
|
+
slug: input.fields.slug
|
|
9311
|
+
},
|
|
9312
|
+
active: true
|
|
9313
|
+
});
|
|
9314
|
+
await paymentProvider.updateProduct(stripeProduct.id, {
|
|
9315
|
+
default_price: newStripePrice.id
|
|
9316
|
+
});
|
|
9317
|
+
const newMerchantPriceId = `mprice_${v4()}`;
|
|
9318
|
+
await client.insert(merchantPrice).values({
|
|
9319
|
+
id: newMerchantPriceId,
|
|
9320
|
+
merchantProductId: merchantProduct2.id,
|
|
9321
|
+
merchantAccountId: merchantProduct2.merchantAccountId,
|
|
9322
|
+
priceId: currentProduct.price.id,
|
|
9323
|
+
status: 1,
|
|
9324
|
+
identifier: newStripePrice.id
|
|
9325
|
+
});
|
|
9326
|
+
if (currentMerchantPrice) {
|
|
9327
|
+
await client.update(merchantPrice).set({
|
|
9328
|
+
status: 0
|
|
9329
|
+
}).where(eq(merchantPrice.id, currentMerchantPrice.id));
|
|
9330
|
+
}
|
|
9331
|
+
await client.update(prices).set({
|
|
9332
|
+
unitAmount: Math.floor(Number(input.price?.unitAmount || 0)).toString(),
|
|
9333
|
+
nickname: input.name
|
|
9334
|
+
}).where(eq(prices.id, currentProduct.price.id));
|
|
9335
|
+
if (currentStripePrice) {
|
|
9336
|
+
await paymentProvider.updatePrice(currentStripePrice.id, {
|
|
9337
|
+
active: false
|
|
9338
|
+
});
|
|
9339
|
+
}
|
|
9340
|
+
}
|
|
9341
|
+
await paymentProvider.updateProduct(stripeProduct.id, {
|
|
9342
|
+
name: input.name,
|
|
9343
|
+
active: true,
|
|
9344
|
+
images: input.fields.image?.url ? [
|
|
9345
|
+
input.fields.image.url
|
|
9346
|
+
] : void 0,
|
|
9347
|
+
description: input.fields.description || "",
|
|
9348
|
+
metadata: {
|
|
9349
|
+
slug: input.fields.slug
|
|
9350
|
+
}
|
|
9351
|
+
});
|
|
9352
|
+
const { image, ...fieldsNoImage } = input.fields;
|
|
9353
|
+
await client.update(products).set({
|
|
9354
|
+
name: input.name,
|
|
9355
|
+
quantityAvailable: input.quantityAvailable,
|
|
9356
|
+
status: 1,
|
|
9357
|
+
fields: {
|
|
9358
|
+
...fieldsNoImage,
|
|
9359
|
+
...image?.url && {
|
|
9360
|
+
image
|
|
9361
|
+
}
|
|
9362
|
+
}
|
|
9363
|
+
}).where(eq(products.id, currentProduct.id));
|
|
9364
|
+
return adapter.getProduct(currentProduct.id);
|
|
9365
|
+
},
|
|
9366
|
+
async createProduct(input) {
|
|
9367
|
+
if (!paymentProvider)
|
|
9368
|
+
throw new Error("Payment provider not found");
|
|
9369
|
+
const merchantAccount2 = merchantAccountSchema.nullish().parse(await client.query.merchantAccount.findFirst({
|
|
9370
|
+
where: (merchantAccount3, { eq: eq2 }) => eq2(merchantAccount3.label, "stripe")
|
|
9371
|
+
}));
|
|
9372
|
+
if (!merchantAccount2) {
|
|
9373
|
+
throw new Error("Merchant account not found");
|
|
9374
|
+
}
|
|
9375
|
+
const hash = guid();
|
|
9376
|
+
const newProductId = slugify(`product-${hash}`);
|
|
9377
|
+
const newProduct = {
|
|
9378
|
+
id: newProductId,
|
|
9379
|
+
name: input.name,
|
|
9380
|
+
status: 1,
|
|
9381
|
+
type: "self-paced",
|
|
9382
|
+
quantityAvailable: input.quantityAvailable,
|
|
9383
|
+
fields: {
|
|
9384
|
+
state: "draft",
|
|
9385
|
+
visibility: "unlisted",
|
|
9386
|
+
slug: slugify(`${input.name}-${hash}`)
|
|
9387
|
+
}
|
|
9388
|
+
};
|
|
9389
|
+
await client.insert(products).values(newProduct);
|
|
9390
|
+
const priceHash = guid();
|
|
9391
|
+
const newPriceId = `price-${priceHash}`;
|
|
9392
|
+
await client.insert(prices).values({
|
|
9393
|
+
id: newPriceId,
|
|
9394
|
+
productId: newProductId,
|
|
9395
|
+
unitAmount: input.price.toString(),
|
|
9396
|
+
status: 1
|
|
9397
|
+
});
|
|
9398
|
+
const product = await adapter.getProduct(newProductId);
|
|
9399
|
+
const stripeProduct = await paymentProvider.createProduct({
|
|
9400
|
+
name: input.name,
|
|
9401
|
+
metadata: {
|
|
9402
|
+
slug: product?.fields?.slug || null
|
|
9403
|
+
}
|
|
9404
|
+
});
|
|
9405
|
+
const stripePrice = await paymentProvider.createPrice({
|
|
9406
|
+
product: stripeProduct.id,
|
|
9407
|
+
unit_amount: Math.floor(Number(input.price) * 100),
|
|
9408
|
+
currency: "usd",
|
|
9409
|
+
nickname: input.name,
|
|
9410
|
+
metadata: {
|
|
9411
|
+
slug: product?.fields?.slug || null
|
|
9412
|
+
}
|
|
9413
|
+
});
|
|
9414
|
+
const newMerchantProductId = `mproduct_${v4()}`;
|
|
9415
|
+
await client.insert(merchantProduct).values({
|
|
9416
|
+
id: newMerchantProductId,
|
|
9417
|
+
merchantAccountId: merchantAccount2.id,
|
|
9418
|
+
productId: newProductId,
|
|
9419
|
+
identifier: stripeProduct.id,
|
|
9420
|
+
status: 1
|
|
9421
|
+
});
|
|
9422
|
+
const newMerchantPriceId = `mprice_${v4()}`;
|
|
9423
|
+
await client.insert(merchantPrice).values({
|
|
9424
|
+
id: newMerchantPriceId,
|
|
9425
|
+
merchantAccountId: merchantAccount2.id,
|
|
9426
|
+
merchantProductId: newMerchantProductId,
|
|
9427
|
+
priceId: newPriceId,
|
|
9428
|
+
identifier: stripePrice.id,
|
|
9429
|
+
status: 1
|
|
9430
|
+
});
|
|
9431
|
+
return product;
|
|
9432
|
+
},
|
|
9433
|
+
async getProduct(productSlugOrId, withResources = true) {
|
|
9434
|
+
if (!productSlugOrId) {
|
|
9435
|
+
return null;
|
|
9436
|
+
}
|
|
9437
|
+
try {
|
|
9438
|
+
const productData = await client.query.products.findFirst({
|
|
9439
|
+
where: and(or(eq(sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), eq(products.id, productSlugOrId))),
|
|
9440
|
+
with: {
|
|
9441
|
+
price: true,
|
|
9442
|
+
...withResources && {
|
|
9443
|
+
resources: {
|
|
9444
|
+
with: {
|
|
9445
|
+
resource: {
|
|
9446
|
+
with: {
|
|
9447
|
+
resources: true
|
|
9448
|
+
}
|
|
9449
|
+
}
|
|
9450
|
+
}
|
|
9451
|
+
}
|
|
9452
|
+
}
|
|
9453
|
+
}
|
|
9454
|
+
});
|
|
9455
|
+
const parsedProduct = productSchema.safeParse(productData);
|
|
9456
|
+
if (!parsedProduct.success) {
|
|
9457
|
+
console.error("Error parsing product", JSON.stringify(parsedProduct.error), JSON.stringify(productData));
|
|
9458
|
+
return null;
|
|
9459
|
+
}
|
|
9460
|
+
return parsedProduct.data;
|
|
9461
|
+
} catch (e) {
|
|
9462
|
+
console.log("getProduct error", e);
|
|
9463
|
+
return null;
|
|
9464
|
+
}
|
|
9465
|
+
},
|
|
9466
|
+
async getProductResources(productId) {
|
|
9467
|
+
const contentResourceProductsForProduct = z.array(ContentResourceProductSchema).nullable().parse(await client.query.contentResourceProduct.findMany({
|
|
9468
|
+
where: eq(contentResourceProduct.productId, productId)
|
|
9237
9469
|
}));
|
|
9470
|
+
if (!contentResourceProductsForProduct) {
|
|
9471
|
+
return null;
|
|
9472
|
+
} else {
|
|
9473
|
+
const contentResources = z.array(ContentResourceSchema).parse(await client.query.contentResource.findMany({
|
|
9474
|
+
where: inArray(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
|
|
9475
|
+
}));
|
|
9476
|
+
return contentResources;
|
|
9477
|
+
}
|
|
9238
9478
|
},
|
|
9239
9479
|
async getPurchaseCountForProduct(productId) {
|
|
9240
9480
|
return await client.query.purchases.findMany({
|
|
@@ -9267,7 +9507,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9267
9507
|
where: eq(merchantCharge.identifier, stripeChargeId)
|
|
9268
9508
|
}) || null);
|
|
9269
9509
|
if (!chargeForPurchase) {
|
|
9270
|
-
logger.error(new Error(
|
|
9510
|
+
logger.error(new Error(`No charge found for purchase: Stripe Charge ID: ${stripeChargeId}`));
|
|
9271
9511
|
return null;
|
|
9272
9512
|
}
|
|
9273
9513
|
const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
@@ -9402,6 +9642,33 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9402
9642
|
purchase: parsedPurchase.data
|
|
9403
9643
|
};
|
|
9404
9644
|
},
|
|
9645
|
+
async getUserWithPurchasersByEmail(email) {
|
|
9646
|
+
const user = await client.query.users.findFirst({
|
|
9647
|
+
where: eq(users.email, email.trim().toLowerCase()),
|
|
9648
|
+
with: {
|
|
9649
|
+
// merchantCustomer: true,
|
|
9650
|
+
roles: {
|
|
9651
|
+
with: {
|
|
9652
|
+
role: true
|
|
9653
|
+
}
|
|
9654
|
+
},
|
|
9655
|
+
purchases: {
|
|
9656
|
+
with: {
|
|
9657
|
+
bulkCoupon: true,
|
|
9658
|
+
merchantCharge: true,
|
|
9659
|
+
product: {
|
|
9660
|
+
columns: {
|
|
9661
|
+
id: true,
|
|
9662
|
+
name: true,
|
|
9663
|
+
key: true
|
|
9664
|
+
}
|
|
9665
|
+
}
|
|
9666
|
+
}
|
|
9667
|
+
}
|
|
9668
|
+
}
|
|
9669
|
+
});
|
|
9670
|
+
return user;
|
|
9671
|
+
},
|
|
9405
9672
|
async getUserById(userId) {
|
|
9406
9673
|
const user = await client.query.users.findFirst({
|
|
9407
9674
|
where: eq(users.id, userId),
|
|
@@ -9475,11 +9742,102 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9475
9742
|
}
|
|
9476
9743
|
return parsedLessonProgress.data;
|
|
9477
9744
|
},
|
|
9745
|
+
transferPurchaseToUser: async (options) => {
|
|
9746
|
+
const { purchaseId, targetUserId, sourceUserId } = options;
|
|
9747
|
+
const transferId = `put_${v4()}`;
|
|
9748
|
+
let purchase = await adapter.getPurchase(purchaseId);
|
|
9749
|
+
if (!purchase)
|
|
9750
|
+
throw new Error("No purchase found");
|
|
9751
|
+
if (purchase.userId !== sourceUserId)
|
|
9752
|
+
throw new Error("Invalid source user");
|
|
9753
|
+
await client.transaction(async (trx) => {
|
|
9754
|
+
if (!purchase)
|
|
9755
|
+
throw new Error("No purchase found");
|
|
9756
|
+
await trx.update(purchaseTable).set({
|
|
9757
|
+
userId: targetUserId
|
|
9758
|
+
}).where(eq(purchaseTable.id, purchase.id));
|
|
9759
|
+
await trx.insert(purchaseUserTransfer).values({
|
|
9760
|
+
id: transferId,
|
|
9761
|
+
purchaseId: purchase.id,
|
|
9762
|
+
sourceUserId,
|
|
9763
|
+
targetUserId,
|
|
9764
|
+
transferState: "COMPLETED",
|
|
9765
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
9766
|
+
});
|
|
9767
|
+
purchase = await adapter.getPurchase(purchaseId);
|
|
9768
|
+
if (!purchase)
|
|
9769
|
+
throw new Error("No purchase found");
|
|
9770
|
+
if (paymentProvider && purchase.merchantChargeId) {
|
|
9771
|
+
await trx.update(merchantCharge).set({
|
|
9772
|
+
userId: targetUserId
|
|
9773
|
+
}).where(eq(merchantCharge.id, purchase.merchantChargeId));
|
|
9774
|
+
const updatedMerchantCharge = await adapter.getMerchantCharge(purchase.merchantChargeId);
|
|
9775
|
+
if (!updatedMerchantCharge)
|
|
9776
|
+
throw new Error("No merchant charge found");
|
|
9777
|
+
await trx.update(merchantCustomer).set({
|
|
9778
|
+
userId: targetUserId
|
|
9779
|
+
}).where(eq(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId));
|
|
9780
|
+
const updatedMerchantCustomer = merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
|
|
9781
|
+
where: eq(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId)
|
|
9782
|
+
}));
|
|
9783
|
+
const targetUser = userSchema.parse(await client.query.users.findFirst({
|
|
9784
|
+
where: eq(users.id, targetUserId)
|
|
9785
|
+
}));
|
|
9786
|
+
const sourceUser = userSchema.parse(await client.query.users.findFirst({
|
|
9787
|
+
where: eq(users.id, sourceUserId)
|
|
9788
|
+
}));
|
|
9789
|
+
await paymentProvider.updateCustomer(updatedMerchantCustomer.identifier, {
|
|
9790
|
+
email: targetUser.email,
|
|
9791
|
+
name: targetUser.name || sourceUser.name || "",
|
|
9792
|
+
metadata: {
|
|
9793
|
+
transferId,
|
|
9794
|
+
transferredFrom: sourceUser.email,
|
|
9795
|
+
transferredOn: (/* @__PURE__ */ new Date()).toISOString()
|
|
9796
|
+
}
|
|
9797
|
+
});
|
|
9798
|
+
}
|
|
9799
|
+
});
|
|
9800
|
+
return await adapter.getPurchaseUserTransferById({
|
|
9801
|
+
id: transferId
|
|
9802
|
+
});
|
|
9803
|
+
},
|
|
9478
9804
|
transferPurchasesToNewUser(options) {
|
|
9479
9805
|
throw new Error("Method not implemented.");
|
|
9480
9806
|
},
|
|
9481
|
-
updatePurchaseStatusForCharge(chargeId, status) {
|
|
9482
|
-
|
|
9807
|
+
async updatePurchaseStatusForCharge(chargeId, status) {
|
|
9808
|
+
try {
|
|
9809
|
+
console.log("updatePurchaseStatusForCharge", {
|
|
9810
|
+
chargeId,
|
|
9811
|
+
status
|
|
9812
|
+
});
|
|
9813
|
+
const merchantChargeForPurchase = await client.query.merchantCharge.findFirst({
|
|
9814
|
+
where: or(eq(merchantCharge.identifier, chargeId), eq(merchantCharge.id, chargeId))
|
|
9815
|
+
});
|
|
9816
|
+
console.log("merchantChargeForPurchase", {
|
|
9817
|
+
merchantChargeForPurchase
|
|
9818
|
+
});
|
|
9819
|
+
const parsedMerchantChargeForPurchase = merchantChargeSchema.parse(merchantChargeForPurchase);
|
|
9820
|
+
if (!parsedMerchantChargeForPurchase)
|
|
9821
|
+
throw new Error(`no-charge-found-for-purchase ${chargeId}`);
|
|
9822
|
+
const purchase = await client.query.purchases.findFirst({
|
|
9823
|
+
where: eq(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
|
|
9824
|
+
});
|
|
9825
|
+
const parsedPurchase = purchaseSchema.nullable().parse(purchase);
|
|
9826
|
+
if (parsedPurchase) {
|
|
9827
|
+
await client.update(purchaseTable).set({
|
|
9828
|
+
status
|
|
9829
|
+
}).where(eq(purchaseTable.id, parsedPurchase.id));
|
|
9830
|
+
const newPurchase = await client.query.purchases.findFirst({
|
|
9831
|
+
where: eq(purchaseTable.id, parsedPurchase.id)
|
|
9832
|
+
});
|
|
9833
|
+
return purchaseSchema.optional().parse(newPurchase);
|
|
9834
|
+
} else {
|
|
9835
|
+
throw new Error(`no-purchase-found-for-charge ${chargeId}`);
|
|
9836
|
+
}
|
|
9837
|
+
} catch (e) {
|
|
9838
|
+
console.log("error updating purchase status", e);
|
|
9839
|
+
throw e;
|
|
9840
|
+
}
|
|
9483
9841
|
},
|
|
9484
9842
|
async updatePurchaseUserTransferTransferState(options) {
|
|
9485
9843
|
await client.update(purchaseUserTransfer).set({
|
|
@@ -9516,6 +9874,18 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9516
9874
|
}
|
|
9517
9875
|
return parsedResourceJoin.data;
|
|
9518
9876
|
},
|
|
9877
|
+
async removeResourceFromResource(options) {
|
|
9878
|
+
const { childResourceId, parentResourceId } = options;
|
|
9879
|
+
const resourceJoin = await client.query.contentResourceResource.findFirst({
|
|
9880
|
+
where: and(eq(contentResourceResource.resourceOfId, parentResourceId), eq(contentResourceResource.resourceId, childResourceId))
|
|
9881
|
+
});
|
|
9882
|
+
const parsedResourceJoin = ContentResourceResourceSchema.safeParse(resourceJoin);
|
|
9883
|
+
if (!parsedResourceJoin.success) {
|
|
9884
|
+
return null;
|
|
9885
|
+
}
|
|
9886
|
+
await client.delete(contentResourceResource).where(and(eq(contentResourceResource.resourceOfId, parentResourceId), eq(contentResourceResource.resourceId, childResourceId)));
|
|
9887
|
+
return parsedResourceJoin.data.resource;
|
|
9888
|
+
},
|
|
9519
9889
|
async updateContentResourceFields(options) {
|
|
9520
9890
|
if (!options.id) {
|
|
9521
9891
|
throw new Error("No content resource id.");
|
|
@@ -9748,8 +10118,9 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9748
10118
|
__name(mySqlDrizzleAdapter, "mySqlDrizzleAdapter");
|
|
9749
10119
|
|
|
9750
10120
|
export {
|
|
10121
|
+
guid,
|
|
9751
10122
|
getCourseBuilderSchema,
|
|
9752
10123
|
createTables,
|
|
9753
10124
|
mySqlDrizzleAdapter
|
|
9754
10125
|
};
|
|
9755
|
-
//# sourceMappingURL=chunk-
|
|
10126
|
+
//# sourceMappingURL=chunk-ZYQYJNLK.js.map
|