elemento-alpha-tools 1.0.2 → 1.0.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.
- package/dist/crud/AvailablePlataformManager.d.ts +2 -2
- package/dist/crud/ComponentManager.d.ts +12 -0
- package/dist/crud/ComponentManager.js +49 -0
- package/dist/crud/ComponentManager.js.map +1 -1
- package/dist/crud/test/ComponentMocks.d.ts +2 -0
- package/dist/crud/test/ComponentMocks.js +63 -0
- package/dist/crud/test/ComponentMocks.js.map +1 -0
- package/package.json +4 -4
|
@@ -4,7 +4,7 @@ export interface IAvailablePlatform {
|
|
|
4
4
|
userId: number;
|
|
5
5
|
roleId: number;
|
|
6
6
|
platformId: number;
|
|
7
|
-
|
|
7
|
+
restrictions: any;
|
|
8
8
|
updatedAt?: string;
|
|
9
9
|
createdAt?: string;
|
|
10
10
|
config?: AxiosRequestConfig;
|
|
@@ -13,6 +13,6 @@ export interface IAvailablePlatformSearchDetails {
|
|
|
13
13
|
userId?: number;
|
|
14
14
|
roleId?: number;
|
|
15
15
|
platformId?: number;
|
|
16
|
-
|
|
16
|
+
restrictions?: any;
|
|
17
17
|
config?: AxiosRequestConfig;
|
|
18
18
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from "axios";
|
|
2
2
|
import { IPlatform } from "./PlatformManager";
|
|
3
|
+
import { CrudServiceManager, StandardIdRequestDefinition } from "itrm-tools";
|
|
3
4
|
export interface IComponent {
|
|
4
5
|
componentId?: number;
|
|
5
6
|
platformId?: number;
|
|
@@ -31,3 +32,14 @@ export interface IComponentSearchDetails {
|
|
|
31
32
|
details?: IComponentDetails;
|
|
32
33
|
config?: AxiosRequestConfig;
|
|
33
34
|
}
|
|
35
|
+
export declare class ComponentManager extends CrudServiceManager<IComponentDetails, IComponent> {
|
|
36
|
+
private url;
|
|
37
|
+
constructor(url: string);
|
|
38
|
+
findById(id: StandardIdRequestDefinition): Promise<IComponent | undefined>;
|
|
39
|
+
findByPlatformId(details: IComponentSearchDetails): Promise<IComponent | undefined>;
|
|
40
|
+
find(details: IComponentSearchDetails): Promise<IComponent | undefined>;
|
|
41
|
+
findAll(details: IComponentSearchDetails): Promise<IComponent[] | undefined>;
|
|
42
|
+
create(details: IComponentSearchDetails): Promise<IComponent | undefined>;
|
|
43
|
+
modify(component: IComponent): Promise<any>;
|
|
44
|
+
destroy(component: IComponent): Promise<any>;
|
|
45
|
+
}
|
|
@@ -1,3 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ComponentManager = void 0;
|
|
13
|
+
const itrm_tools_1 = require("itrm-tools");
|
|
14
|
+
class ComponentManager extends itrm_tools_1.CrudServiceManager {
|
|
15
|
+
constructor(url) {
|
|
16
|
+
super();
|
|
17
|
+
this.url = url;
|
|
18
|
+
}
|
|
19
|
+
findById(id) {
|
|
20
|
+
return this.sendFinding(`${this.url}/components?id=${id.id}`, id.config);
|
|
21
|
+
}
|
|
22
|
+
findByPlatformId(details) {
|
|
23
|
+
return this.sendFinding(`${this.url}/components?platformId=${details.platformId}`, details.config);
|
|
24
|
+
}
|
|
25
|
+
find(details) {
|
|
26
|
+
return this.sendFinding(`${this.url}/components?name=${details.name}`, details.config);
|
|
27
|
+
}
|
|
28
|
+
findAll(details) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
let roles = [], limit = 100, offset = 0, isEmpty = false;
|
|
31
|
+
do {
|
|
32
|
+
let values = yield this.sendAllFinding(`${this.url}/components?limit=${limit}&offset=${offset}`, details.config);
|
|
33
|
+
if (values)
|
|
34
|
+
roles = roles.concat(values);
|
|
35
|
+
isEmpty = values == undefined || values.length == 0;
|
|
36
|
+
offset += limit;
|
|
37
|
+
} while (!isEmpty);
|
|
38
|
+
return roles;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
create(details) {
|
|
42
|
+
return this.sendCreation(`${this.url}/components`, { platformId: details.platformId, name: details.name, details: details.details }, details.config);
|
|
43
|
+
}
|
|
44
|
+
modify(component) {
|
|
45
|
+
return this.sendModification(`${this.url}/components/${component.componentId}`, { platformId: component.platformId, name: component.name, details: component.details }, component.config);
|
|
46
|
+
}
|
|
47
|
+
destroy(component) {
|
|
48
|
+
return this.sendDestuction(`${this.url}/components/${component.componentId}`, component.config);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ComponentManager = ComponentManager;
|
|
3
52
|
//# sourceMappingURL=ComponentManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentManager.js","sourceRoot":"","sources":["../../src/crud/ComponentManager.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"ComponentManager.js","sourceRoot":"","sources":["../../src/crud/ComponentManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,2CAA6E;AAmC7E,MAAa,gBAAiB,SAAQ,+BAAiD;IAInF,YAAY,GAAW;QACnB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAEM,QAAQ,CAAE,EAA+B;QAC5C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,kBAAkB,EAAE,CAAC,EAAE,EAAE,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AAqB;QACjC,OAAO,IAAI,CAAC,gBAAgB,CAC1B,GAAG,IAAI,CAAC,GAAG,eAAe,SAAS,CAAC,WAAW,EAAE,EACjD,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,EACtF,SAAS,CAAC,MAAM,CACjB,CAAC;IACJ,CAAC;IAEM,OAAO,CAAC,SAAqB;QAClC,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,GAAG,eAAe,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAClG,CAAC;CAEN;AArDD,4CAqDC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyComponentMocks = applyComponentMocks;
|
|
4
|
+
var components = {};
|
|
5
|
+
function applyComponentMocks(mock) {
|
|
6
|
+
mock.onGet(/\/components\?id=[a-zA-Z0-9]+/).reply((config) => {
|
|
7
|
+
let searchedId = config.url ? config.url.split("id=")[1] : "";
|
|
8
|
+
if (components[searchedId])
|
|
9
|
+
return [200, { result: [components[searchedId]] }];
|
|
10
|
+
return [200, { result: [] }];
|
|
11
|
+
});
|
|
12
|
+
mock.onGet(/\/components\?platformId=[a-zA-Z0-9]+/).reply((config) => {
|
|
13
|
+
let searchedPlatformId = config.url ? config.url.split("platformId=")[1] : "";
|
|
14
|
+
if (components[searchedPlatformId])
|
|
15
|
+
return [200, { result: [components[searchedPlatformId]] }];
|
|
16
|
+
return [200, { result: [] }];
|
|
17
|
+
});
|
|
18
|
+
mock.onGet(/\/components\?name=[a-zA-Z0-9]+/).reply((config) => {
|
|
19
|
+
let searchedRole = config.url ? config.url.split("name=")[1] : "";
|
|
20
|
+
for (let key of Object.keys(components))
|
|
21
|
+
if (components[key].name === searchedRole)
|
|
22
|
+
return [200, { result: [components[key]] }];
|
|
23
|
+
return [200, { result: [] }];
|
|
24
|
+
});
|
|
25
|
+
mock.onPost(/\/components/).reply((config) => {
|
|
26
|
+
let data = JSON.parse(config.data);
|
|
27
|
+
for (let key of Object.keys(components))
|
|
28
|
+
if (components[key].component === components.name)
|
|
29
|
+
return [
|
|
30
|
+
400,
|
|
31
|
+
{
|
|
32
|
+
status: "Error",
|
|
33
|
+
type: "SequelizeUniqueConstraintError",
|
|
34
|
+
error: "Validation error",
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
let item = {
|
|
38
|
+
componentId: Object.keys(components).length + 1,
|
|
39
|
+
platformId: data.platformId,
|
|
40
|
+
name: data.name,
|
|
41
|
+
details: data.details,
|
|
42
|
+
};
|
|
43
|
+
components["" + item.componentId] = item;
|
|
44
|
+
return [200, { items: [components["" + item.componentId]] }];
|
|
45
|
+
});
|
|
46
|
+
mock.onPut(/\/components\/[0-9]+/).reply((config) => {
|
|
47
|
+
let componentId = config.url ? config.url.split("components/")[1] : "";
|
|
48
|
+
if (components[componentId]) {
|
|
49
|
+
let data = JSON.parse(config.data);
|
|
50
|
+
components[componentId] = Object.assign(Object.assign({}, components[componentId]), data);
|
|
51
|
+
return [200, { status: "Ok", message: "1 item was updated" }];
|
|
52
|
+
}
|
|
53
|
+
return [200, { status: "Ok", message: "0 items were updated" }];
|
|
54
|
+
});
|
|
55
|
+
mock.onDelete(/\/components\/[a-zA-Z0-9]+/).reply((config) => {
|
|
56
|
+
let searchComponentId = config.url ? config.url.split[1] : "";
|
|
57
|
+
for (let key of Object.keys(components))
|
|
58
|
+
if (components[key].componentId == parseInt(searchComponentId))
|
|
59
|
+
delete components[key];
|
|
60
|
+
return [200, { status: "Ok", message: "1 item was deleted" }];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=ComponentMocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentMocks.js","sourceRoot":"","sources":["../../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,IAAI,EAAE,OAAO,EAAE,oBAAoB,EAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AAEP,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elemento-alpha-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Librería para los servicios de elemento alpha",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,19 +31,19 @@
|
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/crypto-js": "^4.2.2",
|
|
34
|
-
"@types/jest": "^29.5.
|
|
34
|
+
"@types/jest": "^29.5.14",
|
|
35
35
|
"@types/morgan": "^1.9.9",
|
|
36
36
|
"@types/node": "^22.5.5",
|
|
37
37
|
"jest": "^29.7.0",
|
|
38
38
|
"rimraf": "^6.0.1",
|
|
39
39
|
"ts-jest": "^29.2.5",
|
|
40
|
-
"typescript": "^5.6.
|
|
40
|
+
"typescript": "^5.6.3"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"axios": "^1.7.7",
|
|
44
44
|
"crypto-js": "^4.2.0",
|
|
45
45
|
"dotenv": "^16.4.5",
|
|
46
|
-
"itrm-tools": "^1.1.
|
|
46
|
+
"itrm-tools": "^1.1.13",
|
|
47
47
|
"morgan": "^1.10.0"
|
|
48
48
|
},
|
|
49
49
|
"optionalDependencies": {
|