rate-core 0.0.5 → 0.0.6

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 CHANGED
@@ -49,12 +49,16 @@ var RateService = (function () {
49
49
  this.rateReactionRepository = rateReactionRepository;
50
50
  this.queryURL = queryURL;
51
51
  this.rate = this.rate.bind(this);
52
+ this.search = this.search.bind(this);
53
+ this.load = this.load.bind(this);
54
+ this.getRate = this.getRate.bind(this);
55
+ this.setUseful = this.setUseful.bind(this);
56
+ this.removeUseful = this.removeUseful.bind(this);
52
57
  this.comment = this.comment.bind(this);
53
58
  this.removeComment = this.removeComment.bind(this);
54
59
  this.updateComment = this.updateComment.bind(this);
55
- this.search = this.search.bind(this);
56
- this.getComment = this.getComment.bind(this);
57
60
  this.getComments = this.getComments.bind(this);
61
+ this.getComment = this.getComment.bind(this);
58
62
  }
59
63
  RateService.prototype.rate = function (rate) {
60
64
  return __awaiter(this, void 0, void 0, function () {
@@ -71,7 +75,7 @@ var RateService = (function () {
71
75
  case 2:
72
76
  r0 = _a.sent();
73
77
  return [2, r0];
74
- case 3: return [4, this.repository.getRate(rate.id, rate.author)];
78
+ case 3: return [4, this.repository.load(rate.id, rate.author)];
75
79
  case 4:
76
80
  exist = _a.sent();
77
81
  if (!!exist) return [3, 6];
@@ -127,8 +131,11 @@ var RateService = (function () {
127
131
  }
128
132
  });
129
133
  };
134
+ RateService.prototype.load = function (id, author) {
135
+ return this.repository.load(id, author);
136
+ };
130
137
  RateService.prototype.getRate = function (id, author) {
131
- return this.repository.getRate(id, author);
138
+ return this.repository.load(id, author);
132
139
  };
133
140
  RateService.prototype.setUseful = function (id, author, userId) {
134
141
  return this.rateReactionRepository.save(id, author, userId, 1);
@@ -138,7 +145,7 @@ var RateService = (function () {
138
145
  };
139
146
  RateService.prototype.comment = function (comment) {
140
147
  var _this = this;
141
- return this.repository.getRate(comment.id, comment.author).then(function (checkRate) {
148
+ return this.repository.load(comment.id, comment.author).then(function (checkRate) {
142
149
  if (!checkRate) {
143
150
  return -1;
144
151
  }
package/lib/rate.js CHANGED
@@ -116,45 +116,3 @@ exports.info10Model = {
116
116
  type: 'number',
117
117
  }
118
118
  };
119
- exports.commentModel = {
120
- comment: {
121
- length: 500
122
- },
123
- time: {
124
- type: 'datetime'
125
- }
126
- };
127
- exports.rateCommentModel = {
128
- commentId: {
129
- key: true
130
- },
131
- id: {
132
- required: true,
133
- noupdate: true,
134
- match: 'equal'
135
- },
136
- author: {
137
- required: true,
138
- noupdate: true,
139
- match: 'equal'
140
- },
141
- userId: {
142
- required: true,
143
- noupdate: true,
144
- match: 'equal'
145
- },
146
- comment: {
147
- length: 500
148
- },
149
- time: {
150
- type: 'datetime',
151
- noupdate: true,
152
- },
153
- updatedAt: {
154
- type: 'datetime'
155
- },
156
- histories: {
157
- type: 'array',
158
- typeof: exports.commentModel
159
- }
160
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rate-core",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "rate",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -18,12 +18,16 @@ export class RateService<O> implements Rater {
18
18
  private rateReactionRepository: RateReactionRepository,
19
19
  private queryURL?: (ids: string[]) => Promise<URL[]>) {
20
20
  this.rate = this.rate.bind(this);
21
+ this.search = this.search.bind(this);
22
+ this.load = this.load.bind(this);
23
+ this.getRate = this.getRate.bind(this);
24
+ this.setUseful = this.setUseful.bind(this);
25
+ this.removeUseful = this.removeUseful.bind(this);
21
26
  this.comment = this.comment.bind(this);
22
27
  this.removeComment = this.removeComment.bind(this);
23
28
  this.updateComment = this.updateComment.bind(this);
24
- this.search = this.search.bind(this);
25
- this.getComment = this.getComment.bind(this);
26
29
  this.getComments = this.getComments.bind(this);
30
+ this.getComment = this.getComment.bind(this);
27
31
  }
28
32
  async rate(rate: Rate): Promise<number> {
29
33
  rate.time = new Date();
@@ -32,7 +36,7 @@ export class RateService<O> implements Rater {
32
36
  const r0 = await this.repository.insert(rate, true);
33
37
  return r0;
34
38
  }
35
- const exist = await this.repository.getRate(rate.id, rate.author);
39
+ const exist = await this.repository.load(rate.id, rate.author);
36
40
  if (!exist) {
37
41
  const r1 = await this.repository.insert(rate);
38
42
  return r1;
@@ -73,8 +77,11 @@ export class RateService<O> implements Rater {
73
77
  }
74
78
  });
75
79
  }
80
+ load(id: string, author: string): Promise<Rate | null> {
81
+ return this.repository.load(id, author);
82
+ }
76
83
  getRate(id: string, author: string): Promise<Rate | null> {
77
- return this.repository.getRate(id, author);
84
+ return this.repository.load(id, author);
78
85
  }
79
86
  setUseful(id: string, author: string, userId: string): Promise<number> {
80
87
  return this.rateReactionRepository.save(id, author, userId, 1);
@@ -83,7 +90,7 @@ export class RateService<O> implements Rater {
83
90
  return this.rateReactionRepository.remove(id, author, userId);
84
91
  }
85
92
  comment(comment: Comment): Promise<number> {
86
- return this.repository.getRate(comment.id, comment.author).then(checkRate => {
93
+ return this.repository.load(comment.id, comment.author).then(checkRate => {
87
94
  if (!checkRate) {
88
95
  return -1;
89
96
  } else {
package/src/rate.ts CHANGED
@@ -35,11 +35,11 @@ export interface RateRepository {
35
35
  // save(obj: Rate, info?: T, ctx?: any): Promise<number>;
36
36
  insert(rate: Rate, newInfo?: boolean): Promise<number>;
37
37
  update(rate: Rate, oldRate: number): Promise<number>;
38
- getRate(id: string, author: string): Promise<Rate | null>;
38
+ load(id: string, author: string): Promise<Rate | null>;
39
39
  }
40
40
  export interface Rater {
41
41
  search(s: RateFilter, limit?: number, offset?: number | string, fields?: string[], ctx?: any): Promise<SearchResult<Rate>>;
42
- getRate(id: string, author: string): Promise<Rate | null>;
42
+ load(id: string, author: string): Promise<Rate | null>;
43
43
  rate(rate: Rate): Promise<number>;
44
44
  setUseful(id: string, author: string, userId: string, ctx?: any): Promise<number>;
45
45
  removeUseful(id: string, author: string, userId: string, ctx?: any): Promise<number>;
@@ -247,45 +247,3 @@ export interface CommentFilter extends Filter {
247
247
  time?: Date;
248
248
  updatedAt?: Date;
249
249
  }
250
- export const commentModel: Attributes = {
251
- comment: {
252
- length: 500
253
- },
254
- time: {
255
- type: 'datetime'
256
- }
257
- };
258
- export const rateCommentModel: Attributes = {
259
- commentId: {
260
- key: true
261
- },
262
- id: {
263
- required: true,
264
- noupdate: true,
265
- match: 'equal'
266
- },
267
- author: {
268
- required: true,
269
- noupdate: true,
270
- match: 'equal'
271
- },
272
- userId: {
273
- required: true,
274
- noupdate: true,
275
- match: 'equal'
276
- },
277
- comment: {
278
- length: 500
279
- },
280
- time: {
281
- type: 'datetime',
282
- noupdate: true,
283
- },
284
- updatedAt: {
285
- type: 'datetime'
286
- },
287
- histories: {
288
- type: 'array',
289
- typeof: commentModel
290
- }
291
- };