@unchainedshop/core-quotations 5.0.0-alpha.10 → 5.0.0-alpha.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.
@@ -9,6 +9,9 @@ export declare const QuotationStatus: {
9
9
  export type QuotationStatus = (typeof QuotationStatus)[keyof typeof QuotationStatus];
10
10
  export interface QuotationProposal {
11
11
  price?: number;
12
+ quantity?: number;
13
+ isTaxable?: boolean;
14
+ isNetPrice?: boolean;
12
15
  expires?: Date;
13
16
  meta?: any;
14
17
  }
@@ -30,9 +33,12 @@ export type Quotation = {
30
33
  currencyCode?: string;
31
34
  expires?: Date;
32
35
  fulfilled?: Date;
36
+ isNetPrice?: boolean;
37
+ isTaxable?: boolean;
33
38
  meta?: any;
34
39
  price?: number;
35
40
  productId: string;
41
+ quantity?: number;
36
42
  quotationNumber?: string;
37
43
  rejected?: Date;
38
44
  status: string | null;
@@ -1,5 +1,5 @@
1
1
  import { type SortOption } from '@unchainedshop/utils';
2
- import { type Quotation, QuotationStatus } from '../db/QuotationsCollection.ts';
2
+ import { type Quotation, type QuotationProposal, QuotationStatus } from '../db/QuotationsCollection.ts';
3
3
  import { mongodb, type ModuleInput } from '@unchainedshop/mongodb';
4
4
  import { type QuotationsSettingsOptions } from '../quotations-settings.ts';
5
5
  export interface QuotationQuery {
@@ -14,6 +14,7 @@ export interface QuotationData {
14
14
  }[];
15
15
  countryCode?: string;
16
16
  productId: string;
17
+ quantity?: number;
17
18
  userId: string;
18
19
  }
19
20
  export declare const buildFindSelector: ({ userId, queryString, quotationIds }?: QuotationQuery) => mongodb.Filter<Quotation>;
@@ -35,12 +36,18 @@ export declare const configureQuotationsModule: ({ db, migrationRepository, opti
35
36
  referenceDate?: Date;
36
37
  }): boolean;
37
38
  isProposalValid(quotation: Quotation): boolean;
39
+ isProposalValidFor(quotation: Quotation, { userId, productId, currencyCode }: {
40
+ userId: string;
41
+ productId: string;
42
+ currencyCode: string;
43
+ }): boolean;
38
44
  create: ({ countryCode, currencyCode, ...quotationData }: QuotationData & {
39
45
  currencyCode: string;
40
46
  }) => Promise<Quotation>;
41
47
  deleteRequestedUserQuotations: (userId: string) => Promise<number>;
48
+ replaceUserIdOfOpenQuotations: (fromUserId: string, toUserId: string) => Promise<number>;
42
49
  updateContext: (quotationId: string, values: any) => Promise<mongodb.WithId<Quotation> | null>;
43
- updateProposal: (quotationId: string, values: any) => Promise<mongodb.WithId<Quotation> | null>;
50
+ updateProposal: (quotationId: string, proposal: QuotationProposal) => Promise<mongodb.WithId<Quotation> | null>;
44
51
  updateStatus: (quotationId: string, { status, info }: {
45
52
  status: QuotationStatus;
46
53
  info?: string;
@@ -95,8 +95,16 @@ export const configureQuotationsModule = async ({ db, migrationRepository, optio
95
95
  return quotationCount;
96
96
  },
97
97
  openQuotationWithProduct: async ({ productId }) => {
98
- const selector = { productId };
99
- selector.status = { $in: [QuotationStatus.REQUESTED, QuotationStatus.PROPOSED] };
98
+ const selector = {
99
+ productId,
100
+ $or: [
101
+ { status: QuotationStatus.REQUESTED },
102
+ {
103
+ status: QuotationStatus.PROPOSED,
104
+ $or: [{ expires: { $not: { $type: 'date' } } }, { expires: { $gt: new Date() } }],
105
+ },
106
+ ],
107
+ };
100
108
  return Quotations.findOne(selector);
101
109
  },
102
110
  findQuotation: async ({ quotationId }, options) => {
@@ -129,6 +137,12 @@ export const configureQuotationsModule = async ({ db, migrationRepository, optio
129
137
  isProposalValid(quotation) {
130
138
  return quotation.status === QuotationStatus.PROPOSED && !this.isExpired(quotation);
131
139
  },
140
+ isProposalValidFor(quotation, { userId, productId, currencyCode }) {
141
+ return (this.isProposalValid(quotation) &&
142
+ quotation.userId === userId &&
143
+ quotation.productId === productId &&
144
+ quotation.currencyCode === currencyCode);
145
+ },
132
146
  create: async ({ countryCode, currencyCode, ...quotationData }) => {
133
147
  const { insertedId: quotationId } = await Quotations.insertOne({
134
148
  _id: generateDbObjectId(),
@@ -154,8 +168,24 @@ export const configureQuotationsModule = async ({ db, migrationRepository, optio
154
168
  await Promise.all(quotations.map((quotation) => emit('QUOTATION_REMOVE', { quotationId: quotation._id })));
155
169
  return deletedCount;
156
170
  },
171
+ replaceUserIdOfOpenQuotations: async (fromUserId, toUserId) => {
172
+ const result = await Quotations.updateMany({
173
+ userId: fromUserId,
174
+ status: {
175
+ $in: [null, QuotationStatus.REQUESTED, QuotationStatus.PROCESSING, QuotationStatus.PROPOSED],
176
+ },
177
+ }, { $set: { userId: toUserId, updated: new Date() } });
178
+ return result.modifiedCount;
179
+ },
157
180
  updateContext: updateQuotationFields(['context']),
158
- updateProposal: updateQuotationFields(['price', 'expires', 'meta']),
181
+ updateProposal: (quotationId, proposal) => updateQuotationFields([
182
+ 'price',
183
+ 'isTaxable',
184
+ 'isNetPrice',
185
+ 'expires',
186
+ 'meta',
187
+ ...(Number.isInteger(proposal.quantity) && proposal.quantity > 0 ? ['quantity'] : []),
188
+ ])(quotationId, proposal),
159
189
  updateStatus,
160
190
  };
161
191
  };
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.10",
4
+ "version": "5.0.0-alpha.11",
5
5
  "files": [
6
6
  "lib"
7
7
  ],
@@ -38,9 +38,9 @@
38
38
  },
39
39
  "homepage": "https://github.com/unchainedshop/unchained#readme",
40
40
  "dependencies": {
41
- "@unchainedshop/events": "^5.0.0-alpha.10",
42
- "@unchainedshop/mongodb": "^5.0.0-alpha.10",
43
- "@unchainedshop/utils": "^5.0.0-alpha.10"
41
+ "@unchainedshop/events": "^5.0.0-alpha.11",
42
+ "@unchainedshop/mongodb": "^5.0.0-alpha.11",
43
+ "@unchainedshop/utils": "^5.0.0-alpha.11"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^26.2.0",