@ikoabo/server
Advanced tools
Comparing version 1.1.23 to 1.1.24
@@ -13,3 +13,3 @@ import { SERVER_STATUS, Logger } from "@ikoabo/core"; | ||
constructor(logger: string, model: mongoose.Model<D>, opts?: ICRUDOptions); | ||
create(data: any | any[]): Promise<D>; | ||
create(data: any | any[]): Promise<D | D[]>; | ||
private _prepareQuery; | ||
@@ -19,6 +19,14 @@ update(queryId: string | any, dataSet?: any, update?: any, options?: any): Promise<D>; | ||
fetchAll(queryId: any, options?: any, populate?: string[], sort?: any, skip?: number, limit?: number): mongoose.QueryCursor<D>; | ||
fetchRaw(queryId: any, options?: any, populate?: string[], sort?: any, skip?: number, limit?: number): mongoose.Query<mongoose.EnforceDocument<D[], any>, mongoose.EnforceDocument<D, any>>; | ||
fetchRaw(queryId: any, options?: any, populate?: string[], sort?: any, skip?: number, limit?: number): mongoose.DocumentQuery<D[], D>; | ||
delete(queryId: string | any): Promise<D>; | ||
protected _updateStatus(queryId: string, status: SERVER_STATUS): Promise<D>; | ||
isValidOwner(path: string, owner?: string): (req: Request, res: Response, next: NextFunction) => void; | ||
enable(id: string): Promise<D>; | ||
disable(id: string): Promise<D>; | ||
private _fieldOp; | ||
addToSet(id: string, field: string, value: any): Promise<D>; | ||
push(id: string, field: string, value: any): Promise<D>; | ||
pushAll(id: string, field: string, value: any): Promise<D>; | ||
pull(id: string, field: string, value: any): Promise<D>; | ||
pullAll(id: string, field: string, value: any): Promise<D>; | ||
} |
@@ -45,3 +45,2 @@ "use strict"; | ||
} | ||
options["rawResult"] = false; | ||
if (core_1.Objects.get(options, "new", null) === null) { | ||
@@ -56,2 +55,3 @@ options["new"] = true; | ||
boError: core_1.SERVER_ERRORS.OBJECT_NOT_FOUND, | ||
boStr: "object-not-found", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
@@ -89,2 +89,3 @@ }); | ||
boError: core_1.SERVER_ERRORS.OBJECT_NOT_FOUND, | ||
boStr: "object-not-found", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
@@ -147,2 +148,3 @@ }); | ||
boError: core_1.SERVER_ERRORS.OBJECT_NOT_FOUND, | ||
boStr: "object-not-found", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
@@ -167,2 +169,3 @@ }); | ||
boError: core_1.SERVER_ERRORS.OBJECT_NOT_FOUND, | ||
boStr: "object-not-found", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
@@ -179,4 +182,12 @@ }); | ||
return (req, res, next) => { | ||
const ownerStr = owner ? core_1.Objects.get(res, owner, null) : null; | ||
this.fetch(core_1.Objects.get(req, path, "")) | ||
const objId = core_1.Objects.get(req, path, null); | ||
const ownerId = owner ? core_1.Objects.get(res, owner, null) : null; | ||
if (!objId) { | ||
return next({ | ||
boError: core_1.SERVER_ERRORS.OBJECT_NOT_FOUND, | ||
boStr: "object-not-found", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
}); | ||
} | ||
this.fetch(objId) | ||
.then((value) => { | ||
@@ -186,8 +197,10 @@ if (!value || value.status !== core_1.SERVER_STATUS.ENABLED) { | ||
boError: core_1.SERVER_ERRORS.OBJECT_NOT_FOUND, | ||
boStr: "object-not-found", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
}); | ||
} | ||
if (ownerStr && value.owner.toString() !== ownerStr) { | ||
if (ownerId && value.owner.toString() !== ownerId) { | ||
return next({ | ||
boError: core_1.SERVER_ERRORS.INVALID_OWNER, | ||
boStr: "invalid-owner", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_FORBIDDEN | ||
@@ -202,4 +215,35 @@ }); | ||
} | ||
enable(id) { | ||
const query = { _id: id, status: core_1.SERVER_STATUS.DISABLED }; | ||
return this._updateStatus(query, core_1.SERVER_STATUS.ENABLED); | ||
} | ||
disable(id) { | ||
const query = { _id: id, status: core_1.SERVER_STATUS.ENABLED }; | ||
return this._updateStatus(query, core_1.SERVER_STATUS.DISABLED); | ||
} | ||
_fieldOp(op, id, field, value) { | ||
const query = { _id: id, status: { $gt: core_1.SERVER_STATUS.UNKNOWN } }; | ||
const obj = {}; | ||
obj[`${field}`] = value; | ||
const update = {}; | ||
update[`${op}`] = obj; | ||
return this.update(query, {}, update); | ||
} | ||
addToSet(id, field, value) { | ||
return this._fieldOp("$addToSet", id, field, value); | ||
} | ||
push(id, field, value) { | ||
return this._fieldOp("$push", id, field, value); | ||
} | ||
pushAll(id, field, value) { | ||
return this._fieldOp("$pushAll", id, field, value); | ||
} | ||
pull(id, field, value) { | ||
return this._fieldOp("$pull", id, field, value); | ||
} | ||
pullAll(id, field, value) { | ||
return this._fieldOp("$pullAll", id, field, value); | ||
} | ||
} | ||
exports.CRUD = CRUD; | ||
//# sourceMappingURL=crud.controller.js.map |
@@ -19,3 +19,4 @@ "use strict"; | ||
response: { | ||
error: err.boError ? err.boError : core_1.SERVER_ERRORS.UNKNOW_ERROR | ||
error: err.boError || core_1.SERVER_ERRORS.UNKNOW_ERROR, | ||
description: err.boStr || "no-description" | ||
} | ||
@@ -30,2 +31,3 @@ }; | ||
error.response.error = core_1.SERVER_ERRORS.OBJECT_DUPLICATED; | ||
error.response.description = "object-duplicated"; | ||
error.status = core_1.HTTP_STATUS.HTTP_4XX_CONFLICT; | ||
@@ -35,2 +37,3 @@ break; | ||
error.response.error = core_1.SERVER_ERRORS.INVALID_OPERATION; | ||
error.response.description = "invalid-operation"; | ||
error.status = core_1.HTTP_STATUS.HTTP_4XX_BAD_REQUEST; | ||
@@ -44,2 +47,3 @@ } | ||
error.response.error = core_1.SERVER_ERRORS.INVALID_OPERATION; | ||
error.response.description = "invalid-operation"; | ||
error.status = core_1.HTTP_STATUS.HTTP_4XX_UNAUTHORIZED; | ||
@@ -49,2 +53,3 @@ break; | ||
error.response.error = core_1.SERVER_ERRORS.INVALID_OPERATION; | ||
error.response.description = "invalid-operation"; | ||
error.status = err.status || core_1.HTTP_STATUS.HTTP_4XX_FORBIDDEN; | ||
@@ -54,3 +59,3 @@ } | ||
} | ||
this._logger.error("Request error", { error: err.stack, response: error }); | ||
this._logger.error("Request error", { error: err, stack: err.stack, response: error }); | ||
return error; | ||
@@ -57,0 +62,0 @@ } |
@@ -158,5 +158,5 @@ "use strict"; | ||
boError: core_1.SERVER_ERRORS.INVALID_OPERATION, | ||
boStr: "invalid-operation", | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_FOUND | ||
}); | ||
res; | ||
} | ||
@@ -163,0 +163,0 @@ next(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ValidateObjectId = exports.Validator = exports.Joi = exports.ResponseHandler = exports.GeoJSON = exports.BaseModel = exports.ErrorCtrl = exports.CRUD = exports.HttpServer = exports.ClusterServer = void 0; | ||
const typegoose_1 = require("@typegoose/typegoose"); | ||
typegoose_1.setGlobalOptions({ options: { allowMixed: typegoose_1.Severity.ALLOW } }); | ||
var cluster_controller_1 = require("./controllers/cluster.controller"); | ||
@@ -5,0 +7,0 @@ Object.defineProperty(exports, "ClusterServer", { enumerable: true, get: function () { return cluster_controller_1.ClusterServer; } }); |
@@ -40,2 +40,3 @@ "use strict"; | ||
boError: core_1.SERVER_ERRORS.INVALID_FIELDS, | ||
boStr: "invalid-fields", | ||
boData: { fields: fields } | ||
@@ -42,0 +43,0 @@ }; |
import { defaultClasses } from "@typegoose/typegoose"; | ||
import { Types } from "mongoose"; | ||
export declare class BaseModel implements defaultClasses.Base<Types.ObjectId>, defaultClasses.TimeStamps { | ||
_id: Types.ObjectId; | ||
id: string; | ||
export declare class BaseModel extends defaultClasses.Base<Types.ObjectId> implements defaultClasses.TimeStamps { | ||
status?: number; | ||
@@ -10,3 +8,3 @@ owner?: Types.ObjectId | string; | ||
updatedAt?: Date; | ||
modifiedBy?: string; | ||
modifiedBy?: Types.ObjectId | string; | ||
} |
@@ -16,13 +16,5 @@ "use strict"; | ||
const mongoose_1 = require("mongoose"); | ||
class BaseModel { | ||
class BaseModel extends typegoose_1.defaultClasses.Base { | ||
} | ||
__decorate([ | ||
typegoose_1.prop({ type: mongoose_1.Types.ObjectId, required: true }), | ||
__metadata("design:type", mongoose_1.Types.ObjectId) | ||
], BaseModel.prototype, "_id", void 0); | ||
__decorate([ | ||
typegoose_1.prop(), | ||
__metadata("design:type", String) | ||
], BaseModel.prototype, "id", void 0); | ||
__decorate([ | ||
typegoose_1.prop({ required: true, default: core_1.SERVER_STATUS.ENABLED }), | ||
@@ -45,5 +37,5 @@ __metadata("design:type", Number) | ||
typegoose_1.prop({ type: mongoose_1.Types.ObjectId }), | ||
__metadata("design:type", String) | ||
__metadata("design:type", Object) | ||
], BaseModel.prototype, "modifiedBy", void 0); | ||
exports.BaseModel = BaseModel; | ||
//# sourceMappingURL=base.model.js.map |
@@ -24,3 +24,3 @@ "use strict"; | ||
__decorate([ | ||
typegoose_1.prop({ required: true, type: [Number] }), | ||
typegoose_1.prop({ required: true, type: Number }), | ||
__metadata("design:type", Array) | ||
@@ -27,0 +27,0 @@ ], GeoJSON.prototype, "coordinates", void 0); |
{ | ||
"name": "@ikoabo/server", | ||
"version": "1.1.23", | ||
"version": "1.1.24", | ||
"description": "IKOA Business Opportunity Server Package", | ||
@@ -14,5 +14,4 @@ "main": "lib/index.js", | ||
"build": "tsc", | ||
"deploy": "tsc && npm run publish-npm && npm run publish-nexus", | ||
"deploy": "tsc && npm run publish-npm", | ||
"publish-npm": "npm publish --registry='https://registry.npmjs.org/' --access public", | ||
"publish-nexus": "npm publish --registry='https://nxs.ikoabo.com/repository/npm-local/'", | ||
"lint": "tsc --noEmit && eslint '*/**/*.ts' --fix", | ||
@@ -68,2 +67,3 @@ "test": "mocha --require ts-node/register tests/*.ts", | ||
"@types/mocha": "^8.2.2", | ||
"@types/mongoose": "5.10.x", | ||
"@types/morgan": "^1.9.2", | ||
@@ -89,6 +89,6 @@ "@types/on-finished": "^2.3.1", | ||
"@ikoabo/core": "1.x", | ||
"@typegoose/typegoose": "8.0.0-beta.13", | ||
"@typegoose/typegoose": "7.x", | ||
"express": "4.x", | ||
"mongoose": "5.x" | ||
"mongoose": "5.10.18" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85203
965
25