express-ext 0.1.31 → 0.1.34
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 +77 -3
- package/package.json +1 -1
- package/src/index.ts +75 -3
package/lib/index.js
CHANGED
|
@@ -123,7 +123,7 @@ var SavedController = (function () {
|
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
this.service.load(id).then(function (data) {
|
|
126
|
-
res.status(200).json(data).
|
|
126
|
+
res.status(200).json(data).end();
|
|
127
127
|
})
|
|
128
128
|
.catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
129
129
|
};
|
|
@@ -138,7 +138,7 @@ var FollowController = (function () {
|
|
|
138
138
|
this.id = (id && id.length > 0 ? id : 'id');
|
|
139
139
|
this.follow = this.follow.bind(this);
|
|
140
140
|
this.unfollow = this.unfollow.bind(this);
|
|
141
|
-
this.
|
|
141
|
+
this.checkFollow = this.checkFollow.bind(this);
|
|
142
142
|
}
|
|
143
143
|
FollowController.prototype.follow = function (req, res) {
|
|
144
144
|
var _this = this;
|
|
@@ -172,7 +172,7 @@ var FollowController = (function () {
|
|
|
172
172
|
return res.status(200).json(count).end();
|
|
173
173
|
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
174
174
|
};
|
|
175
|
-
FollowController.prototype.
|
|
175
|
+
FollowController.prototype.checkFollow = function (req, res) {
|
|
176
176
|
var _this = this;
|
|
177
177
|
var id = req.params.id;
|
|
178
178
|
var target = req.params.target;
|
|
@@ -191,3 +191,77 @@ var FollowController = (function () {
|
|
|
191
191
|
return FollowController;
|
|
192
192
|
}());
|
|
193
193
|
exports.FollowController = FollowController;
|
|
194
|
+
var ReactionController = (function () {
|
|
195
|
+
function ReactionController(log, service, author, id, reaction) {
|
|
196
|
+
this.log = log;
|
|
197
|
+
this.service = service;
|
|
198
|
+
this.author = author;
|
|
199
|
+
this.reaction = reaction;
|
|
200
|
+
this.id = (id && id.length > 0 ? id : 'id');
|
|
201
|
+
this.react = this.react.bind(this);
|
|
202
|
+
this.unreact = this.unreact.bind(this);
|
|
203
|
+
this.checkReaction = this.checkReaction.bind(this);
|
|
204
|
+
}
|
|
205
|
+
ReactionController.prototype.react = function (req, res) {
|
|
206
|
+
var _this = this;
|
|
207
|
+
var id = req.params.id;
|
|
208
|
+
var author = req.params.author;
|
|
209
|
+
var reaction = req.params.reaction;
|
|
210
|
+
if (!id || id.length === 0) {
|
|
211
|
+
res.status(400).end("'" + this.id + "' cannot be empty");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (!author || author.length === 0) {
|
|
215
|
+
res.status(400).end("'" + this.author + "' cannot be empty");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!reaction || reaction.length === 0) {
|
|
219
|
+
res.status(400).end("'" + this.reaction + "' cannot be empty");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.service.react(id, author, reaction).then(function (count) {
|
|
223
|
+
return res.status(200).json(count).end();
|
|
224
|
+
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
225
|
+
};
|
|
226
|
+
ReactionController.prototype.unreact = function (req, res) {
|
|
227
|
+
var _this = this;
|
|
228
|
+
var id = req.params.id;
|
|
229
|
+
var author = req.params.author;
|
|
230
|
+
var reaction = req.params.reaction;
|
|
231
|
+
if (!id || id.length === 0) {
|
|
232
|
+
res.status(400).end("'" + this.id + "' cannot be empty");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (!author || author.length === 0) {
|
|
236
|
+
res.status(400).end("'" + this.author + "' cannot be empty");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!reaction || reaction.length === 0) {
|
|
240
|
+
res.status(400).end("'" + this.reaction + "' cannot be empty");
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this.service.unreact(id, author, reaction).then(function (count) {
|
|
244
|
+
return res.status(200).json(count).end();
|
|
245
|
+
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
246
|
+
};
|
|
247
|
+
ReactionController.prototype.checkReaction = function (req, res) {
|
|
248
|
+
var _this = this;
|
|
249
|
+
var id = req.params.id;
|
|
250
|
+
var author = req.params.author;
|
|
251
|
+
if (!id || id.length === 0) {
|
|
252
|
+
res.status(400).end("'" + this.id + "' cannot be empty");
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (!author || author.length === 0) {
|
|
256
|
+
res.status(400).end("'" + this.author + "' cannot be empty");
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this.service.checkReaction(id, author).then(function (count) {
|
|
260
|
+
return res.status(200).json(count).end();
|
|
261
|
+
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
262
|
+
};
|
|
263
|
+
return ReactionController;
|
|
264
|
+
}());
|
|
265
|
+
exports.ReactionController = ReactionController;
|
|
266
|
+
exports.ReactController = ReactionController;
|
|
267
|
+
exports.UserReactionController = ReactionController;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -132,7 +132,7 @@ export class SavedController<T> {
|
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
this.service.load(id).then(data => {
|
|
135
|
-
res.status(200).json(data).
|
|
135
|
+
res.status(200).json(data).end();
|
|
136
136
|
})
|
|
137
137
|
.catch(err => handleError(err, res, this.log));
|
|
138
138
|
}
|
|
@@ -148,7 +148,7 @@ export class FollowController {
|
|
|
148
148
|
this.id = (id && id.length > 0 ? id : 'id');
|
|
149
149
|
this.follow = this.follow.bind(this);
|
|
150
150
|
this.unfollow = this.unfollow.bind(this);
|
|
151
|
-
this.
|
|
151
|
+
this.checkFollow = this.checkFollow.bind(this);
|
|
152
152
|
}
|
|
153
153
|
id: string;
|
|
154
154
|
follow(req: Request, res: Response): void {
|
|
@@ -181,7 +181,7 @@ export class FollowController {
|
|
|
181
181
|
return res.status(200).json(count).end();
|
|
182
182
|
}).catch(err => handleError(err, res, this.log));
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
checkFollow(req: Request, res: Response): void {
|
|
185
185
|
const id = req.params.id;
|
|
186
186
|
const target = req.params.target;
|
|
187
187
|
if (!id || id.length === 0) {
|
|
@@ -197,3 +197,75 @@ export class FollowController {
|
|
|
197
197
|
}).catch(err => handleError(err, res, this.log));
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
+
export interface ReactService {
|
|
201
|
+
react(id: string, author: string, reaction: string): Promise<number>;
|
|
202
|
+
unreact(id: string, author: string, reaction: string): Promise<number>;
|
|
203
|
+
checkReaction(id: string, author: string): Promise<number>;
|
|
204
|
+
}
|
|
205
|
+
// tslint:disable-next-line:max-classes-per-file
|
|
206
|
+
export class ReactionController {
|
|
207
|
+
constructor(public log: Log, public service: ReactService, public author: string, id: string, public reaction: string) {
|
|
208
|
+
this.id = (id && id.length > 0 ? id : 'id');
|
|
209
|
+
this.react = this.react.bind(this);
|
|
210
|
+
this.unreact = this.unreact.bind(this);
|
|
211
|
+
this.checkReaction = this.checkReaction.bind(this);
|
|
212
|
+
}
|
|
213
|
+
id: string;
|
|
214
|
+
react(req: Request, res: Response): void {
|
|
215
|
+
const id = req.params.id;
|
|
216
|
+
const author = req.params.author;
|
|
217
|
+
const reaction = req.params.reaction;
|
|
218
|
+
if (!id || id.length === 0) {
|
|
219
|
+
res.status(400).end(`'${this.id}' cannot be empty`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!author || author.length === 0) {
|
|
223
|
+
res.status(400).end(`'${this.author}' cannot be empty`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!reaction || reaction.length === 0) {
|
|
227
|
+
res.status(400).end(`'${this.reaction}' cannot be empty`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.service.react(id, author, reaction).then(count => {
|
|
231
|
+
return res.status(200).json(count).end();
|
|
232
|
+
}).catch(err => handleError(err, res, this.log));
|
|
233
|
+
}
|
|
234
|
+
unreact(req: Request, res: Response): void {
|
|
235
|
+
const id = req.params.id;
|
|
236
|
+
const author = req.params.author;
|
|
237
|
+
const reaction = req.params.reaction;
|
|
238
|
+
if (!id || id.length === 0) {
|
|
239
|
+
res.status(400).end(`'${this.id}' cannot be empty`);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (!author || author.length === 0) {
|
|
243
|
+
res.status(400).end(`'${this.author}' cannot be empty`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (!reaction || reaction.length === 0) {
|
|
247
|
+
res.status(400).end(`'${this.reaction}' cannot be empty`);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.service.unreact(id, author, reaction).then(count => {
|
|
251
|
+
return res.status(200).json(count).end();
|
|
252
|
+
}).catch(err => handleError(err, res, this.log));
|
|
253
|
+
}
|
|
254
|
+
checkReaction(req: Request, res: Response): void {
|
|
255
|
+
const id = req.params.id;
|
|
256
|
+
const author = req.params.author;
|
|
257
|
+
if (!id || id.length === 0) {
|
|
258
|
+
res.status(400).end(`'${this.id}' cannot be empty`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (!author || author.length === 0) {
|
|
262
|
+
res.status(400).end(`'${this.author}' cannot be empty`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.service.checkReaction(id, author).then(count => {
|
|
266
|
+
return res.status(200).json(count).end();
|
|
267
|
+
}).catch(err => handleError(err, res, this.log));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export const ReactController = ReactionController;
|
|
271
|
+
export const UserReactionController = ReactionController;
|