@coursebuilder/adapter-drizzle 1.0.2 → 1.0.4

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.
@@ -3,11 +3,11 @@ import {
3
3
  getCourseBuilderSchema,
4
4
  guid,
5
5
  mySqlDrizzleAdapter
6
- } from "../../chunk-5QEGBX2O.js";
7
- import "../../chunk-253RMSB3.js";
6
+ } from "../../chunk-ARHWIBFG.js";
8
7
  import "../../chunk-ET3QAIY7.js";
9
8
  import "../../chunk-6YPHJWS2.js";
10
9
  import "../../chunk-ORRM7KVW.js";
10
+ import "../../chunk-253RMSB3.js";
11
11
  import "../../chunk-HWIQUI7O.js";
12
12
  import "../../chunk-FPAQINSA.js";
13
13
  import "../../chunk-LERR6HQ3.js";
@@ -1,4 +1,4 @@
1
- import { MySqlDatabase, AnyMySqlTable, MySqlTableFn } from 'drizzle-orm/mysql-core';
1
+ import { MySqlDatabase, MySqlTableFn, AnyMySqlTable } from 'drizzle-orm/mysql-core';
2
2
  import { PgDatabase, PgTableFn } from 'drizzle-orm/pg-core';
3
3
  import { BaseSQLiteDatabase, SQLiteTableFn, AnySQLiteTable } from 'drizzle-orm/sqlite-core';
4
4
  import { DefaultSchema } from './mysql/index.cjs';
@@ -1,4 +1,4 @@
1
- import { MySqlDatabase, AnyMySqlTable, MySqlTableFn } from 'drizzle-orm/mysql-core';
1
+ import { MySqlDatabase, MySqlTableFn, AnyMySqlTable } from 'drizzle-orm/mysql-core';
2
2
  import { PgDatabase, PgTableFn } from 'drizzle-orm/pg-core';
3
3
  import { BaseSQLiteDatabase, SQLiteTableFn, AnySQLiteTable } from 'drizzle-orm/sqlite-core';
4
4
  import { DefaultSchema } from './mysql/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coursebuilder/adapter-drizzle",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Drizzle adapter for Course Builder.",
5
5
  "keywords": [
6
6
  "coursebuilder",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@auth/core": "0.37.2",
46
- "@coursebuilder/core": "1.0.2",
46
+ "@coursebuilder/core": "1.0.5",
47
47
  "@libsql/client": "0.5.6",
48
48
  "@types/better-sqlite3": "7.6.9",
49
49
  "@types/uuid": "9.0.8",
@@ -432,6 +432,11 @@ export function mySqlDrizzleAdapter(
432
432
  }
433
433
 
434
434
  const purchaseId = `purchase-${v4()}`
435
+ const userMemberships = await adapter.getMembershipsForUser(user.id)
436
+ const organizationId =
437
+ coupon.organizationId ||
438
+ userMemberships.find((m) => m.organization.name?.includes(user.email))
439
+ ?.organizationId // safer way to make sure we are using personal organization
435
440
 
436
441
  await adapter.createPurchase({
437
442
  id: purchaseId,
@@ -440,6 +445,7 @@ export function mySqlDrizzleAdapter(
440
445
  redeemedBulkCouponId: bulkCouponRedemption ? coupon.id : null,
441
446
  productId,
442
447
  totalAmount: '0',
448
+ organizationId,
443
449
  metadata: {
444
450
  couponUsedId: bulkCouponRedemption ? null : coupon.id,
445
451
  },
@@ -967,6 +973,7 @@ export function mySqlDrizzleAdapter(
967
973
  name,
968
974
  emailVerified: null,
969
975
  })
976
+ console.log('newUser', { newUser })
970
977
  if (!newUser) {
971
978
  throw new Error('Could not create user')
972
979
  }
@@ -994,6 +1001,18 @@ export function mySqlDrizzleAdapter(
994
1001
 
995
1002
  return couponSchema.nullable().parse(loadedCoupon)
996
1003
  },
1004
+ async getPurchasesForBulkCouponId(
1005
+ bulkCouponId: string,
1006
+ ): Promise<(Purchase & { user: User })[]> {
1007
+ return z.array(purchaseSchema.extend({ user: userSchema })).parse(
1008
+ await client.query.purchases.findMany({
1009
+ where: eq(purchaseTable.bulkCouponId, bulkCouponId),
1010
+ with: {
1011
+ user: true,
1012
+ },
1013
+ }),
1014
+ )
1015
+ },
997
1016
  async getCouponWithBulkPurchases(couponId: string): Promise<
998
1017
  | (Coupon & {
999
1018
  bulkPurchases?: Purchase[] | null
@@ -1543,11 +1562,11 @@ export function mySqlDrizzleAdapter(
1543
1562
  id: newProductId,
1544
1563
  name: input.name,
1545
1564
  status: 1,
1546
- type: 'self-paced',
1565
+ type: input.type || 'self-paced',
1547
1566
  quantityAvailable: input.quantityAvailable,
1548
1567
  fields: {
1549
- state: 'draft',
1550
- visibility: 'unlisted',
1568
+ state: input.state || 'draft',
1569
+ visibility: input.visibility || 'unlisted',
1551
1570
  slug: slugify(`${input.name}-${hash}`),
1552
1571
  },
1553
1572
  }
@@ -1772,6 +1791,7 @@ export function mySqlDrizzleAdapter(
1772
1791
  sourceUser: userSchema,
1773
1792
  targetUser: userSchema.nullable(),
1774
1793
  purchase: purchaseSchema,
1794
+ organizationId: z.string().nullable(),
1775
1795
  }),
1776
1796
  )
1777
1797
  .nullable()
@@ -2736,6 +2756,10 @@ export function mySqlDrizzleAdapter(
2736
2756
  ),
2737
2757
  eq(organizationMembershipTable.userId, options.userId),
2738
2758
  ),
2759
+ with: {
2760
+ organization: true,
2761
+ user: true,
2762
+ },
2739
2763
  })
2740
2764
 
2741
2765
  if (currentMembership) {