rate-core 0.0.2 → 0.0.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/lib/index.js +15 -6
- package/package.json +1 -1
- package/src/index.ts +13 -4
- package/src/rate.ts +1 -0
package/lib/index.js
CHANGED
|
@@ -189,18 +189,27 @@ var RateService = (function () {
|
|
|
189
189
|
return RateService;
|
|
190
190
|
}());
|
|
191
191
|
exports.RateService = RateService;
|
|
192
|
-
var
|
|
193
|
-
function
|
|
192
|
+
var CommentQuery = (function () {
|
|
193
|
+
function CommentQuery(find, repository, queryURL) {
|
|
194
194
|
this.find = find;
|
|
195
195
|
this.repository = repository;
|
|
196
196
|
this.queryURL = queryURL;
|
|
197
197
|
this.load = this.load.bind(this);
|
|
198
198
|
this.search = this.search.bind(this);
|
|
199
|
+
this.getComments = this.getComments.bind(this);
|
|
199
200
|
}
|
|
200
|
-
|
|
201
|
+
CommentQuery.prototype.load = function (id, ctx) {
|
|
201
202
|
return this.repository.load(id, ctx);
|
|
202
203
|
};
|
|
203
|
-
|
|
204
|
+
CommentQuery.prototype.getComments = function (id, author, limit) {
|
|
205
|
+
if (this.repository.getComments) {
|
|
206
|
+
return this.repository.getComments(id, author, limit);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
return Promise.resolve([]);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
CommentQuery.prototype.search = function (s, limit, offset, fields) {
|
|
204
213
|
var _this = this;
|
|
205
214
|
return this.find(s, limit, offset, fields).then(function (res) {
|
|
206
215
|
if (!_this.queryURL) {
|
|
@@ -230,9 +239,9 @@ var RateCommentManager = (function () {
|
|
|
230
239
|
}
|
|
231
240
|
});
|
|
232
241
|
};
|
|
233
|
-
return
|
|
242
|
+
return CommentQuery;
|
|
234
243
|
}());
|
|
235
|
-
exports.
|
|
244
|
+
exports.CommentQuery = CommentQuery;
|
|
236
245
|
function binarySearch(ar, el) {
|
|
237
246
|
var m = 0;
|
|
238
247
|
var n = ar.length - 1;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -125,18 +125,27 @@ export class RateService<O> implements Rater {
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
export interface
|
|
129
|
-
load(
|
|
128
|
+
export interface CommentRepository {
|
|
129
|
+
load(commentId: string, ctx?: any): Promise<RateComment|null>;
|
|
130
|
+
getComments?(id: string, author: string, limit?: number): Promise<RateComment[]>;
|
|
130
131
|
}
|
|
131
132
|
// tslint:disable-next-line:max-classes-per-file
|
|
132
|
-
export class
|
|
133
|
-
constructor(protected find: Search<RateComment, RateCommentFilter>, protected repository:
|
|
133
|
+
export class CommentQuery implements RateCommentQuery {
|
|
134
|
+
constructor(protected find: Search<RateComment, RateCommentFilter>, protected repository: CommentRepository, private queryURL?: (ids: string[]) => Promise<URL[]>) {
|
|
134
135
|
this.load = this.load.bind(this);
|
|
135
136
|
this.search = this.search.bind(this);
|
|
137
|
+
this.getComments = this.getComments.bind(this)
|
|
136
138
|
}
|
|
137
139
|
load(id: string, ctx?: any): Promise<RateComment|null> {
|
|
138
140
|
return this.repository.load(id, ctx);
|
|
139
141
|
}
|
|
142
|
+
getComments(id: string, author: string, limit?: number): Promise<RateComment[]> {
|
|
143
|
+
if (this.repository.getComments) {
|
|
144
|
+
return this.repository.getComments(id, author, limit);
|
|
145
|
+
} else {
|
|
146
|
+
return Promise.resolve([]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
140
149
|
search(s: RateCommentFilter, limit?: number, offset?: number | string, fields?: string[]): Promise<SearchResult<RateComment>> {
|
|
141
150
|
return this.find(s, limit, offset, fields).then(res => {
|
|
142
151
|
if (!this.queryURL) {
|
package/src/rate.ts
CHANGED
|
@@ -63,6 +63,7 @@ export interface Query<T, ID, S> {
|
|
|
63
63
|
load(id: ID, ctx?: any): Promise<T|null>;
|
|
64
64
|
}
|
|
65
65
|
export interface RateCommentQuery extends Query<RateComment, string, RateCommentFilter> {
|
|
66
|
+
getComments(id: string, author: string, limit?: number): Promise<RateComment[]>;
|
|
66
67
|
}
|
|
67
68
|
export const rateHistoryModel: Attributes = {
|
|
68
69
|
rate: {
|