@unchainedshop/core-quotations 5.0.0-alpha.1 → 5.0.0-alpha.3

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
  export const QuotationStatus = {
3
3
  REQUESTED: 'REQUESTED',
4
4
  PROCESSING: 'PROCESSING',
@@ -8,30 +8,28 @@ export const QuotationStatus = {
8
8
  };
9
9
  export const QuotationsCollection = async (db) => {
10
10
  const Quotations = db.collection('quotations');
11
- if (!isDocumentDBCompatModeEnabled()) {
12
- await buildDbIndexes(Quotations, [
13
- {
14
- index: {
15
- _id: 'text',
16
- userId: 'text',
17
- quotationNumber: 'text',
18
- status: 'text',
19
- },
20
- options: {
21
- weights: {
22
- _id: 8,
23
- userId: 3,
24
- quotationNumber: 6,
25
- status: 1,
26
- },
27
- name: 'quotation_fulltext_search',
11
+ await buildDbIndexes(Quotations, [
12
+ {
13
+ index: {
14
+ _id: 'text',
15
+ userId: 'text',
16
+ quotationNumber: 'text',
17
+ status: 'text',
18
+ },
19
+ options: {
20
+ weights: {
21
+ _id: 8,
22
+ userId: 3,
23
+ quotationNumber: 6,
24
+ status: 1,
28
25
  },
26
+ name: 'quotation_fulltext_search',
29
27
  },
30
- ]);
31
- }
28
+ },
29
+ ]);
32
30
  await buildDbIndexes(Quotations, [
33
- { index: { userId: 1 } },
34
- { index: { productId: 1 } },
31
+ { index: { userId: 1, status: 1 } },
32
+ { index: { productId: 1, status: 1 } },
35
33
  { index: { status: 1 } },
36
34
  ]);
37
35
  return Quotations;
@@ -31,8 +31,8 @@ export declare const configureQuotationsModule: ({ db, migrationRepository, opti
31
31
  sort?: SortOption[];
32
32
  }, options?: mongodb.FindOptions) => Promise<Quotation[]>;
33
33
  normalizedStatus: (quotation: Quotation) => QuotationStatus;
34
- isExpired(quotation: Quotation, { referenceDate }: {
35
- referenceDate: Date;
34
+ isExpired(quotation: Quotation, { referenceDate }?: {
35
+ referenceDate?: Date;
36
36
  }): boolean;
37
37
  isProposalValid(quotation: Quotation): boolean;
38
38
  create: ({ countryCode, currencyCode, ...quotationData }: QuotationData & {
@@ -1,7 +1,7 @@
1
1
  import { SortDirection } from '@unchainedshop/utils';
2
2
  import { QuotationStatus } from "../db/QuotationsCollection.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 { QuotationsCollection } from "../db/QuotationsCollection.js";
6
6
  import { quotationsSettings } from "../quotations-settings.js";
7
7
  import renameCurrencyCode from "../migrations/20250502111800-currency-code.js";
@@ -15,7 +15,6 @@ export const buildFindSelector = ({ userId, queryString, quotationIds } = {}) =>
15
15
  selector._id = { $in: quotationIds };
16
16
  }
17
17
  if (queryString) {
18
- assertDocumentDBCompatMode();
19
18
  selector.$text = { $search: queryString };
20
19
  }
21
20
  return selector;
@@ -84,7 +83,7 @@ export const configureQuotationsModule = async ({ db, migrationRepository, optio
84
83
  updated: new Date(),
85
84
  ...fieldKeys.reduce((set, key) => ({ ...set, [key]: values[key] }), {}),
86
85
  },
87
- });
86
+ }, { returnDocument: 'after' });
88
87
  if (!quotation)
89
88
  return null;
90
89
  await emit('QUOTATION_UPDATE', { quotation, fields: fieldKeys });
@@ -119,7 +118,7 @@ export const configureQuotationsModule = async ({ db, migrationRepository, optio
119
118
  ? QuotationStatus.REQUESTED
120
119
  : quotation.status;
121
120
  },
122
- isExpired(quotation, { referenceDate }) {
121
+ isExpired(quotation, { referenceDate } = {}) {
123
122
  const relevantDate = referenceDate ? new Date(referenceDate) : new Date();
124
123
  if (!quotation.expires)
125
124
  return false;
@@ -146,10 +145,13 @@ export const configureQuotationsModule = async ({ db, migrationRepository, optio
146
145
  return quotation;
147
146
  },
148
147
  deleteRequestedUserQuotations: async (userId) => {
149
- const { deletedCount } = await Quotations.deleteMany({
148
+ const selector = {
150
149
  userId,
151
150
  status: { $in: [QuotationStatus.REQUESTED, null] },
152
- });
151
+ };
152
+ const quotations = await Quotations.find(selector, { projection: { _id: 1 } }).toArray();
153
+ const { deletedCount } = await Quotations.deleteMany(selector);
154
+ await Promise.all(quotations.map((quotation) => emit('QUOTATION_REMOVE', { quotationId: quotation._id })));
153
155
  return deletedCount;
154
156
  },
155
157
  updateContext: updateQuotationFields(['context']),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-quotations",
3
3
  "description": "Quotation and RFQ management module for the Unchained Engine",
4
- "version": "5.0.0-alpha.1",
4
+ "version": "5.0.0-alpha.3",
5
5
  "main": "lib/quotations-index.js",
6
6
  "types": "lib/quotations-index.d.ts",
7
7
  "type": "module",
@@ -36,11 +36,11 @@
36
36
  "homepage": "https://github.com/unchainedshop/unchained#readme",
37
37
  "dependencies": {
38
38
  "@unchainedshop/events": "^5.0.0-alpha.1",
39
- "@unchainedshop/logger": "^5.0.0-alpha.1",
39
+ "@unchainedshop/mongodb": "^5.0.0-alpha.1",
40
40
  "@unchainedshop/utils": "^5.0.0-alpha.1"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^25.0.0",
43
+ "@types/node": "^26.2.0",
44
44
  "typescript": "^5.8.3"
45
45
  }
46
46
  }