@nomalism-com/api 0.8.288 → 0.8.290

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,5 @@
1
1
  import { shared, Promotion as Entity } from '@nomalism-com/types';
2
+ import { IProductPromotionVirtuals } from './product';
2
3
  export import IFindRequest = Entity.IFindRequest;
3
4
  export import IFindResponse = Entity.IFindResponse;
4
5
  export import IFindPaginatedRequest = Entity.IFindPaginatedRequest;
@@ -10,4 +11,5 @@ export import IEntity = Entity.Entity;
10
11
  export import IUpdateRequest = Entity.IUpdateRequest;
11
12
  export type IPaginationResponse = shared.IPaginationResponse<Entity.IFindResponse>;
12
13
  export declare const route: string;
14
+ export declare const getBestDiscount: (promotions: IProductPromotionVirtuals[], discount?: number, location_id?: string, client_id?: string) => number;
13
15
  export declare const find: (selector: Entity.IFindRequest) => Promise<Entity.IFindResponse[]>, findPaginated: (selector: Entity.IFindPaginatedRequest) => Promise<Entity.IFindWithPaginationResponse>, findMinified: (params?: shared.IFindMinifiedRequest | undefined) => Promise<shared.IFindMinifiedResponse[]>, findByOwnerId: (params: shared.IFindByOwnerIdRequest) => Promise<Entity.IFindByOwnerIdResponse[]>, findById: (selector: shared.IFindByIdRequest) => Promise<Entity.IFindByIdResponse | null>, create: (data: Entity.ICreateRequest) => Promise<import("@nomalism-com/types/dist/shared/entities").Promotion>, update: (selector: shared.IFindByIdRequest, data: Entity.IUpdateRequest) => Promise<import("@nomalism-com/types/dist/shared/entities").Promotion | null>, deleteOne: (selector: shared.IFindByIdRequest) => Promise<import("@nomalism-com/types/dist/shared/entities").Promotion | null>;
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.deleteOne = exports.update = exports.create = exports.findById = exports.findByOwnerId = exports.findMinified = exports.findPaginated = exports.find = exports.route = void 0;
42
+ exports.deleteOne = exports.update = exports.create = exports.findById = exports.findByOwnerId = exports.findMinified = exports.findPaginated = exports.find = exports.getBestDiscount = exports.route = void 0;
43
43
  var client_1 = __importDefault(require("../../shared/client"));
44
44
  var _1 = require(".");
45
45
  exports.route = "".concat(_1.serviceHostname).concat(_1.serviceAuthPath, "promotion/");
@@ -137,4 +137,25 @@ var repository = {
137
137
  });
138
138
  }); },
139
139
  };
140
+ var getBestDiscount = function (promotions, discount, location_id, client_id) {
141
+ var highestPromoDiscount = promotions
142
+ .filter(function (promotion) {
143
+ return promotion.exclusive_to_location_id
144
+ ? promotion.exclusive_to_location_id === location_id
145
+ : true;
146
+ })
147
+ .filter(function (promotion) {
148
+ return promotion.exclusive_to_client_id
149
+ ? promotion.exclusive_to_client_id === client_id
150
+ : true;
151
+ })
152
+ .reduce(function (highest, promotion) {
153
+ return promotion.discount > highest ? promotion.discount : highest;
154
+ }, 0);
155
+ var clientDiscount = discount || 0;
156
+ return highestPromoDiscount > clientDiscount
157
+ ? highestPromoDiscount
158
+ : clientDiscount;
159
+ };
160
+ exports.getBestDiscount = getBestDiscount;
140
161
  exports.find = repository.find, exports.findPaginated = repository.findPaginated, exports.findMinified = repository.findMinified, exports.findByOwnerId = repository.findByOwnerId, exports.findById = repository.findById, exports.create = repository.create, exports.update = repository.update, exports.deleteOne = repository.deleteOne;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "typescript",
10
10
  "helper"
11
11
  ],
12
- "version": "0.8.288",
12
+ "version": "0.8.290",
13
13
  "main": "dist/index.js",
14
14
  "types": "./dist/index.d.ts",
15
15
  "files": [
@@ -47,7 +47,7 @@
47
47
  "typescript": "^5.0.4"
48
48
  },
49
49
  "dependencies": {
50
- "@nomalism-com/types": "^0.9.376",
50
+ "@nomalism-com/types": "^0.9.378",
51
51
  "axios": "^0.27.2"
52
52
  }
53
53
  }