@alba-cars/common-modules 1.2.2 → 1.2.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.
Files changed (30) hide show
  1. package/dist/core/models/pagination/paginated_data.d.ts +18 -3
  2. package/dist/core/models/pagination/paginated_data.js +19 -0
  3. package/dist/core/network/endpoint-config.js +3 -3
  4. package/dist/features/sales-team/api/GetAgent.d.ts +1 -1
  5. package/dist/features/vehicle/api/index.d.ts +1 -0
  6. package/dist/features/vehicle/api/index.js +17 -0
  7. package/dist/features/vehicle/api/make/CreateMake.d.ts +2 -0
  8. package/dist/features/vehicle/api/make/CreateMake.js +21 -0
  9. package/dist/features/vehicle/api/make/DeleteMake.d.ts +2 -0
  10. package/dist/features/vehicle/api/make/DeleteMake.js +16 -0
  11. package/dist/features/vehicle/api/make/GetAllMakes.d.ts +3 -0
  12. package/dist/features/vehicle/api/make/GetAllMakes.js +25 -0
  13. package/dist/features/vehicle/api/make/GetOneMake.d.ts +2 -0
  14. package/dist/features/vehicle/api/make/GetOneMake.js +16 -0
  15. package/dist/features/vehicle/api/make/UpdateMake.d.ts +1 -1
  16. package/dist/features/vehicle/api/make/UpdateMake.js +9 -4
  17. package/dist/features/vehicle/api/make/index.d.ts +5 -0
  18. package/dist/features/vehicle/api/make/index.js +21 -0
  19. package/dist/features/vehicle/api/models/index.d.ts +0 -0
  20. package/dist/features/vehicle/api/models/index.js +1 -0
  21. package/dist/features/vehicle/data/dto/VehicleDTO.d.ts +2 -1
  22. package/dist/features/vehicle/data/dto/VehicleDTO.js +10 -3
  23. package/dist/features/vehicle/data/dto/VehicleMakeDTO.d.ts +2 -0
  24. package/dist/features/vehicle/data/utilities.d.ts +4 -2
  25. package/dist/features/vehicle/data/utilities.js +22 -6
  26. package/dist/features/vehicle/index.d.ts +1 -0
  27. package/dist/features/vehicle/index.js +1 -0
  28. package/dist/models.d.ts +1 -2
  29. package/dist/models.js +15 -0
  30. package/package.json +3 -3
