@dwtechs/antity-pgsql 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -181,11 +181,11 @@ class SQLEntity {
181
181
  delete: () => string;
182
182
  return: (prop: string) => string;
183
183
  };
184
- get(req: Request, res: Response, next: NextFunction): void;
185
- add(req: Request, res: Response, next: NextFunction): Promise<void>;
186
- update(req: Request, res: Response, next: NextFunction): Promise<void>;
187
- archive(req: Request, res: Response, next: NextFunction): Promise<void>;
188
- delete(req: Request, res: Response, next: NextFunction): void;
184
+ get: (req: Request, res: Response, next: NextFunction) => void;
185
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
186
+ update: (req: Request, res: Response, next: NextFunction) => Promise<void>;
187
+ archive: (req: Request, res: Response, next: NextFunction) => Promise<void>;
188
+ delete: (req: Request, res: Response, next: NextFunction) => void;
189
189
 
190
190
  }
191
191
 
@@ -87,13 +87,11 @@ declare class SQLEntity extends Entity {
87
87
  delete: () => string;
88
88
  return: (prop: string) => string;
89
89
  };
90
- get(req: Request, res: Response, next: NextFunction): void;
91
- add(req: Request, res: Response, next: NextFunction): Promise<void>;
92
- update(req: Request, res: Response, next: NextFunction): Promise<void>;
93
- archive(req: Request, res: Response, next: NextFunction): Promise<void>;
94
- delete(req: Request, res: Response, next: NextFunction): void;
95
- private cleanFilters;
96
- private mapProps;
90
+ get: (req: Request, res: Response, next: NextFunction) => void;
91
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
92
+ update: (req: Request, res: Response, next: NextFunction) => Promise<void>;
93
+ archive: (req: Request, res: Response, next: NextFunction) => Promise<void>;
94
+ delete: (req: Request, res: Response, next: NextFunction) => void;
97
95
  }
98
96
 
99
97
  declare function filter(
@@ -450,45 +450,31 @@ class SQLEntity extends Entity {
450
450
  return this.ins.rtn(prop);
451
451
  }
452
452
  };
453
- this._table = name;
454
- for (const p of properties) {
455
- this.mapProps(p.methods, p.key);
456
- }
457
- }
458
- get table() {
459
- return this._table;
460
- }
461
- set table(table) {
462
- if (!isString(table, "!0"))
463
- throw new Error('table must be a string of length > 0');
464
- this._table = table;
465
- }
466
- get(req, res, next) {
467
- var _a;
468
- const l = res.locals;
469
- const b = req.body;
470
- const first = (_a = b === null || b === void 0 ? void 0 : b.first) !== null && _a !== void 0 ? _a : 0;
471
- const rows = b.rows || null;
472
- const sortField = b.sortField || null;
473
- const sortOrder = b.sortOrder === -1 || b.sortOrder === "DESC" ? "DESC" : "ASC";
474
- const filters = this.cleanFilters(b.filters) || null;
475
- const pagination = b.pagination || false;
476
- const dbClient = l.dbClient || null;
477
- log.debug(`get(first='${first}', rows='${rows}',
453
+ this.get = (req, res, next) => {
454
+ var _a;
455
+ const l = res.locals;
456
+ const b = req.body;
457
+ const first = (_a = b === null || b === void 0 ? void 0 : b.first) !== null && _a !== void 0 ? _a : 0;
458
+ const rows = b.rows || null;
459
+ const sortField = b.sortField || null;
460
+ const sortOrder = b.sortOrder === -1 || b.sortOrder === "DESC" ? "DESC" : "ASC";
461
+ const filters = this.cleanFilters(b.filters) || null;
462
+ const pagination = b.pagination || false;
463
+ const dbClient = l.dbClient || null;
464
+ log.debug(`get(first='${first}', rows='${rows}',
478
465
  sortOrder='${sortOrder}', sortField='${sortField}',
479
466
  pagination=${pagination}, filters=${JSON.stringify(filters)}`);
480
- const { filterClause, args } = filter(first, rows, sortField, sortOrder, filters);
481
- const q = this.sel.query(this._table, pagination) + filterClause;
482
- this.sel.execute(q, args, dbClient)
483
- .then((r) => {
484
- l.rows = r.rows;
485
- l.total = r.total;
486
- next();
487
- })
488
- .catch((err) => next(err));
489
- }
490
- add(req, res, next) {
491
- return __awaiter(this, void 0, void 0, function* () {
467
+ const { filterClause, args } = filter(first, rows, sortField, sortOrder, filters);
468
+ const q = this.sel.query(this._table, pagination) + filterClause;
469
+ this.sel.execute(q, args, dbClient)
470
+ .then((r) => {
471
+ l.rows = r.rows;
472
+ l.total = r.total;
473
+ next();
474
+ })
475
+ .catch((err) => next(err));
476
+ };
477
+ this.add = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
492
478
  const l = res.locals;
493
479
  const rows = req.body.rows;
494
480
  const dbClient = l.dbClient || null;
@@ -514,9 +500,7 @@ class SQLEntity extends Entity {
514
500
  l.rows = flatten(chunks);
515
501
  next();
516
502
  });
517
- }
518
- update(req, res, next) {
519
- return __awaiter(this, void 0, void 0, function* () {
503
+ this.update = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
520
504
  const l = res.locals;
521
505
  const rows = req.body.rows;
522
506
  const dbClient = l.dbClient || null;
@@ -535,9 +519,7 @@ class SQLEntity extends Entity {
535
519
  }
536
520
  next();
537
521
  });
538
- }
539
- archive(req, res, next) {
540
- return __awaiter(this, void 0, void 0, function* () {
522
+ this.archive = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
541
523
  const l = res.locals;
542
524
  let rows = req.body.rows;
543
525
  const dbClient = l.dbClient || null;
@@ -557,15 +539,27 @@ class SQLEntity extends Entity {
557
539
  }
558
540
  next();
559
541
  });
542
+ this.delete = (req, res, next) => {
543
+ const date = req.body.date;
544
+ const dbClient = res.locals.dbClient || null;
545
+ log.debug(`delete archived`);
546
+ const q = query(this._table);
547
+ execute(date, q, dbClient)
548
+ .then(() => next())
549
+ .catch((err) => next(err));
550
+ };
551
+ this._table = name;
552
+ for (const p of properties) {
553
+ this.mapProps(p.methods, p.key);
554
+ }
555
+ }
556
+ get table() {
557
+ return this._table;
560
558
  }
561
- delete(req, res, next) {
562
- const date = req.body.date;
563
- const dbClient = res.locals.dbClient || null;
564
- log.debug(`delete archived`);
565
- const q = query(this._table);
566
- execute(date, q, dbClient)
567
- .then(() => next())
568
- .catch((err) => next(err));
559
+ set table(table) {
560
+ if (!isString(table, "!0"))
561
+ throw new Error('table must be a string of length > 0');
562
+ this._table = table;
569
563
  }
570
564
  cleanFilters(filters) {
571
565
  for (const k in filters) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity-pgsql",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Open source library for easy entity management",
5
5
  "keywords": [
6
6
  "entities"
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@dwtechs/checkard": "3.2.3",
40
40
  "@dwtechs/winstan": "0.4.0",
41
- "@dwtechs/antity": "0.9.0",
41
+ "@dwtechs/antity": "0.9.2",
42
42
  "@dwtechs/sparray": "0.2.0",
43
43
  "pg": "8.13.1"
44
44
  },