@ccci/micro-server 1.0.103 → 1.0.105

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
@@ -118991,6 +118991,7 @@ class Uploader {
118991
118991
  let newName = new Date;
118992
118992
  let path3 = `/${bucket}/${dir}/${newName.getTime()}`;
118993
118993
  console.log("path :>> ", path3);
118994
+ console.log("Uploader.client :>> ", Uploader.client);
118994
118995
  let etag = await Uploader.client.putObject(bucket, `${dir}/${newName.getTime()}`, file.data, file.size, { "Content-type": file.mimetype });
118995
118996
  console.log("etag :>> ", etag);
118996
118997
  response4.push({
@@ -119316,11 +119317,22 @@ class BaseRouter {
119316
119317
  res.status(422).json(error);
119317
119318
  }
119318
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
+ }
119319
119330
  getMapping = () => {
119320
119331
  return [
119321
119332
  { method: GET, path: "/", function: this.get },
119322
119333
  { method: POST, path: "/", function: this.post },
119323
119334
  { method: GET, path: "/archives", function: this.archives },
119335
+ { method: GET, path: "/count", function: this.count },
119324
119336
  { method: GET, path: "/:id", function: this.getId },
119325
119337
  { method: PUT, path: "/:id", function: this.update },
119326
119338
  { method: DELETE, path: "/:id", function: this.delete },
@@ -119653,6 +119665,21 @@ class BaseController {
119653
119665
  throw ErrorResponseHandler(error);
119654
119666
  }
119655
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
+ }
119656
119683
  async beforeCreate(req) {
119657
119684
  }
119658
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.103",
3
+ "version": "1.0.105",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",