@alba-cars/common-modules 1.2.4 → 1.2.5
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.
- package/dist/core/network/endpoint-config.js +8 -8
- package/dist/core/network/fetch-api.d.ts +1 -1
- package/dist/core/network/fetch-api.js +4 -2
- package/dist/core/utils/global-utils.d.ts +73 -7
- package/dist/core/utils/global-utils.js +112 -9
- package/dist/core/utils/query_flatten.d.ts +1 -0
- package/dist/core/utils/query_flatten.js +15 -0
- package/dist/features/vehicle/api/body_types/CreateBodyType.d.ts +2 -0
- package/dist/features/vehicle/api/body_types/CreateBodyType.js +22 -0
- package/dist/features/vehicle/api/body_types/DeleteBodyType.d.ts +2 -0
- package/dist/features/vehicle/api/body_types/DeleteBodyType.js +17 -0
- package/dist/features/vehicle/api/body_types/GetAllBodyTypes.d.ts +3 -0
- package/dist/features/vehicle/api/body_types/GetAllBodyTypes.js +26 -0
- package/dist/features/vehicle/api/body_types/UpdateBodyType.d.ts +2 -0
- package/dist/features/vehicle/api/body_types/UpdateBodyType.js +22 -0
- package/dist/features/vehicle/api/body_types/index.d.ts +4 -0
- package/dist/features/vehicle/api/body_types/index.js +20 -0
- package/dist/features/vehicle/api/index.d.ts +2 -0
- package/dist/features/vehicle/api/index.js +2 -0
- package/dist/features/vehicle/api/make/GetAllMakes.d.ts +1 -1
- package/dist/features/vehicle/api/make/GetAllMakes.js +1 -1
- package/dist/features/vehicle/api/models/CreateModel.d.ts +2 -0
- package/dist/features/vehicle/api/models/CreateModel.js +21 -0
- package/dist/features/vehicle/api/models/DeleteModel.d.ts +2 -0
- package/dist/features/vehicle/api/models/DeleteModel.js +16 -0
- package/dist/features/vehicle/api/models/GetAllModels.d.ts +3 -0
- package/dist/features/vehicle/api/models/GetAllModels.js +36 -0
- package/dist/features/vehicle/api/models/UpdateModel.d.ts +2 -0
- package/dist/features/vehicle/api/models/UpdateModel.js +21 -0
- package/dist/features/vehicle/api/models/index.d.ts +4 -0
- package/dist/features/vehicle/api/models/index.js +19 -0
- package/dist/features/vehicle/data/dto/VehicleModelDTO.d.ts +1 -3
- package/dist/features/vehicle/data/dto/VehicleModelDTO.js +0 -7
- package/package.json +3 -2
|
@@ -33,9 +33,9 @@ exports.API_ENDPOINTS = {
|
|
|
33
33
|
vehicleModel: {
|
|
34
34
|
getAll: `/vehicle/models`,
|
|
35
35
|
create: `/vehicle/models`,
|
|
36
|
-
getOne: (id) => `/
|
|
37
|
-
deleteOne: (id) => `/
|
|
38
|
-
updateOne: (id) => `/
|
|
36
|
+
getOne: (id) => `/vehicle/models/${id}`,
|
|
37
|
+
deleteOne: (id) => `/vehicle/models/${id}`,
|
|
38
|
+
updateOne: (id) => `/vehicle/models/${id}`,
|
|
39
39
|
},
|
|
40
40
|
TestDrive: {
|
|
41
41
|
getAll: `/test-drive-requests`,
|
|
@@ -52,11 +52,11 @@ exports.API_ENDPOINTS = {
|
|
|
52
52
|
updateOne: (id) => `/vehicleorder/${id}`,
|
|
53
53
|
},
|
|
54
54
|
vehicleType: {
|
|
55
|
-
getAll: `/body-types`,
|
|
56
|
-
create: `/body-types`,
|
|
57
|
-
getOne: (id) => `/body-types/${id}`,
|
|
58
|
-
deleteOne: (id) => `/body-types/${id}`,
|
|
59
|
-
updateOne: (id) => `/body-types/${id}`,
|
|
55
|
+
getAll: `/vehicle/body-types`,
|
|
56
|
+
create: `/vehicle/body-types`,
|
|
57
|
+
getOne: (id) => `/vehicle/body-types/${id}`,
|
|
58
|
+
deleteOne: (id) => `/vehicle/body-types/${id}`,
|
|
59
|
+
updateOne: (id) => `/vehicle/body-types/${id}`,
|
|
60
60
|
},
|
|
61
61
|
carOptions: {
|
|
62
62
|
getAll: `/caroptions`,
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.apiRequest = void 0;
|
|
7
|
-
const
|
|
7
|
+
const qs_1 = __importDefault(require("qs"));
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const enums_1 = require("../enums");
|
|
10
10
|
const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
@@ -27,7 +27,9 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
27
27
|
options.method && options.method !== enums_1.HttpMethods.GET && console.log(`${BASE_URL}${endpoint}`);
|
|
28
28
|
let url = `${BASE_URL}${endpoint}`;
|
|
29
29
|
if (options.query && Object.keys(options.query).length > 0) {
|
|
30
|
-
|
|
30
|
+
console.log("Raw params ", options.query);
|
|
31
|
+
console.log("Stringified params = ", qs_1.default.stringify(options.query));
|
|
32
|
+
url += `?${qs_1.default.stringify(options.query, { allowDots: true, arrayFormat: 'brackets', allowEmptyArrays: false, skipNulls: true })}`;
|
|
31
33
|
}
|
|
32
34
|
const response = await fetch(url, config);
|
|
33
35
|
// Parse the response once and store it
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Converts a value to an array.
|
|
3
|
-
*
|
|
4
|
-
* @param value - The value to convert.
|
|
5
|
-
* @returns An array containing the value, or the value itself if it is already an array.
|
|
6
|
-
*/
|
|
7
|
-
export declare const makeArray: <T>(value: T) => T[];
|
|
1
|
+
import { Booleanish } from "../../global";
|
|
8
2
|
/**
|
|
9
3
|
* Deeply compares two objects for equality.
|
|
10
4
|
*
|
|
@@ -39,4 +33,76 @@ type ComparatorFunction = (_a: any, _b: any) => number;
|
|
|
39
33
|
export declare const sortBy: (array: any[], key: string | ComparatorFunction) => any[];
|
|
40
34
|
export declare function generateRandomBase64(length: number): string;
|
|
41
35
|
export declare const formatValue: (n: number | string) => string;
|
|
36
|
+
interface TimeInput {
|
|
37
|
+
minutes?: number;
|
|
38
|
+
hours?: number;
|
|
39
|
+
seconds?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts a time input to milliseconds
|
|
43
|
+
*/
|
|
44
|
+
export declare const timeAsMilliseconds: ({ minutes, hours, seconds }: TimeInput) => number;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a time input to seconds
|
|
47
|
+
*/
|
|
48
|
+
export declare const timeAsSeconds: ({ minutes, hours, seconds }: TimeInput) => number;
|
|
49
|
+
/**
|
|
50
|
+
* Removes a key from an object or an array of objects (deeply)
|
|
51
|
+
*/
|
|
52
|
+
export declare function removeKeyFromObject(obj: any, keyToRemove: string): unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Formats a number as a currency string (AED)
|
|
55
|
+
*/
|
|
56
|
+
export declare const currencyFormatter: ({ isDecimal, decimalPlaces }: {
|
|
57
|
+
isDecimal: boolean;
|
|
58
|
+
decimalPlaces: number;
|
|
59
|
+
}) => Intl.NumberFormat;
|
|
60
|
+
/**
|
|
61
|
+
* Safely parses a string or number into a number
|
|
62
|
+
*/
|
|
63
|
+
export declare const safeParseNumber: (value: string | number) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Formats a number with commas
|
|
66
|
+
*/
|
|
67
|
+
export declare const formatNumberWithCommas: (value: string) => string;
|
|
68
|
+
/**
|
|
69
|
+
* Converts a single value or an array of values into an array
|
|
70
|
+
*/
|
|
71
|
+
export declare const makeArray: <T>(value: T | T[]) => T[];
|
|
72
|
+
/**
|
|
73
|
+
* Check if a value is empty (nullable or empty string)
|
|
74
|
+
*/
|
|
75
|
+
export declare const isEmpty: (value: any) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Check if an object is an empty object
|
|
78
|
+
*/
|
|
79
|
+
export declare const isEmptyObject: (value: Record<string, any>) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Check if a value is an empty array
|
|
82
|
+
*/
|
|
83
|
+
export declare const isEmptyArray: (value: any) => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if a value is not empty (null, undefined, or empty string), not an empty object, and not an empty array
|
|
86
|
+
*/
|
|
87
|
+
export declare const hasValue: (value: any) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a pluralized string based on the value
|
|
90
|
+
* @example getPlural(1, 'item') => '1 item'
|
|
91
|
+
* @example getPlural(4, 'item') => '4 items'
|
|
92
|
+
* @example getPlural(2, 'person', 'people') => '2 people'
|
|
93
|
+
* @example getPlural(0, 'item') => '0 items'
|
|
94
|
+
*/
|
|
95
|
+
export declare const getPlural: (value: number, singular: string, plural?: string | null) => string;
|
|
96
|
+
/**
|
|
97
|
+
* Escapes special characters in a search term to prevent them from being interpreted as regex operators
|
|
98
|
+
*/
|
|
99
|
+
export declare const sanitizeRegexString: (input: string) => string;
|
|
100
|
+
/**
|
|
101
|
+
* Converts a value to a plain object by serializing to and from JSON
|
|
102
|
+
*/
|
|
103
|
+
export declare const toPlainObject: (value: unknown) => Record<string, any>;
|
|
104
|
+
/**
|
|
105
|
+
* Converts a Booleanish value (boolean | 'true' | '1' | 'false' | '0') to a boolean
|
|
106
|
+
*/
|
|
107
|
+
export declare const booleanize: (value: Booleanish) => boolean;
|
|
42
108
|
export {};
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatValue = exports.generateRandomBase64 = exports.sortBy = exports.isFunction = exports.isPlainObject = exports.deepEqual =
|
|
4
|
-
/**
|
|
5
|
-
* Converts a value to an array.
|
|
6
|
-
*
|
|
7
|
-
* @param value - The value to convert.
|
|
8
|
-
* @returns An array containing the value, or the value itself if it is already an array.
|
|
9
|
-
*/
|
|
10
|
-
const makeArray = (value) => (Array.isArray(value) ? value : [value]);
|
|
11
|
-
exports.makeArray = makeArray;
|
|
3
|
+
exports.booleanize = exports.toPlainObject = exports.sanitizeRegexString = exports.getPlural = exports.hasValue = exports.isEmptyArray = exports.isEmptyObject = exports.isEmpty = exports.makeArray = exports.formatNumberWithCommas = exports.safeParseNumber = exports.currencyFormatter = exports.removeKeyFromObject = exports.timeAsSeconds = exports.timeAsMilliseconds = exports.formatValue = exports.generateRandomBase64 = exports.sortBy = exports.isFunction = exports.isPlainObject = exports.deepEqual = void 0;
|
|
12
4
|
/**
|
|
13
5
|
* Deeply compares two objects for equality.
|
|
14
6
|
*
|
|
@@ -85,3 +77,114 @@ const formatValue = (n) => {
|
|
|
85
77
|
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
86
78
|
};
|
|
87
79
|
exports.formatValue = formatValue;
|
|
80
|
+
/**
|
|
81
|
+
* Converts a time input to milliseconds
|
|
82
|
+
*/
|
|
83
|
+
const timeAsMilliseconds = ({ minutes = 0, hours = 0, seconds = 0 }) => {
|
|
84
|
+
return minutes * 60 * 1000 + hours * 60 * 60 * 1000 + seconds * 1000;
|
|
85
|
+
};
|
|
86
|
+
exports.timeAsMilliseconds = timeAsMilliseconds;
|
|
87
|
+
/**
|
|
88
|
+
* Converts a time input to seconds
|
|
89
|
+
*/
|
|
90
|
+
const timeAsSeconds = ({ minutes = 0, hours = 0, seconds = 0 }) => {
|
|
91
|
+
return minutes * 60 + hours * 60 * 60 + seconds;
|
|
92
|
+
};
|
|
93
|
+
exports.timeAsSeconds = timeAsSeconds;
|
|
94
|
+
/**
|
|
95
|
+
* Removes a key from an object or an array of objects (deeply)
|
|
96
|
+
*/
|
|
97
|
+
function removeKeyFromObject(obj, keyToRemove) {
|
|
98
|
+
if (Array.isArray(obj)) {
|
|
99
|
+
return obj.map((item) => removeKeyFromObject(item, keyToRemove));
|
|
100
|
+
}
|
|
101
|
+
else if (typeof obj === "object" && obj !== null) {
|
|
102
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
103
|
+
if (key !== keyToRemove) {
|
|
104
|
+
acc[key] = removeKeyFromObject(obj[key], keyToRemove);
|
|
105
|
+
}
|
|
106
|
+
return acc;
|
|
107
|
+
}, {});
|
|
108
|
+
}
|
|
109
|
+
return obj;
|
|
110
|
+
}
|
|
111
|
+
exports.removeKeyFromObject = removeKeyFromObject;
|
|
112
|
+
/**
|
|
113
|
+
* Formats a number as a currency string (AED)
|
|
114
|
+
*/
|
|
115
|
+
const currencyFormatter = ({ isDecimal, decimalPlaces = 2 }) => new Intl.NumberFormat('en-US', {
|
|
116
|
+
style: "currency",
|
|
117
|
+
currency: "AED",
|
|
118
|
+
maximumFractionDigits: isDecimal ? decimalPlaces : 0,
|
|
119
|
+
});
|
|
120
|
+
exports.currencyFormatter = currencyFormatter;
|
|
121
|
+
/**
|
|
122
|
+
* Safely parses a string or number into a number
|
|
123
|
+
*/
|
|
124
|
+
const safeParseNumber = (value) => {
|
|
125
|
+
if (typeof value === 'number')
|
|
126
|
+
return value;
|
|
127
|
+
if (typeof value !== 'string')
|
|
128
|
+
return 0;
|
|
129
|
+
return Number(value.trim().replace(/,/g, '')) || 0;
|
|
130
|
+
};
|
|
131
|
+
exports.safeParseNumber = safeParseNumber;
|
|
132
|
+
/**
|
|
133
|
+
* Formats a number with commas
|
|
134
|
+
*/
|
|
135
|
+
const formatNumberWithCommas = (value) => {
|
|
136
|
+
const number = value.replace(/[^\d]/g, '');
|
|
137
|
+
return number.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
138
|
+
};
|
|
139
|
+
exports.formatNumberWithCommas = formatNumberWithCommas;
|
|
140
|
+
/**
|
|
141
|
+
* Converts a single value or an array of values into an array
|
|
142
|
+
*/
|
|
143
|
+
const makeArray = (value) => {
|
|
144
|
+
return Array.isArray(value) ? value : [value];
|
|
145
|
+
};
|
|
146
|
+
exports.makeArray = makeArray;
|
|
147
|
+
/**
|
|
148
|
+
* Check if a value is empty (nullable or empty string)
|
|
149
|
+
*/
|
|
150
|
+
const isEmpty = (value) => (value === null || value === undefined || value === '');
|
|
151
|
+
exports.isEmpty = isEmpty;
|
|
152
|
+
/**
|
|
153
|
+
* Check if an object is an empty object
|
|
154
|
+
*/
|
|
155
|
+
const isEmptyObject = (value) => Object.keys(value).length === 0 && value.constructor === Object;
|
|
156
|
+
exports.isEmptyObject = isEmptyObject;
|
|
157
|
+
/**
|
|
158
|
+
* Check if a value is an empty array
|
|
159
|
+
*/
|
|
160
|
+
const isEmptyArray = (value) => Array.isArray(value) && value.length === 0;
|
|
161
|
+
exports.isEmptyArray = isEmptyArray;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a value is not empty (null, undefined, or empty string), not an empty object, and not an empty array
|
|
164
|
+
*/
|
|
165
|
+
const hasValue = (value) => !(0, exports.isEmpty)(value) && !(0, exports.isEmptyObject)(value) && !(0, exports.isEmptyArray)(value);
|
|
166
|
+
exports.hasValue = hasValue;
|
|
167
|
+
/**
|
|
168
|
+
* Returns a pluralized string based on the value
|
|
169
|
+
* @example getPlural(1, 'item') => '1 item'
|
|
170
|
+
* @example getPlural(4, 'item') => '4 items'
|
|
171
|
+
* @example getPlural(2, 'person', 'people') => '2 people'
|
|
172
|
+
* @example getPlural(0, 'item') => '0 items'
|
|
173
|
+
*/
|
|
174
|
+
const getPlural = (value, singular, plural = null) => value === 1 ? `${value} ${singular}` : plural ? `${value} ${plural}` : `${value} ${singular}s`;
|
|
175
|
+
exports.getPlural = getPlural;
|
|
176
|
+
/**
|
|
177
|
+
* Escapes special characters in a search term to prevent them from being interpreted as regex operators
|
|
178
|
+
*/
|
|
179
|
+
const sanitizeRegexString = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
180
|
+
exports.sanitizeRegexString = sanitizeRegexString;
|
|
181
|
+
/**
|
|
182
|
+
* Converts a value to a plain object by serializing to and from JSON
|
|
183
|
+
*/
|
|
184
|
+
const toPlainObject = (value) => JSON.parse(JSON.stringify(value));
|
|
185
|
+
exports.toPlainObject = toPlainObject;
|
|
186
|
+
/**
|
|
187
|
+
* Converts a Booleanish value (boolean | 'true' | '1' | 'false' | '0') to a boolean
|
|
188
|
+
*/
|
|
189
|
+
const booleanize = (value) => ([true, 'true', '1'].includes(value) ? true : false);
|
|
190
|
+
exports.booleanize = booleanize;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare function flattenQuery(query: Record<string, any>): Record<string, any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function flattenQuery(query) {
|
|
3
|
+
const flattened = {};
|
|
4
|
+
for (const key in query) {
|
|
5
|
+
if (typeof query[key] === "object" && query[key] !== null) {
|
|
6
|
+
for (const subKey in query[key]) {
|
|
7
|
+
flattened[subKey] = query[key][subKey];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
flattened[key] = query[key];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return flattened;
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVehicleBodyType = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const createVehicleBodyType = async (vehicleBodyTypeDTO) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
try {
|
|
8
|
+
const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleType.create.toString(), {
|
|
9
|
+
method: core_1.HttpMethods.POST,
|
|
10
|
+
body: JSON.stringify(vehicleBodyTypeDTO)
|
|
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.createVehicleBodyType = createVehicleBodyType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteVehicleBodyType = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const deleteVehicleBodyType = async (bodyTypeId) => {
|
|
6
|
+
try {
|
|
7
|
+
const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleType.deleteOne(bodyTypeId).toString(), {
|
|
8
|
+
method: core_1.HttpMethods.DELETE,
|
|
9
|
+
});
|
|
10
|
+
return response;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
console.error('Failed to delete vehicle body type:', error);
|
|
14
|
+
return Promise.reject(error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.deleteVehicleBodyType = deleteVehicleBodyType;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllVehicleBodyTypes = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const getAllVehicleBodyTypes = 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.vehicleType.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 fetch vehicle types:', error);
|
|
23
|
+
return Promise.reject(error);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.getAllVehicleBodyTypes = getAllVehicleBodyTypes;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateVehicleBodyType = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const updateVehicleBodyType = async (bodyTypeId, params) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
try {
|
|
8
|
+
const res = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleType.updateOne(bodyTypeId), {
|
|
9
|
+
method: core_1.HttpMethods.PUT,
|
|
10
|
+
body: JSON.stringify(params),
|
|
11
|
+
});
|
|
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;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.log('Failed to update make with id:', bodyTypeId, 'Error:', error);
|
|
19
|
+
return await Promise.reject(error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.updateVehicleBodyType = updateVehicleBodyType;
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./CreateBodyType"), exports);
|
|
18
|
+
__exportStar(require("./DeleteBodyType"), exports);
|
|
19
|
+
__exportStar(require("./GetAllBodyTypes"), exports);
|
|
20
|
+
__exportStar(require("./UpdateBodyType"), exports);
|
|
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./make"), exports);
|
|
18
|
+
__exportStar(require("./models"), exports);
|
|
19
|
+
__exportStar(require("./body_types"), exports);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PaginatedData } from "../../../../core";
|
|
2
2
|
import { VehicleMake } from "../../data";
|
|
3
|
-
export declare const getAllVehicleMakes: (page:
|
|
3
|
+
export declare const getAllVehicleMakes: (page: number | null, searchQuery: string | null) => Promise<PaginatedData<VehicleMake[]>>;
|
|
@@ -19,7 +19,7 @@ const getAllVehicleMakes = async (page, searchQuery) => {
|
|
|
19
19
|
return (_c = response.data) !== null && _c !== void 0 ? _c : [];
|
|
20
20
|
}
|
|
21
21
|
catch (error) {
|
|
22
|
-
console.error('Failed to
|
|
22
|
+
console.error('Failed to fetch vehicle make:', error);
|
|
23
23
|
return Promise.reject(error);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
@@ -1 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVehicleModel = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const createVehicleModel = async (vehicleModelDTO) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
try {
|
|
8
|
+
const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleModel.create.toString(), {
|
|
9
|
+
method: core_1.HttpMethods.POST,
|
|
10
|
+
body: JSON.stringify(vehicleModelDTO)
|
|
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 model:', error);
|
|
19
|
+
return Promise.reject(error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.createVehicleModel = createVehicleModel;
|
|
@@ -1 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteVehicleModel = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const deleteVehicleModel = async (modelId) => {
|
|
6
|
+
try {
|
|
7
|
+
const response = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleModel.deleteOne(modelId).toString(), {
|
|
8
|
+
method: core_1.HttpMethods.DELETE,
|
|
9
|
+
});
|
|
10
|
+
return response;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
console.error('Failed to delete vehicle model:', error);
|
|
14
|
+
return Promise.reject(error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.deleteVehicleModel = deleteVehicleModel;
|
|
@@ -1 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAllVehicleModels = void 0;
|
|
7
|
+
const qs_1 = __importDefault(require("qs"));
|
|
8
|
+
const core_1 = require("../../../../core");
|
|
9
|
+
const data_1 = require("../../data");
|
|
10
|
+
const getAllVehicleModels = async (page, searchQuery) => {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
try {
|
|
13
|
+
let getDTO = new data_1.VehicleModelGetDTO();
|
|
14
|
+
let options = new data_1.VehicleModelOptions();
|
|
15
|
+
if ((searchQuery !== null && searchQuery !== void 0 ? searchQuery : "").trim().length > 1) {
|
|
16
|
+
let filter = new data_1.VehicleModelFilter();
|
|
17
|
+
filter.search = searchQuery;
|
|
18
|
+
getDTO.filter = filter;
|
|
19
|
+
}
|
|
20
|
+
options.withMake = true;
|
|
21
|
+
options.page = (page !== null && page !== void 0 ? page : 0) + 1;
|
|
22
|
+
getDTO.options = options;
|
|
23
|
+
const endpoint = `${core_1.API_ENDPOINTS.vehicleModel.getAll.toString()}?${qs_1.default.stringify(getDTO.toPlain(), { arrayFormat: 'brackets', allowEmptyArrays: false, skipNulls: true })}`;
|
|
24
|
+
const response = await (0, core_1.apiRequest)(endpoint, {
|
|
25
|
+
method: core_1.HttpMethods.GET,
|
|
26
|
+
});
|
|
27
|
+
if (!response.success) {
|
|
28
|
+
throw Error((_a = response.message) !== null && _a !== void 0 ? _a : (_b = response.error) === null || _b === void 0 ? void 0 : _b.message);
|
|
29
|
+
}
|
|
30
|
+
return (_c = response.data) !== null && _c !== void 0 ? _c : [];
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error('Failed to fetch vehicle models:', error);
|
|
34
|
+
return Promise.reject(error);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.getAllVehicleModels = getAllVehicleModels;
|
|
@@ -1 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateVehicleModel = void 0;
|
|
4
|
+
const core_1 = require("../../../../core");
|
|
5
|
+
const updateVehicleModel = async (makeID, params) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
try {
|
|
8
|
+
const res = await (0, core_1.apiRequest)(core_1.API_ENDPOINTS.vehicleModel.updateOne(makeID), {
|
|
9
|
+
method: core_1.HttpMethods.PUT,
|
|
10
|
+
body: JSON.stringify(params),
|
|
11
|
+
});
|
|
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;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error('Failed to update model with id:', makeID, 'Error:', error);
|
|
19
|
+
return await Promise.reject(error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.updateVehicleModel = updateVehicleModel;
|
|
@@ -1 +1,20 @@
|
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CreateModel"), exports);
|
|
18
|
+
__exportStar(require("./GetAllModels"), exports);
|
|
19
|
+
__exportStar(require("./DeleteModel"), exports);
|
|
20
|
+
__exportStar(require("./UpdateModel"), exports);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { VehicleModelFilter, VehicleModelOptions, VehicleModelUniqueFilter } from '../utilities';
|
|
2
2
|
import { BaseCreateDTO, BaseUpdateDTO } from './BaseDTO';
|
|
3
|
-
import { VehicleBodyType } from '../models/VehicleBodyType';
|
|
4
3
|
import { Vehicle } from '../models/Vehicle';
|
|
5
4
|
import { VehicleMake } from '../models/VehicleMake';
|
|
6
5
|
export declare class VehicleModelGetDTO {
|
|
@@ -8,7 +7,7 @@ export declare class VehicleModelGetDTO {
|
|
|
8
7
|
options?: VehicleModelOptions;
|
|
9
8
|
validate(): string[];
|
|
10
9
|
static fromPlain(plain: Record<string, unknown>): VehicleModelGetDTO;
|
|
11
|
-
toPlain(): Record<string,
|
|
10
|
+
toPlain(): Record<string, any>;
|
|
12
11
|
}
|
|
13
12
|
export declare class VehicleModelGetUniqueDTO {
|
|
14
13
|
filter?: VehicleModelUniqueFilter;
|
|
@@ -26,7 +25,6 @@ export declare class VehicleModelCreateDTO extends BaseCreateDTO {
|
|
|
26
25
|
metaKeywords?: string;
|
|
27
26
|
make: VehicleMake;
|
|
28
27
|
vehicles?: Vehicle[];
|
|
29
|
-
bodyType: VehicleBodyType;
|
|
30
28
|
validate(): string[];
|
|
31
29
|
static fromPlain(plain: Record<string, unknown>): VehicleModelCreateDTO;
|
|
32
30
|
static toPlain(entity: any): Record<string, unknown>;
|
|
@@ -14,7 +14,6 @@ exports.DynamicModelDTO = exports.VehicleModelUpdateDTO = exports.VehicleModelCr
|
|
|
14
14
|
const class_validator_1 = require("class-validator");
|
|
15
15
|
const class_transformer_1 = require("class-transformer");
|
|
16
16
|
const BaseDTO_1 = require("./BaseDTO");
|
|
17
|
-
const VehicleBodyType_1 = require("../models/VehicleBodyType");
|
|
18
17
|
const Vehicle_1 = require("../models/Vehicle");
|
|
19
18
|
const VehicleMake_1 = require("../models/VehicleMake");
|
|
20
19
|
class VehicleModelGetDTO {
|
|
@@ -104,12 +103,6 @@ __decorate([
|
|
|
104
103
|
,
|
|
105
104
|
__metadata("design:type", Array)
|
|
106
105
|
], VehicleModelCreateDTO.prototype, "vehicles", void 0);
|
|
107
|
-
__decorate([
|
|
108
|
-
(0, class_validator_1.ValidateNested)(),
|
|
109
|
-
(0, class_transformer_1.Type)(() => VehicleBodyType_1.VehicleBodyType) // This transforms each object in the array to the OtherDetailsDTO class
|
|
110
|
-
,
|
|
111
|
-
__metadata("design:type", VehicleBodyType_1.VehicleBodyType)
|
|
112
|
-
], VehicleModelCreateDTO.prototype, "bodyType", void 0);
|
|
113
106
|
exports.VehicleModelCreateDTO = VehicleModelCreateDTO;
|
|
114
107
|
class VehicleModelUpdateDTO extends BaseDTO_1.BaseUpdateDTO {
|
|
115
108
|
validate() {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.5",
|
|
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",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"class-transformer": "^0.5.1",
|
|
38
38
|
"class-validator": "^0.14.1",
|
|
39
39
|
"dist": "^0.1.2",
|
|
40
|
-
"express": "^4.21.1"
|
|
40
|
+
"express": "^4.21.1",
|
|
41
|
+
"qs": "^6.13.1"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@types/express": "^4.17.13",
|