@@ -1,6 +1,21 @@
1
- export interface PaginatedData<T> {
2
- result: T[];
1
+ import { AppError } from "../../error-handling";
2
+ export declare class DataReturnType<Data = unknown> {
3
+ constructor(success: boolean, message?: string, data?: Data, error?: AppError);
4
+ success: boolean;
5
+ message?: string;
6
+ data?: Data;
7
+ error?: AppError;
8
+ }
9
+ export interface PaginatedData<Data = unknown> {
10
+ result: Data;
11
+ limit: number;
3
12
  total: number;
4
13
  page: number;
5
- limit: number;
14
+ }
15
+ export declare class ReturnTypeWithPagination<Data = unknown> {
16
+ success: boolean;
17
+ message?: string | undefined;
18
+ data?: PaginatedData<Data> | undefined;
19
+ error?: AppError | undefined;
20
+ constructor(success: boolean, message?: string | undefined, data?: PaginatedData<Data> | undefined, error?: AppError | undefined);
6
21
  }
@@ -1,2 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReturnTypeWithPagination = exports.DataReturnType = void 0;
4
+ class DataReturnType {
5
+ constructor(success, message, data, error) {
6
+ this.success = success;
7
+ this.message = message;
8
+ this.data = data;
9
+ this.error = error;
10
+ }
11
+ }
12
+ exports.DataReturnType = DataReturnType;
13
+ class ReturnTypeWithPagination {
14
+ constructor(success, message, data, error) {
15
+ this.success = success;
16
+ this.message = message;
17
+ this.data = data;
18
+ this.error = error;
19
+ }
20
+ }
21
+ exports.ReturnTypeWithPagination = ReturnTypeWithPagination;
@@ -26,9 +26,9 @@ exports.API_ENDPOINTS = {
26
26
  vehicleMake: {
27
27
  getAll: `/vehicle/makes`,
28
28
  create: `/vehicle/makes`,
29
- getOne: (id) => `/vehiclemake/${id}`,
30
- deleteOne: (id) => `/vehiclemake/${id}`,
31
- updateOne: (id) => `/vehiclemake/${id}`,
29
+ getOne: (id) => `/vehicle/makes/${id}`,
30
+ deleteOne: (id) => `/vehicle/makes/${id}`,
31
+ updateOne: (id) => `/vehicle/makes/${id}`,
32
32
  },
33
33
  vehicleModel: {
34
34
  getAll: `/vehicle/models`,
@@ -1,3 +1,3 @@
1
1
  import { SalesAgentGetDTO } from "../data/dto/SalesAgentDTO";
2
2
  import { PaginatedData } from "../../../core";
3
- export declare const fetchAgents: (page: number, searchQuery?: string) => Promise<PaginatedData<SalesAgentGetDTO>>;
3
+ export declare const fetchAgents: (page: number, searchQuery?: string) => Promise<PaginatedData<SalesAgentGetDTO[]>>;
@@ -0,0 +1 @@
1
+ export * from "./make";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./make"), exports);
@@ -0,0 +1,2 @@
1
+ import { VehicleMakeApiResponse, VehicleMakeCreateDTO } from "../../data";
2
+ export declare const createVehicleMake: (vehicleMakeDTO: VehicleMakeCreateDTO) => Promise<VehicleMakeApiResponse>;
@@ -1 +1,22 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createVehicleMake = void 0;
4
+ const core_1 = require("../../../../core");
5
+ const createVehicleMake = async (vehicleMakeDTO) => {
6
+ var _a, _b;
7
+ try {
8
+ const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleMake.create.toString(), {
9
+ method: core_1.HttpMethods.POST,
10
+ body: JSON.stringify(vehicleMakeDTO)
11
+ });
12
+ if (!response.success) {
13
+ throw Error((_a = response.message) !== null && _a !== void 0 ? _a : (_b = response.error) === null || _b === void 0 ? void 0 : _b.message);
14
+ }
15
+ return response.data;
16
+ }
17
+ catch (error) {
18
+ console.error('Failed to create vehicle make:', error);
19
+ return Promise.reject(error);
20
+ }
21
+ };
22
+ exports.createVehicleMake = createVehicleMake;
@@ -0,0 +1,2 @@
1
+ import { VehicleMakeGetDTO } from "../../data";
2
+ export declare const deleteVehicleMake: (vehicleId: string) => Promise<VehicleMakeGetDTO>;
@@ -1 +1,17 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteVehicleMake = void 0;
4
+ const core_1 = require("../../../../core");
5
+ const deleteVehicleMake = async (vehicleId) => {
6
+ try {
7
+ const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleMake.deleteOne(vehicleId).toString(), {
8
+ method: core_1.HttpMethods.DELETE,
9
+ });
10
+ return response;
11
+ }
12
+ catch (error) {
13
+ console.error('Failed to delete vehicle make:', error);
14
+ return Promise.reject(error);
15
+ }
16
+ };
17
+ exports.deleteVehicleMake = deleteVehicleMake;
@@ -0,0 +1,3 @@
1
+ import { PaginatedData } from "../../../../core";
2
+ import { VehicleMake } from "../../data";
3
+ export declare const getAllVehicleMakes: (page: Number | null, searchQuery: string | null) => Promise<PaginatedData<VehicleMake[]>>;
@@ -1 +1,26 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllVehicleMakes = void 0;
4
+ const core_1 = require("../../../../core");
5
+ const getAllVehicleMakes = async (page, searchQuery) => {
6
+ var _a, _b, _c;
7
+ try {
8
+ const queryParams = { page: `${page}`, limit: "10" };
9
+ if ((searchQuery !== null && searchQuery !== void 0 ? searchQuery : "").trim().length > 1) {
10
+ queryParams.search = searchQuery;
11
+ }
12
+ const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleMake.getAll.toString(), {
13
+ method: core_1.HttpMethods.GET,
14
+ query: queryParams
15
+ });
16
+ if (!response.success) {
17
+ throw Error((_a = response.message) !== null && _a !== void 0 ? _a : (_b = response.error) === null || _b === void 0 ? void 0 : _b.message);
18
+ }
19
+ return (_c = response.data) !== null && _c !== void 0 ? _c : [];
20
+ }
21
+ catch (error) {
22
+ console.error('Failed to create vehicle make:', error);
23
+ return Promise.reject(error);
24
+ }
25
+ };
26
+ exports.getAllVehicleMakes = getAllVehicleMakes;
@@ -0,0 +1,2 @@
1
+ import { VehicleMakeGetDTO } from "../../data";
2
+ export default function getOneMake(makeID: string | number): Promise<VehicleMakeGetDTO>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("../../../../core");
4
+ async function getOneMake(makeID) {
5
+ try {
6
+ const res = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleMake.getOne(makeID), {
7
+ method: core_1.HttpMethods.GET,
8
+ });
9
+ return res;
10
+ }
11
+ catch (error) {
12
+ console.log('Failed to update make with id:', makeID, 'Error:', error);
13
+ return await Promise.reject(error);
14
+ }
15
+ }
16
+ exports.default = getOneMake;
@@ -1,2 +1,2 @@
1
1
  import { VehicleMakeGetDTO, VehicleMakeUpdateDTO } from "../../data";
