xpress-mongo
Advanced tools
Comparing version 0.0.33 to 0.0.34
@@ -61,3 +61,9 @@ "use strict"; | ||
} | ||
/** | ||
* Set required to false | ||
*/ | ||
isOptional() { | ||
return this.required(false); | ||
} | ||
} | ||
module.exports = XMongoDataType; |
@@ -131,2 +131,45 @@ "use strict"; | ||
/** | ||
* Push element to model | ||
* @param key | ||
* @param value | ||
* @param strict | ||
* @return {this} | ||
*/ | ||
pushToArray(key, value, strict = false) { | ||
// Find current value of key | ||
let data = this.get(key, undefined); | ||
// if current value is undefined create new array | ||
if (data === undefined) { | ||
data = []; | ||
} | ||
// Else if not array we throw an error | ||
else if (!Array.isArray(data)) { | ||
throw Error(`PushTo: Current value of {${key}} is not an array.`); | ||
} | ||
// Else if strict and value already exists. | ||
else if (strict && data.includes(value)) { | ||
return this; | ||
} | ||
// push value to array | ||
data.push(value); | ||
// Set data to model | ||
this.set(key, data); | ||
// Return this. | ||
return this; | ||
} | ||
/** | ||
* Find data in array | ||
* @param key | ||
* @param value | ||
*/ | ||
findInArray(key, value) { | ||
// Get data value | ||
const data = this.get(key, undefined); | ||
// Return undefined of value is undefined | ||
if (data === undefined) | ||
return data; | ||
// Find in data | ||
return _.find(data, value); | ||
} | ||
/** | ||
* Insert new record and return instance. | ||
@@ -133,0 +176,0 @@ * @param data - new record data. |
{ | ||
"name": "xpress-mongo", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
@@ -70,4 +70,11 @@ import {ValidatorType, CastFunctionType, SchemaPropertiesType} from "./CustomTypes"; | ||
} | ||
/** | ||
* Set required to false | ||
*/ | ||
isOptional() { | ||
return this.required(false); | ||
} | ||
} | ||
export = XMongoDataType; |
@@ -180,2 +180,54 @@ import ObjectCollection = require('object-collection'); | ||
/** | ||
* Push element to model | ||
* @param key | ||
* @param value | ||
* @param strict | ||
* @return {this} | ||
*/ | ||
pushToArray(key: string, value: any, strict: boolean = false): this { | ||
// Find current value of key | ||
let data: any[] = this.get(key, undefined); | ||
// if current value is undefined create new array | ||
if (data === undefined) { | ||
data = []; | ||
} | ||
// Else if not array we throw an error | ||
else if (!Array.isArray(data)) { | ||
throw Error(`PushTo: Current value of {${key}} is not an array.`); | ||
} | ||
// Else if strict and value already exists. | ||
else if (strict && data.includes(value)) { | ||
return this; | ||
} | ||
// push value to array | ||
data.push(value); | ||
// Set data to model | ||
this.set(key, data); | ||
// Return this. | ||
return this; | ||
} | ||
/** | ||
* Find data in array | ||
* @param key | ||
* @param value | ||
*/ | ||
findInArray(key: string, value: any): any { | ||
// Get data value | ||
const data = this.get(key, undefined); | ||
// Return undefined of value is undefined | ||
if (data === undefined) return data; | ||
// Find in data | ||
return _.find(data, value); | ||
} | ||
/** | ||
* Insert new record and return instance. | ||
@@ -182,0 +234,0 @@ * @param data - new record data. |
@@ -34,3 +34,7 @@ import { ValidatorType, CastFunctionType, SchemaPropertiesType } from "./CustomTypes"; | ||
isUndefined(): this; | ||
/** | ||
* Set required to false | ||
*/ | ||
isOptional(): this; | ||
} | ||
export = XMongoDataType; |
@@ -91,2 +91,16 @@ import ObjectCollection = require('object-collection'); | ||
/** | ||
* Push element to model | ||
* @param key | ||
* @param value | ||
* @param strict | ||
* @return {this} | ||
*/ | ||
pushToArray(key: string, value: any, strict?: boolean): this; | ||
/** | ||
* Find data in array | ||
* @param key | ||
* @param value | ||
*/ | ||
findInArray(key: string, value: any): any; | ||
/** | ||
* Insert new record and return instance. | ||
@@ -93,0 +107,0 @@ * @param data - new record data. |
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
131401
3583