asv-hlps 1.3.58 → 1.3.60

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.
@@ -0,0 +1,21 @@
1
+ import { Request, Response } from "express";
2
+ import { Entity } from "typeorm";
3
+ export declare class HlpCrud {
4
+ dataSource: any;
5
+ constructor(dataSource: any);
6
+ checkUniqProp(prop: string, model: any, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
7
+ toggleProp(id: number, prop: string, model: typeof Entity | any): Promise<any>;
8
+ create(tob: any, model: typeof Entity | any): any;
9
+ del(id: number, model: typeof Entity | any): any;
10
+ delete(id: number, model: typeof Entity | any): Promise<any>;
11
+ isActive(id: number, repository: any): Promise<any>;
12
+ isAvailable(id: number, repository: any): Promise<any>;
13
+ isPublished(id: number, repository: any): Promise<any>;
14
+ delMulti(tobs: any[], repository: any): any;
15
+ isExtern(id: number, repository: any): Promise<any>;
16
+ isIntern(id: number, repository: any): Promise<any>;
17
+ update(id: number, tob: any, model: typeof Entity | any): any;
18
+ save(tob: any, model: typeof Entity | any): any;
19
+ findById(id: string | number, model: typeof Entity | any): any;
20
+ private checkObj;
21
+ }
@@ -0,0 +1,200 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HlpCrud = void 0;
13
+ // import { dataSource } from "../../data-source";
14
+ class HlpCrud {
15
+ constructor(dataSource) {
16
+ this.dataSource = dataSource;
17
+ }
18
+ checkUniqProp(prop, model, req, res) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ try {
21
+ const reqName = req.body.name;
22
+ const reqId = req.body.id;
23
+ const obj = yield this.dataSource.manager.findOneBy(model, { [prop]: reqName });
24
+ // ------ no obj ------
25
+ if (!obj) {
26
+ return res.send(true);
27
+ }
28
+ // ------ if id ------
29
+ if (reqId) {
30
+ return reqId === obj.id ? res.send(true) : res.send(false);
31
+ }
32
+ else {
33
+ return res.send(false);
34
+ }
35
+ }
36
+ catch (error) {
37
+ console.log(error);
38
+ }
39
+ /* try {
40
+ const repository = dataSource.manager
41
+
42
+ const obj = await repository.findOneBy(model, {[prop]: req.body.name})
43
+ this.checkObj(obj, req.body.id, res)
44
+ } catch (error) {
45
+ console.log(error);
46
+ } */
47
+ });
48
+ }
49
+ toggleProp(id, prop, model) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ try {
52
+ const repo = this.dataSource.manager;
53
+ const tob = yield repo.findOneBy(model, { id: id });
54
+ if (tob) {
55
+ tob[prop] = !tob[prop];
56
+ return repo.save(tob);
57
+ }
58
+ }
59
+ catch (error) {
60
+ console.log(error);
61
+ }
62
+ });
63
+ }
64
+ create(tob, model) {
65
+ try {
66
+ return this.dataSource.manager.save(model, tob);
67
+ }
68
+ catch (error) {
69
+ console.log(error);
70
+ }
71
+ }
72
+ del(id, model) {
73
+ try {
74
+ // return repository.delete(id);
75
+ return this.dataSource.manager.delete(model, id);
76
+ }
77
+ catch (error) { }
78
+ }
79
+ delete(id, model) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ try {
82
+ const repo = this.dataSource.manager;
83
+ const tob = yield repo.findOneBy(model, { id: id });
84
+ if (tob) {
85
+ return repo.delete(model, tob.id);
86
+ }
87
+ }
88
+ catch (error) { }
89
+ });
90
+ }
91
+ isActive(id, repository) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ try {
94
+ const tob = yield repository.findOneByOrFail({ id });
95
+ if (tob) {
96
+ tob.isActive = !tob.isActive;
97
+ // return repository.update(tob.id, tob)
98
+ return repository.save(tob);
99
+ }
100
+ }
101
+ catch (error) { }
102
+ });
103
+ }
104
+ isAvailable(id, repository) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ try {
107
+ const tob = yield repository.findOneBy({ id });
108
+ if (tob) {
109
+ tob.isAvailable = !tob.isAvailable;
110
+ return repository.update(tob.id, tob);
111
+ }
112
+ }
113
+ catch (error) { }
114
+ });
115
+ }
116
+ isPublished(id, repository) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ try {
119
+ const tob = yield repository.findOneBy({ id });
120
+ if (tob) {
121
+ tob.isPublished = !tob.isPublished;
122
+ return repository.update(tob.id, tob);
123
+ }
124
+ }
125
+ catch (error) { }
126
+ });
127
+ }
128
+ delMulti(tobs, repository) {
129
+ try {
130
+ return repository.remove(tobs);
131
+ }
132
+ catch (error) { }
133
+ }
134
+ isExtern(id, repository) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ try {
137
+ const tob = yield repository.findOneByOrFail({ id });
138
+ tob.extern = !tob.extern;
139
+ return repository.update(tob.id, tob);
140
+ }
141
+ catch (error) {
142
+ console.log(error);
143
+ }
144
+ });
145
+ }
146
+ isIntern(id, repository) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ try {
149
+ const tob = yield repository.findOneByOrFail({ id });
150
+ tob.intern = !tob.intern;
151
+ return repository.update(tob.id, tob);
152
+ }
153
+ catch (error) {
154
+ console.log(error);
155
+ }
156
+ });
157
+ }
158
+ // update(id: number, repository: any, tob: any) {
159
+ // update(id: number, model: typeof Entity | any, tob: any) {
160
+ update(id, tob, model) {
161
+ try {
162
+ // return repository.update(id, tob);
163
+ // return dataSource.manager.save(model, tob);
164
+ return this.dataSource.manager.update(model, id, tob);
165
+ // return repository.save(tob);
166
+ }
167
+ catch (error) {
168
+ console.log(error);
169
+ }
170
+ }
171
+ // save(repository: any, tob: any) {
172
+ save(tob, model) {
173
+ try {
174
+ // return repository.save(tob);
175
+ return this.dataSource.manager.save(model, tob);
176
+ }
177
+ catch (error) { }
178
+ }
179
+ // findById(id: string | number, repository: any) {
180
+ findById(id, model) {
181
+ try {
182
+ // return repository.findOneBy({ id });
183
+ return this.dataSource.manager.findOneBy(model, { id });
184
+ }
185
+ catch (error) { }
186
+ }
187
+ checkObj(obj, reqId, res) {
188
+ if (!obj) {
189
+ return res.send(true);
190
+ }
191
+ // ------ if id ------
192
+ if (reqId) {
193
+ return reqId === obj.id ? res.send(true) : res.send(false);
194
+ }
195
+ else {
196
+ return res.send(false);
197
+ }
198
+ }
199
+ }
200
+ exports.HlpCrud = HlpCrud;
@@ -1,4 +1,4 @@
1
- import { Estate, Housing } from "../../estates/models";
1
+ import { Estate, Housing } from "../../estates";
2
2
  import UserAbs from "./UserAbs";