2
- export default function updateMake(makeID: string | number, params: VehicleMakeUpdateDTO): Promise<VehicleMakeGetDTO>;
2
+ export declare const updateVehicleMake: (makeID: string | number, params: VehicleMakeUpdateDTO) => Promise<VehicleMakeGetDTO>;
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateVehicleMake = void 0;
3
4
  const core_1 = require("../../../../core");
4
- async function updateMake(makeID, params) {
5
+ const updateVehicleMake = async (makeID, params) => {
6
+ var _a, _b;
5
7
  try {
6
8
  const res = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleMake.updateOne(makeID), {
7
9
  method: core_1.HttpMethods.PUT,
8
10
  body: JSON.stringify(params),
9
11
  });
10
- return res;
12
+ if (!res.success) {
13
+ throw Error((_a = res.message) !== null && _a !== void 0 ? _a : (_b = res.error) === null || _b === void 0 ? void 0 : _b.message);
14
+ }
15
+ return res.data;
11
16
  }
12
17
  catch (error) {
13
18
  console.log('Failed to update make with id:', makeID, 'Error:', error);
14
19
  return await Promise.reject(error);
15
20
  }
16
- }
17
- exports.default = updateMake;
21
+ };
22
+ exports.updateVehicleMake = updateVehicleMake;
@@ -0,0 +1,5 @@
1
+ export * from "./CreateMake";
2
+ export * from "./DeleteMake";
3
+ export * from "./GetAllMakes";
4
+ export * from "./GetOneMake";
5
+ export * from "./UpdateMake";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./CreateMake"), exports);
18
+ __exportStar(require("./DeleteMake"), exports);
19
+ __exportStar(require("./GetAllMakes"), exports);
20
+ __exportStar(require("./GetOneMake"), exports);
21
+ __exportStar(require("./UpdateMake"), exports);
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -7,7 +7,8 @@ import { VehicleMediaCreateDTO, VehicleMediaUpdateDTO } from './VehicleMedia';
7
7
  export declare class VehicleGetDTO {
8
8
  filter?: VehicleFilter;
9
9
  options?: VehicleOptions;
10
- validate(): string[];
10
+ validate?: (shouldValidate?: boolean) => string[];
11
+ constructor(shouldIncludeValidate?: boolean);
11
12
  static fromPlain(plain: Record<string, unknown>): VehicleGetDTO;
12
13
  static toPlain(entity: any): Record<string, unknown>;
13
14
  }
@@ -19,9 +19,16 @@ const VehicleModelDTO_1 = require("./VehicleModelDTO");
19
19
  const VehicleTypeDTO_1 = require("./VehicleTypeDTO");
20
20
  const VehicleMedia_1 = require("./VehicleMedia");
