@ccci/micro-server 1.0.104 → 1.0.106

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/index.js CHANGED
@@ -119317,12 +119317,23 @@ class BaseRouter {
119317
119317
  res.status(422).json(error);
119318
119318
  }
119319
119319
  }
119320
+ async count(req, res, next) {
119321
+ let response4;
119322
+ try {
119323
+ response4 = await this.controller.count(req, res, next);
119324
+ res.status(200).json(response4);
119325
+ } catch (error) {
119326
+ Logger.error(error);
119327
+ res.status(422).json(error);
119328
+ }
119329
+ }
119320
119330
  getMapping = () => {
119321
119331
  return [
119322
119332
  { method: GET, path: "/", function: this.get },
119323
119333
  { method: POST, path: "/", function: this.post },
119324
- { method: GET, path: "/archives", function: this.archives },
119325
119334
  { method: GET, path: "/:id", function: this.getId },
119335
+ { method: GET, path: "/archives", function: this.archives },
119336
+ { method: GET, path: "/count", function: this.count },
119326
119337
  { method: PUT, path: "/:id", function: this.update },
119327
119338
  { method: DELETE, path: "/:id", function: this.delete },
119328
119339
  { method: PUT, path: "/restore/:id", function: this.restore }
@@ -119654,6 +119665,21 @@ class BaseController {
119654
119665
  throw ErrorResponseHandler(error);
119655
119666
  }
119656
119667
  }
119668
+ async count(req, res, next) {
119669
+ try {
119670
+ let query = req.query;
119671
+ let options = ConstructQuery(query);
119672
+ const count = await this._model?.count({
119673
+ where: options.where,
119674
+ attributes: options.attributes,
119675
+ include: options.includes
119676
+ });
119677
+ return { count: count ? count : 0 };
119678
+ } catch (error) {
119679
+ Logger.error(error);
119680
+ throw ErrorResponseHandler(error);
119681
+ }
119682
+ }
119657
119683
  async beforeCreate(req) {
119658
119684
  }
119659
119685
  async afterCreate(req, rec) {
@@ -59,6 +59,16 @@ export default class BaseController {
59
59
  */
60
60
  archives(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
61
61
  restore(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
62
+ /**
63
+ * count total number of records
64
+ * @param req
65
+ * @param res
66
+ * @param next
67
+ * @returns
68
+ */
69
+ count(req: Request, res: Response, next?: NextFunction): Promise<{
70
+ count: number;
71
+ }>;
62
72
  /**
63
73
  * ###############################################################
64
74
  * ###################### LIFE CYCLE HOOKS #######################
@@ -58,6 +58,13 @@ export default class BaseRouter<T extends BaseController> {
58
58
  * @param next
59
59
  */
60
60
  restore(req: Request, res: Response, next: NextFunction): Promise<void>;
61
+ /**
62
+ * /count route
63
+ * @param req
64
+ * @param res
65
+ * @param next
66
+ */
67
+ count(req: Request, res: Response, next: NextFunction): Promise<void>;
61
68
  /**
62
69
  * @description default mappings that will be inherited across all router class
63
70
  * @returns {Array} mappings
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccci/micro-server",
3
- "version": "1.0.104",
3
+ "version": "1.0.106",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",