Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rhases-nodejs-commons

Package Overview
Dependencies
Maintainers
3
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rhases-nodejs-commons - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

3

dist/utils/base.controller.d.ts
/// <reference types="express" />
/// <reference types="mongoose" />
import { Request, Response } from 'express';
import { Model, Document } from 'mongoose';
import { Model, Document, DocumentQuery } from 'mongoose';
export declare function baseCtrlCreate(req: Request, res: Response, model: Model<Document>, options?: any): void;
export declare function baseCtrlFind(req: any, res: Response, model: Model<Document>): void;
export declare function baseCtrlFindWithQueryBuilder(req: Request, res: Response, model: Model<Document>, queryBuilder: (query: any) => DocumentQuery<any, any>): void;
export declare function baseCtrlFindById(req: Request, res: Response, model: Model<Document>): void;
export declare function baseCtrlUpdate(req: Request, res: Response, model: Model<Document>): void;
export declare function baseCtrlRemove(req: Request, res: Response, model: Model<Document>): void;

@@ -17,9 +17,15 @@ "use strict";

function baseCtrlFind(req, res, model) {
base_query_builder_1.queryBuilder(model)
.byUser(req.user)
.exec()
baseCtrlFindWithQueryBuilder(req, res, model, function (query) {
query.byUser(req.user);
return query;
});
}
exports.baseCtrlFind = baseCtrlFind;
function baseCtrlFindWithQueryBuilder(req, res, model, queryBuilder) {
base_query_builder_1.createQueryExecutor(model, queryBuilder)
.then(base_query_builder_1.execFindAndCound(req.query, res))
.then(controller_utils_1.respondWithResult(res))
.catch(controller_utils_1.handleError(res));
}
exports.baseCtrlFind = baseCtrlFind;
exports.baseCtrlFindWithQueryBuilder = baseCtrlFindWithQueryBuilder;
function baseCtrlFindById(req, res, model) {

@@ -26,0 +32,0 @@ entity_utils_1.findEntityById(model, req.params.id)

/// <reference types="mongoose" />
import { Model, Document } from 'mongoose';
/// <reference types="express" />
import { Model, Document, DocumentQuery } from 'mongoose';
import { Response } from 'express';
export declare function setBasicQueries(schema: any): any;
export declare function queryBuilder(model: Model<Document>): any;
export declare function createQueryExecutor(model: Model<Document>, queryBuilder: (query: DocumentQuery<any, any>) => DocumentQuery<any, any>): any;
export declare function execFindAndCound(query: any, res: Response): (queryExecutor: any) => any;
export declare function execCount(model: Model<Document>, queryBuilder: (query: DocumentQuery<any, any>) => DocumentQuery<any, any>): Promise<any>;
export declare function execFind(model: Model<Document>, queryBuilder: (query: DocumentQuery<any, any>) => DocumentQuery<any, any>, sortBy: string, currentPage: number, perPage: number): Promise<any>;
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = require("../logger");
var Q = require('q');
function setBasicQueries(schema) {

@@ -13,5 +15,45 @@ schema.query.byUser = function (user) {

//export var TicketSchema;
function queryBuilder(model) {
return model.find();
function createQueryExecutor(model, queryBuilder) {
var self = this;
var executor = {};
executor.execCount = function () {
return self.execCount(model, queryBuilder);
};
executor.execFind = function (sortBy, currentPage, perPage) {
return self.execFind(model, queryBuilder, sortBy, currentPage, perPage);
};
return Q.when(executor);
}
exports.queryBuilder = queryBuilder;
exports.createQueryExecutor = createQueryExecutor;
function execFindAndCound(query, res) {
return function (queryExecutor) {
var sortBy = query.sort;
var currentPage = query.page || 1;
var perPage = query.per_page || 200;
return queryExecutor
.execCount()
.then(function (totalCount) {
res.set('X-Total-Count', String(totalCount));
return queryExecutor.execFind(sortBy, currentPage, perPage);
});
};
}
exports.execFindAndCound = execFindAndCound;
//Query utils
function execCount(model, queryBuilder) {
logger_1.default.info(queryBuilder, model.collection.collectionName + ".execCount()");
return queryBuilder(model.count(null)).exec();
}
exports.execCount = execCount;
function execFind(model, queryBuilder, sortBy, currentPage, perPage) {
logger_1.default.info(queryBuilder, model.collection.collectionName + ".execFind()");
var query = queryBuilder(model.find());
if (sortBy)
query.sort(sortBy);
if (currentPage > 0 && perPage > 0)
query
.skip((currentPage - 1) * perPage)
.limit(perPage);
return query.exec();
}
exports.execFind = execFind;
{
"name": "rhases-nodejs-commons",
"version": "0.2.1",
"version": "0.2.2",
"description": "Node.js utilities",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc