rate-core 0.5.4 → 0.6.0
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/lib/index.js +4 -4
- package/lib/rate.js +6 -4
- package/package.json +4 -3
- package/src/core.ts +3 -35
- package/src/index.ts +4 -4
- package/src/rate.ts +7 -5
package/lib/index.js
CHANGED
|
@@ -57,7 +57,7 @@ var RateService = (function () {
|
|
|
57
57
|
case 1:
|
|
58
58
|
info = _a.sent();
|
|
59
59
|
if (!!info) return [3, 3];
|
|
60
|
-
return [4, this.repository.
|
|
60
|
+
return [4, this.repository.create(rate, true)];
|
|
61
61
|
case 2:
|
|
62
62
|
r0 = _a.sent();
|
|
63
63
|
return [2, r0];
|
|
@@ -65,7 +65,7 @@ var RateService = (function () {
|
|
|
65
65
|
case 4:
|
|
66
66
|
exist = _a.sent();
|
|
67
67
|
if (!!exist) return [3, 6];
|
|
68
|
-
return [4, this.repository.
|
|
68
|
+
return [4, this.repository.create(rate)];
|
|
69
69
|
case 5:
|
|
70
70
|
r1 = _a.sent();
|
|
71
71
|
return [2, r1];
|
|
@@ -118,7 +118,7 @@ var RatesService = (function () {
|
|
|
118
118
|
}
|
|
119
119
|
rate.time = new Date();
|
|
120
120
|
if (!!info) return [3, 3];
|
|
121
|
-
return [4, this.repository.
|
|
121
|
+
return [4, this.repository.create(rate, true)];
|
|
122
122
|
case 2:
|
|
123
123
|
r0 = _a.sent();
|
|
124
124
|
return [2, r0];
|
|
@@ -126,7 +126,7 @@ var RatesService = (function () {
|
|
|
126
126
|
case 4:
|
|
127
127
|
exist = _a.sent();
|
|
128
128
|
if (!!exist) return [3, 6];
|
|
129
|
-
return [4, this.repository.
|
|
129
|
+
return [4, this.repository.create(rate)];
|
|
130
130
|
case 5:
|
|
131
131
|
r1 = _a.sent();
|
|
132
132
|
return [2, r1];
|
package/lib/rate.js
CHANGED
|
@@ -13,12 +13,12 @@ exports.rateModel = {
|
|
|
13
13
|
id: {
|
|
14
14
|
key: true,
|
|
15
15
|
required: true,
|
|
16
|
-
|
|
16
|
+
operator: '='
|
|
17
17
|
},
|
|
18
18
|
author: {
|
|
19
19
|
key: true,
|
|
20
20
|
required: true,
|
|
21
|
-
|
|
21
|
+
operator: '='
|
|
22
22
|
},
|
|
23
23
|
rate: {
|
|
24
24
|
type: 'integer',
|
|
@@ -31,10 +31,12 @@ exports.rateModel = {
|
|
|
31
31
|
q: true,
|
|
32
32
|
},
|
|
33
33
|
usefulCount: {
|
|
34
|
+
column: "useful_count",
|
|
34
35
|
type: 'integer',
|
|
35
36
|
min: 0
|
|
36
37
|
},
|
|
37
38
|
replyCount: {
|
|
39
|
+
column: "reply_count",
|
|
38
40
|
type: 'integer',
|
|
39
41
|
min: 0
|
|
40
42
|
},
|
|
@@ -136,11 +138,11 @@ exports.rateInfoModel = {
|
|
|
136
138
|
exports.ratesModel = {
|
|
137
139
|
id: {
|
|
138
140
|
key: true,
|
|
139
|
-
|
|
141
|
+
operator: '='
|
|
140
142
|
},
|
|
141
143
|
author: {
|
|
142
144
|
key: true,
|
|
143
|
-
|
|
145
|
+
operator: '='
|
|
144
146
|
},
|
|
145
147
|
rate: {
|
|
146
148
|
type: 'number'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rate-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "rate",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"rate",
|
|
24
|
-
"rate core"
|
|
24
|
+
"rate core",
|
|
25
|
+
"rate-core"
|
|
25
26
|
]
|
|
26
|
-
}
|
|
27
|
+
}
|
package/src/core.ts
CHANGED
|
@@ -2,42 +2,19 @@ export type DataType = 'ObjectId' | 'date' | 'datetime' | 'time'
|
|
|
2
2
|
| 'boolean' | 'number' | 'integer' | 'string' | 'text'
|
|
3
3
|
| 'object' | 'array' | 'binary'
|
|
4
4
|
| 'primitives' | 'booleans' | 'numbers' | 'integers' | 'strings' | 'dates' | 'datetimes' | 'times';
|
|
5
|
-
export type
|
|
6
|
-
export type MatchType = 'equal' | 'prefix' | 'contain' | 'max' | 'min'; // contain: default for string, min: default for Date, number
|
|
5
|
+
export type Operator = "=" | "like" | "!=" | "<>" | ">" | ">=" | "<" | "<="
|
|
7
6
|
|
|
8
7
|
export interface Attribute {
|
|
9
|
-
name?: string;
|
|
10
8
|
field?: string;
|
|
11
9
|
column?: string;
|
|
12
10
|
type?: DataType;
|
|
13
|
-
format?: FormatType;
|
|
14
11
|
required?: boolean;
|
|
15
|
-
|
|
16
|
-
default?: string|number|Date|boolean;
|
|
12
|
+
operator?: Operator;
|
|
17
13
|
key?: boolean;
|
|
18
|
-
unique?: boolean;
|
|
19
|
-
enum?: string[] | number[];
|
|
20
14
|
q?: boolean;
|
|
21
|
-
noinsert?: boolean;
|
|
22
|
-
noupdate?: boolean;
|
|
23
|
-
nopatch?: boolean;
|
|
24
|
-
version?: boolean;
|
|
25
|
-
length?: number;
|
|
26
15
|
min?: number;
|
|
27
16
|
max?: number;
|
|
28
|
-
gt?: number;
|
|
29
|
-
lt?: number;
|
|
30
|
-
precision?: number;
|
|
31
|
-
scale?: number;
|
|
32
|
-
exp?: RegExp | string;
|
|
33
|
-
code?: string;
|
|
34
|
-
noformat?: boolean;
|
|
35
|
-
ignored?: boolean;
|
|
36
|
-
jsonField?: string;
|
|
37
|
-
link?: string;
|
|
38
17
|
typeof?: Attributes;
|
|
39
|
-
true?: string|number;
|
|
40
|
-
false?: string|number;
|
|
41
18
|
}
|
|
42
19
|
export interface Attributes {
|
|
43
20
|
[key: string]: Attribute;
|
|
@@ -45,17 +22,8 @@ export interface Attributes {
|
|
|
45
22
|
|
|
46
23
|
export interface Filter {
|
|
47
24
|
page?: number;
|
|
48
|
-
limit
|
|
49
|
-
firstLimit?: number;
|
|
25
|
+
limit: number;
|
|
50
26
|
fields?: string[];
|
|
51
27
|
sort?: string;
|
|
52
|
-
currentUserId?: string;
|
|
53
|
-
|
|
54
28
|
q?: string;
|
|
55
|
-
keyword?: string;
|
|
56
|
-
excluding?: string[]|number[];
|
|
57
|
-
refId?: string|number;
|
|
58
|
-
|
|
59
|
-
pageIndex?: number;
|
|
60
|
-
pageSize?: number;
|
|
61
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,12 +14,12 @@ export class RateService implements Rater<Rate> {
|
|
|
14
14
|
rate.time = new Date();
|
|
15
15
|
const info = await this.infoRepository.exist(rate.id);
|
|
16
16
|
if (!info) {
|
|
17
|
-
const r0 = await this.repository.
|
|
17
|
+
const r0 = await this.repository.create(rate, true);
|
|
18
18
|
return r0;
|
|
19
19
|
}
|
|
20
20
|
const exist = await this.repository.load(rate.id, rate.author);
|
|
21
21
|
if (!exist) {
|
|
22
|
-
const r1 = await this.repository.
|
|
22
|
+
const r1 = await this.repository.create(rate);
|
|
23
23
|
return r1;
|
|
24
24
|
}
|
|
25
25
|
const sr: ShortRate = { review: exist.review, rate: exist.rate, time: exist.time };
|
|
@@ -55,12 +55,12 @@ export class RatesService implements Rater<Rates> {
|
|
|
55
55
|
}
|
|
56
56
|
rate.time = new Date();
|
|
57
57
|
if (!info) {
|
|
58
|
-
const r0 = await this.repository.
|
|
58
|
+
const r0 = await this.repository.create(rate, true);
|
|
59
59
|
return r0;
|
|
60
60
|
}
|
|
61
61
|
const exist = await this.repository.load(rate.id, rate.author);
|
|
62
62
|
if (!exist) {
|
|
63
|
-
const r1 = await this.repository.
|
|
63
|
+
const r1 = await this.repository.create(rate);
|
|
64
64
|
return r1;
|
|
65
65
|
}
|
|
66
66
|
const sr: ShortRates = { review: exist.review, rates: exist.rates, time: exist.time };
|
package/src/rate.ts
CHANGED
|
@@ -68,7 +68,7 @@ export interface RatesFilter extends RateFilter {
|
|
|
68
68
|
rate10: number;
|
|
69
69
|
}
|
|
70
70
|
export interface BaseRepository<R> {
|
|
71
|
-
|
|
71
|
+
create(rate: R, newInfo?: boolean): Promise<number>;
|
|
72
72
|
update(rate: R, oldRate: number): Promise<number>;
|
|
73
73
|
load(id: string, author: string): Promise<R | null>;
|
|
74
74
|
}
|
|
@@ -90,12 +90,12 @@ export const rateModel: Attributes = {
|
|
|
90
90
|
id: {
|
|
91
91
|
key: true,
|
|
92
92
|
required: true,
|
|
93
|
-
|
|
93
|
+
operator: '='
|
|
94
94
|
},
|
|
95
95
|
author: {
|
|
96
96
|
key: true,
|
|
97
97
|
required: true,
|
|
98
|
-
|
|
98
|
+
operator: '='
|
|
99
99
|
},
|
|
100
100
|
rate: {
|
|
101
101
|
type: 'integer',
|
|
@@ -108,10 +108,12 @@ export const rateModel: Attributes = {
|
|
|
108
108
|
q: true,
|
|
109
109
|
},
|
|
110
110
|
usefulCount: {
|
|
111
|
+
column: "useful_count",
|
|
111
112
|
type: 'integer',
|
|
112
113
|
min: 0
|
|
113
114
|
},
|
|
114
115
|
replyCount: {
|
|
116
|
+
column: "reply_count",
|
|
115
117
|
type: 'integer',
|
|
116
118
|
min: 0
|
|
117
119
|
},
|
|
@@ -245,11 +247,11 @@ export const rateInfoModel: Attributes = {
|
|
|
245
247
|
export const ratesModel: Attributes = {
|
|
246
248
|
id: {
|
|
247
249
|
key: true,
|
|
248
|
-
|
|
250
|
+
operator: '='
|
|
249
251
|
},
|
|
250
252
|
author: {
|
|
251
253
|
key: true,
|
|
252
|
-
|
|
254
|
+
operator: '='
|
|
253
255
|
},
|
|
254
256
|
rate: {
|
|
255
257
|
type: 'number'
|