rate-core 0.5.3 → 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 +9 -4
- package/package.json +4 -3
- package/src/core.ts +3 -35
- package/src/index.ts +4 -4
- package/src/rate.ts +13 -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,16 +31,21 @@ 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
|
},
|
|
41
43
|
histories: {
|
|
42
44
|
type: 'array',
|
|
43
45
|
typeof: exports.rateHistoryModel
|
|
46
|
+
},
|
|
47
|
+
anonymous: {
|
|
48
|
+
type: 'boolean',
|
|
44
49
|
}
|
|
45
50
|
};
|
|
46
51
|
exports.infoModel = {
|
|
@@ -133,11 +138,11 @@ exports.rateInfoModel = {
|
|
|
133
138
|
exports.ratesModel = {
|
|
134
139
|
id: {
|
|
135
140
|
key: true,
|
|
136
|
-
|
|
141
|
+
operator: '='
|
|
137
142
|
},
|
|
138
143
|
author: {
|
|
139
144
|
key: true,
|
|
140
|
-
|
|
145
|
+
operator: '='
|
|
141
146
|
},
|
|
142
147
|
rate: {
|
|
143
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
|
@@ -7,6 +7,9 @@ export interface RateId {
|
|
|
7
7
|
export interface BaseRate {
|
|
8
8
|
author: string;
|
|
9
9
|
authorURL?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
displayName: string;
|
|
12
|
+
anonymous: boolean;
|
|
10
13
|
rate: number;
|
|
11
14
|
}
|
|
12
15
|
export interface Rate extends BaseRate {
|
|
@@ -65,7 +68,7 @@ export interface RatesFilter extends RateFilter {
|
|
|
65
68
|
rate10: number;
|
|
66
69
|
}
|
|
67
70
|
export interface BaseRepository<R> {
|
|
68
|
-
|
|
71
|
+
create(rate: R, newInfo?: boolean): Promise<number>;
|
|
69
72
|
update(rate: R, oldRate: number): Promise<number>;
|
|
70
73
|
load(id: string, author: string): Promise<R | null>;
|
|
71
74
|
}
|
|
@@ -87,12 +90,12 @@ export const rateModel: Attributes = {
|
|
|
87
90
|
id: {
|
|
88
91
|
key: true,
|
|
89
92
|
required: true,
|
|
90
|
-
|
|
93
|
+
operator: '='
|
|
91
94
|
},
|
|
92
95
|
author: {
|
|
93
96
|
key: true,
|
|
94
97
|
required: true,
|
|
95
|
-
|
|
98
|
+
operator: '='
|
|
96
99
|
},
|
|
97
100
|
rate: {
|
|
98
101
|
type: 'integer',
|
|
@@ -105,16 +108,21 @@ export const rateModel: Attributes = {
|
|
|
105
108
|
q: true,
|
|
106
109
|
},
|
|
107
110
|
usefulCount: {
|
|
111
|
+
column: "useful_count",
|
|
108
112
|
type: 'integer',
|
|
109
113
|
min: 0
|
|
110
114
|
},
|
|
111
115
|
replyCount: {
|
|
116
|
+
column: "reply_count",
|
|
112
117
|
type: 'integer',
|
|
113
118
|
min: 0
|
|
114
119
|
},
|
|
115
120
|
histories: {
|
|
116
121
|
type: 'array',
|
|
117
122
|
typeof: rateHistoryModel
|
|
123
|
+
},
|
|
124
|
+
anonymous: {
|
|
125
|
+
type: 'boolean',
|
|
118
126
|
}
|
|
119
127
|
};
|
|
120
128
|
|
|
@@ -239,11 +247,11 @@ export const rateInfoModel: Attributes = {
|
|
|
239
247
|
export const ratesModel: Attributes = {
|
|
240
248
|
id: {
|
|
241
249
|
key: true,
|
|
242
|
-
|
|
250
|
+
operator: '='
|
|
243
251
|
},
|
|
244
252
|
author: {
|
|
245
253
|
key: true,
|
|
246
|
-
|
|
254
|
+
operator: '='
|
|
247
255
|
},
|
|
248
256
|
rate: {
|
|
249
257
|
type: 'number'
|