3
3
  export default interface UserNotarial extends UserAbs {
4
4
  estates?: Estate[];
@@ -0,0 +1,21 @@
1
+ import { Request, Response } from "express";
2
+ import { Entity } from "typeorm";
3
+ export declare class HlpCrud {
4
+ dataSource: any;
5
+ constructor(dataSource: any);
6
+ checkUniqProp(prop: string, model: any, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
7
+ toggleProp(id: number, prop: string, model: typeof Entity | any): Promise<any>;
8
+ create(tob: any, model: typeof Entity | any): any;
9
+ del(id: number, model: typeof Entity | any): any;
10
+ delete(id: number, model: typeof Entity | any): Promise<any>;
11
+ isActive(id: number, repository: any): Promise<any>;
12
+ isAvailable(id: number, repository: any): Promise<any>;
13
+ isPublished(id: number, repository: any): Promise<any>;
14
+ delMulti(tobs: any[], repository: any): any;
15
+ isExtern(id: number, repository: any): Promise<any>;
16
+ isIntern(id: number, repository: any): Promise<any>;
17
+ update(id: number, tob: any, model: typeof Entity | any): any;
18
+ save(tob: any, model: typeof Entity | any): any;
19
+ findById(id: string | number, model: typeof Entity | any): any;
20
+ private checkObj;
21
+ }
@@ -0,0 +1,196 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ // import { dataSource } from "../../data-source";
11
+ export class HlpCrud {
12
+ constructor(dataSource) {
13
+ this.dataSource = dataSource;
14
+ }
15
+ checkUniqProp(prop, model, req, res) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ const reqName = req.body.name;
19
+ const reqId = req.body.id;
20
+ const obj = yield this.dataSource.manager.findOneBy(model, { [prop]: reqName });
21
+ // ------ no obj ------
22
+ if (!obj) {
23
+ return res.send(true);
24
+ }
25
+ // ------ if id ------
26
+ if (reqId) {
27
+ return reqId === obj.id ? res.send(true) : res.send(false);
28
+ }
29
+ else {
30
+ return res.send(false);
31
+ }
32
+ }
33
+ catch (error) {
34
+ console.log(error);
35
+ }
36
+ /* try {
37
+ const repository = dataSource.manager
38
+
39
+ const obj = await repository.findOneBy(model, {[prop]: req.body.name})
40
+ this.checkObj(obj, req.body.id, res)
41
+ } catch (error) {
42
+ console.log(error);
43
+ } */
44
+ });
45
+ }
46
+ toggleProp(id, prop, model) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ try {
49
+ const repo = this.dataSource.manager;
50
+ const tob = yield repo.findOneBy(model, { id: id });
51
+ if (tob) {
52
+ tob[prop] = !tob[prop];
53
+ return repo.save(tob);
54
+ }
55
+ }
56
+ catch (error) {
57
+ console.log(error);
58
+ }
59
+ });
60
+ }
61
+ create(tob, model) {
62
+ try {
63
+ return this.dataSource.manager.save(model, tob);
64
+ }
65
+ catch (error) {
66
+ console.log(error);
67
+ }
68
+ }
69
+ del(id, model) {
70
+ try {
71
+ // return repository.delete(id);
72
+ return this.dataSource.manager.delete(model, id);
73
+ }
74
+ catch (error) { }
75
+ }
76
+ delete(id, model) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ try {
79
+ const repo = this.dataSource.manager;
80
+ const tob = yield repo.findOneBy(model, { id: id });
81
+ if (tob) {
82
+ return repo.delete(model, tob.id);
83
+ }
84
+ }
85
+ catch (error) { }
86
+ });
87
+ }
88
+ isActive(id, repository) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ try {
91
+ const tob = yield repository.findOneByOrFail({ id });
92
+ if (tob) {
93
+ tob.isActive = !tob.isActive;
94
+ // return repository.update(tob.id, tob)
95
+ return repository.save(tob);
96
+ }
97
+ }
98
+ catch (error) { }
99
+ });
100
+ }
101
+ isAvailable(id, repository) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ try {
104
+ const tob = yield repository.findOneBy({ id });
105
+ if (tob) {
106
+ tob.isAvailable = !tob.isAvailable;
107
+ return repository.update(tob.id, tob);
108
+ }
109
+ }
110
+ catch (error) { }
111
+ });
112
+ }
113
+ isPublished(id, repository) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ try {
116
+ const tob = yield repository.findOneBy({ id });
117
+ if (tob) {
118
+ tob.isPublished = !tob.isPublished;
119
+ return repository.update(tob.id, tob);
120
+ }
121
+ }
122
+ catch (error) { }
123
+ });
124
+ }
125
+ delMulti(tobs, repository) {
126
+ try {
127
+ return repository.remove(tobs);
128
+ }
129
+ catch (error) { }
130
+ }
131
+ isExtern(id, repository) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ try {
134
+ const tob = yield repository.findOneByOrFail({ id });
135
+ tob.extern = !tob.extern;
136
+ return repository.update(tob.id, tob);
137
+ }
138
+ catch (error) {
139
+ console.log(error);
140
+ }
141
+ });
142
+ }
143
+ isIntern(id, repository) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ try {
146
+ const tob = yield repository.findOneByOrFail({ id });
147
+ tob.intern = !tob.intern;
148
+ return repository.update(tob.id, tob);
149
+ }
150
+ catch (error) {
151
+ console.log(error);
152
+ }
153
+ });
154
+ }
155
+ // update(id: number, repository: any, tob: any) {
156
+ // update(id: number, model: typeof Entity | any, tob: any) {
157
+ update(id, tob, model) {
158
+ try {
159
+ // return repository.update(id, tob);
160
+ // return dataSource.manager.save(model, tob);
161
+ return this.dataSource.manager.update(model, id, tob);
162
+ // return repository.save(tob);
163
+ }
164
+ catch (error) {
165
+ console.log(error);
166
+ }
167
+ }
168
+ // save(repository: any, tob: any) {
169
+ save(tob, model) {
170
+ try {
171
+ // return repository.save(tob);
172
+ return this.dataSource.manager.save(model, tob);
173
+ }
174
+ catch (error) { }
175
+ }
176
+ // findById(id: string | number, repository: any) {
177
+ findById(id, model) {
178
+ try {
179
+ // return repository.findOneBy({ id });
180
+ return this.dataSource.manager.findOneBy(model, { id });
181
+ }
182
+ catch (error) { }
183
+ }
184
+ checkObj(obj, reqId, res) {
185
+ if (!obj) {
186
+ return res.send(true);
187
+ }
188
+ // ------ if id ------
189
+ if (reqId) {
190
+ return reqId === obj.id ? res.send(true) : res.send(false);
191
+ }
192
+ else {
193
+ return res.send(false);
194
+ }
195
+ }
196
+ }
@@ -1,4 +1,4 @@
1
- import { Estate, Housing } from "../../estates/models";
1
+ import { Estate, Housing } from "../../estates";
2
2
  import UserAbs from "./UserAbs";
3
3
  export default interface UserNotarial extends UserAbs {
4
4
  estates?: Estate[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.3.58",
3
+ "version": "1.3.60",
4
4
  "description": "helpers",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -17,6 +17,7 @@
17
17
  "license": "ISC",
18
18
  "devDependencies": {
19
19
  "@types/bcryptjs": "^2.4.6",
20
+ "@types/express": "^4.17.21",
20
21
  "@types/lodash": "^4.14.202",
21
22
  "@types/pdfmake": "^0.2.9",
22
23
  "@types/randomatic": "^3.1.5",
@@ -28,6 +29,7 @@
28
29
  "bcryptjs": "^2.4.3",
29
30
  "classnames": "^2.5.1",
30
31
  "dayjs": "^1.11.10",
32
+ "express": "^4.18.2",
31
33
  "jwt-decode": "^4.0.0",
32
34
  "lodash": "^4.17.21",
33
35
  "pdfmake": "^0.2.9",