model-redis 0.1.2 → 0.1.3
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/README.md +14 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,14 +93,13 @@ class User extends Table{
|
|
|
93
93
|
'updated_on': {default: function(){return (new Date).getTime()}, always: true},
|
|
94
94
|
'username': {isRequired: true, type: 'string', min: 3, max: 500},
|
|
95
95
|
'password': {isRequired: true, type: 'string', min: 3, max: 500},
|
|
96
|
-
}
|
|
96
|
+
};
|
|
97
97
|
|
|
98
98
|
static async add(data) {
|
|
99
99
|
try{
|
|
100
100
|
data['password'] = await bcrypt.hash(data['password'], saltRounds);
|
|
101
101
|
|
|
102
|
-
return await super.add(data)
|
|
103
|
-
|
|
102
|
+
return await super.add(data);
|
|
104
103
|
}catch(error){
|
|
105
104
|
throw error;
|
|
106
105
|
}
|
|
@@ -118,12 +117,11 @@ class User extends Table{
|
|
|
118
117
|
|
|
119
118
|
static async login(data){
|
|
120
119
|
try{
|
|
121
|
-
|
|
122
120
|
let user = await User.get(data);
|
|
123
121
|
let auth = await bcrypt.compare(data.password, user.password);
|
|
124
122
|
|
|
125
123
|
if(auth){
|
|
126
|
-
return user
|
|
124
|
+
return user;
|
|
127
125
|
}else{
|
|
128
126
|
throw new Error("LogginFailed");
|
|
129
127
|
}
|
|
@@ -142,13 +140,13 @@ module.exports = {User};
|
|
|
142
140
|
The table schema a required aspect of using this module. The schema is defined
|
|
143
141
|
with `_key`, `_indexed` and `_keyMap`
|
|
144
142
|
|
|
145
|
-
`static _key` *string* is required and is basically the primary key for this
|
|
143
|
+
* `static _key` *string* is required and is basically the primary key for this
|
|
146
144
|
table. It MUST match one of the keys in the `_keyMap` schema
|
|
147
145
|
|
|
148
|
-
`static _indexed` *array* is optional list of keys to be indexed. Indexed keys
|
|
146
|
+
* `static _indexed` *array* is optional list of keys to be indexed. Indexed keys
|
|
149
147
|
can be searched by with the `list()` and `listDetial()` methods.
|
|
150
148
|
|
|
151
|
-
`static _keyMap` *object* is required and defines the allowed schema for the
|
|
149
|
+
* `static _keyMap` *object* is required and defines the allowed schema for the
|
|
152
150
|
table. Validation will be enforced based on what is defined in the schema.
|
|
153
151
|
|
|
154
152
|
The `_keyMap` schema is an object where the key is the name of the field and the
|
|
@@ -162,10 +160,12 @@ value is an object with the options for that field:
|
|
|
162
160
|
|
|
163
161
|
* `type` *string* Required The native type this field will be checked for, valid
|
|
164
162
|
types are:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
|
|
164
|
+
* `string`
|
|
165
|
+
* `number`
|
|
166
|
+
* `boolean`
|
|
167
|
+
* `object`
|
|
168
|
+
|
|
169
169
|
* `isRequired` *boolean* If this is set to true, this must be set when a new
|
|
170
170
|
entry is created. This has no effect on updates.
|
|
171
171
|
* `default` *field type or function* if nothing is passed, this will be used be
|
|
@@ -174,6 +174,8 @@ value is an object with the options for that field:
|
|
|
174
174
|
* `always` *boolean* If this is set, the `default` is set, then its value will
|
|
175
175
|
always be used when calling update. This is useful for setting an updated on
|
|
176
176
|
field or access count.
|
|
177
|
+
* `min` *number* Used with *string* or *number* type to define the lower limit
|
|
178
|
+
* `max` *number* Used with *string* or *number* type to define the max limit
|
|
177
179
|
|
|
178
180
|
Once we have defined a `_keyMap` schema, the table can be used.
|
|
179
181
|
|