@unchainedshop/core-enrollments 4.8.9 → 4.8.11

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.
@@ -1,4 +1,4 @@
1
- import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled } from '@unchainedshop/mongodb';
1
+ import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
2
2
  import {} from '@unchainedshop/mongodb';
3
3
  export const EnrollmentStatus = {
4
4
  INITIAL: 'INITIAL',
@@ -8,34 +8,33 @@ export const EnrollmentStatus = {
8
8
  };
9
9
  export const EnrollmentsCollection = async (db) => {
10
10
  const Enrollments = db.collection('enrollments');
11
- if (!isDocumentDBCompatModeEnabled()) {
12
- await buildDbIndexes(Enrollments, [
13
- {
14
- index: {
15
- _id: 'text',
16
- userId: 'text',
17
- enrollmentNumber: 'text',
18
- status: 'text',
19
- 'contact.telNumber': 'text',
20
- 'contact.emailAddress': 'text',
21
- },
22
- options: {
23
- weights: {
24
- _id: 8,
25
- userId: 3,
26
- enrollmentNumber: 6,
27
- 'contact.telNumber': 5,
28
- 'contact.emailAddress': 4,
29
- status: 1,
30
- },
31
- name: 'enrollment_fulltext_search',
11
+ await buildDbIndexes(Enrollments, [
12
+ {
13
+ index: {
14
+ _id: 'text',
15
+ userId: 'text',
16
+ enrollmentNumber: 'text',
17
+ status: 'text',
18
+ 'contact.telNumber': 'text',
19
+ 'contact.emailAddress': 'text',
20
+ },
21
+ options: {
22
+ weights: {
23
+ _id: 8,
24
+ userId: 3,
25
+ enrollmentNumber: 6,
26
+ 'contact.telNumber': 5,
27
+ 'contact.emailAddress': 4,
28
+ status: 1,
32
29
  },
30
+ name: 'enrollment_fulltext_search',
33
31
  },
34
- ]);
35
- }
32
+ },
33
+ ]);
36
34
  await buildDbIndexes(Enrollments, [
37
- { index: { userId: 1 } },
38
- { index: { productId: 1 } },
35
+ { index: { 'periods.orderId': 1 } },
36
+ { index: { userId: 1, status: 1 } },
37
+ { index: { productId: 1, status: 1 } },
39
38
  { index: { status: 1 } },
40
39
  { index: { enrollmentNumber: 1 } },
41
40
  ]);
@@ -18,6 +18,9 @@ export declare const configureEnrollmentsModule: ({ db, options: enrollmentOptio
18
18
  } | {
19
19
  orderId: string;
20
20
  }, options?: mongodb.FindOptions) => Promise<Enrollment | null>;
21
+ findEnrollmentsByOrderIds: ({ orderIds }: {
22
+ orderIds: string[];
23
+ }, options?: mongodb.FindOptions) => Promise<Enrollment[]>;
21
24
  findEnrollments: ({ limit, offset, sort, ...query }: EnrollmentQuery & {
22
25
  limit?: number;
23
26
  offset?: number;
@@ -1,7 +1,7 @@
1
1
  import { SortDirection } from '@unchainedshop/utils';
2
2
  import { EnrollmentStatus, } from "../db/EnrollmentsCollection.js";
3
3
  import { emit, registerEvents } from '@unchainedshop/events';
4
- import { generateDbFilterById, buildSortOptions, mongodb, generateDbObjectId, assertDocumentDBCompatMode, } from '@unchainedshop/mongodb';
4
+ import { generateDbFilterById, buildSortOptions, mongodb, generateDbObjectId, } from '@unchainedshop/mongodb';
5
5
  import { EnrollmentsCollection } from "../db/EnrollmentsCollection.js";
6
6
  import { enrollmentsSettings } from "../enrollments-settings.js";
7
7
  const ENROLLMENT_EVENTS = [
@@ -19,7 +19,6 @@ export const buildFindSelector = ({ queryString, status, userId }) => {
19
19
  if (userId)
20
20
  selector.userId = userId;
21
21
  if (queryString) {
22
- assertDocumentDBCompatMode();
23
22
  selector.$text = { $search: queryString };
24
23
  }
25
24
  return selector;
@@ -102,6 +101,11 @@ export const configureEnrollmentsModule = async ({ db, options: enrollmentOption
102
101
  }
103
102
  return Enrollments.findOne({ 'periods.orderId': params.orderId, deleted: null }, options);
104
103
  },
104
+ findEnrollmentsByOrderIds: async ({ orderIds }, options) => {
105
+ if (!orderIds?.length)
106
+ return [];
107
+ return Enrollments.find({ 'periods.orderId': { $in: orderIds }, deleted: null }, options).toArray();
108
+ },
105
109
  findEnrollments: async ({ limit, offset, sort, ...query }) => {
106
110
  const defaultSortOption = [{ key: 'created', value: SortDirection.ASC }];
107
111
  const enrollments = Enrollments.find(buildFindSelector(query), {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-enrollments",
3
3
  "description": "Subscription and recurring billing module for the Unchained Engine",
4
- "version": "4.8.9",
4
+ "version": "4.8.11",
5
5
  "main": "lib/enrollments-index.js",
6
6
  "types": "lib/enrollments-index.d.ts",
7
7
  "type": "module",