21
21
  class VehicleGetDTO {
22
- validate() {
23
- const errors = (0, class_validator_1.validateSync)(this);
24
- return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
22
+ constructor(shouldIncludeValidate = true) {
23
+ if (shouldIncludeValidate) {
24
+ this.validate = (shouldValidate = true) => {
25
+ if (!shouldValidate) {
26
+ return [];
27
+ }
28
+ const errors = (0, class_validator_1.validateSync)(this);
29
+ return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
30
+ };
31
+ }
25
32
  }
26
33
  static fromPlain(plain) {
27
34
  return (0, class_transformer_1.plainToClass)(VehicleGetDTO, plain);
@@ -1,5 +1,6 @@
1
1
  import { VehicleMakeFilter, VehicleMakeOptions, VehicleMakeUniqueFilter } from '../utilities';
2
2
  import { BaseCreateDTO, BaseUpdateDTO } from './BaseDTO';
3
+ import { VehicleMake } from '../models';
3
4
  export declare class VehicleMakeGetDTO {
4
5
  filter?: VehicleMakeFilter;
5
6
  options?: VehicleMakeOptions;
@@ -7,6 +8,7 @@ export declare class VehicleMakeGetDTO {
7
8
  static fromPlain(plain: Record<string, unknown>): VehicleMakeGetDTO;
8
9
  static toPlain(entity: any): Record<string, unknown>;
9
10
  }
11
+ export type VehicleMakeApiResponse = Omit<VehicleMake, 'createdBy' | 'updatedBy' | 'deletedBy' | '_id'>;
10
12
  export declare class VehicleMakeGetUniqueDTO {
11
13
  filter?: VehicleMakeUniqueFilter;
12
14
  options?: Omit<VehicleMakeOptions, 'page' | 'limit' | 'sort'>;
@@ -181,7 +181,8 @@ export declare class VehicleFilter extends BaseFilter {
181
181
  status?: string | string[];
182
182
  features?: string | string[];
183
183
  search?: string;
184
- validate(): string[];
184
+ validate?: (shouldValidate?: boolean) => string[];
185
+ constructor(shouldIncludeValidate?: boolean);
185
186
  static fromPlain(plain: Record<string, unknown>): VehicleFilter;
186
187
  static toPlain(entity: any): Record<string, unknown>;
187
188
  }
@@ -203,7 +204,8 @@ export declare class VehicleOptions extends PaginationOptions {
203
204
  withBodyType?: boolean;
204
205
  withFeatures?: boolean;
205
206
  withMetaData?: boolean;
206
- validate(): string[];
207
+ validate?: (shouldValidate?: boolean) => string[];
208
+ constructor(shouldIncludeValidate?: boolean);
207
209
  static fromPlain(plain: Record<string, unknown>): VehicleOptions;
208
210
  static toPlain(entity: any): Record<string, unknown>;
209
211
  }
@@ -512,9 +512,17 @@ class VehicleFeatureCategoryOptions extends utilities_1.PaginationOptions {
512
512
  exports.VehicleFeatureCategoryOptions = VehicleFeatureCategoryOptions;
513
513
  // -----------------------------------------------------CAR-------------------------------------------------------------------------
514
514
  class VehicleFilter extends utilities_1.BaseFilter {
515
- validate() {
516
- const errors = (0, class_validator_1.validateSync)(this);
517
- return errors.map(error => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
515
+ constructor(shouldIncludeValidate = true) {
516
+ super();
517
+ if (shouldIncludeValidate) {
518
+ this.validate = (shouldValidate = true) => {
519
+ if (!shouldValidate) {
520
+ return [];
521
+ }
522
+ const errors = (0, class_validator_1.validateSync)(this);
523
+ return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
524
+ };
525
+ }
518
526
  }
519
527
  static fromPlain(plain) {
520
528
  return (0, class_transformer_1.plainToClass)(VehicleFilter, plain);
@@ -692,9 +700,17 @@ __decorate([
692
700
  ], VehicleUniqueFilter.prototype, "chassisNumber", void 0);
693
701
  exports.VehicleUniqueFilter = VehicleUniqueFilter;
694
702
  class VehicleOptions extends utilities_1.PaginationOptions {
695
- validate() {
696
- const errors = (0, class_validator_1.validateSync)(this);
697
- return errors.map(error => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
703
+ constructor(shouldIncludeValidate = true) {
704
+ super();
705
+ if (shouldIncludeValidate) {
706
+ this.validate = (shouldValidate = true) => {
707
+ if (!shouldValidate) {
708
+ return [];
709
+ }
710
+ const errors = (0, class_validator_1.validateSync)(this);
711
+ return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
712
+ };
713
+ }
698
714
  }
699
715
  static fromPlain(plain) {
700
716
  return (0, class_transformer_1.plainToClass)(VehicleOptions, plain);
@@ -1 +1,2 @@
1
1
  export * from "./data";
2
+ export * from "./api";
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./data"), exports);
18
+ __exportStar(require("./api"), exports);
package/dist/models.d.ts CHANGED
@@ -1,2 +1 @@
1
- import { PaginatedData } from "./core/models/pagination/paginated_data";
2
- export { PaginatedData };
1
+ export * from "./core/models/pagination/paginated_data";
package/dist/models.js CHANGED
@@ -1,2 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./core/models/pagination/paginated_data"), exports);
package/package.json CHANGED
@@ -3,14 +3,14 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.2.2",
6
+ "version": "1.2.4",
7
7
  "description": "A package containing DTOs, validation classes and common modules and interfaces for Alba Cars",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
- "types": "./index.d.ts",
13
- "default": "./index.ts"
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
14
  }
15
15
  },
16
16
  "scripts": {